[xiph-commits] r7623 - trunk/oggdsf/src/lib/core/directshow/dsfOggDemux

illiminable at motherfish-iii.xiph.org illiminable at motherfish-iii.xiph.org
Tue Aug 24 07:47:24 PDT 2004


Author: illiminable
Date: 2004-08-24 07:47:24 -0700 (Tue, 24 Aug 2004)
New Revision: 7623

Modified:
   trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp
   trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h
   trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPSocket.cpp
   trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPSocket.h
   trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/dsfOggDemux.vcproj
Log:
* Factored out the socket stuff.

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp	2004-08-24 14:30:33 UTC (rev 7622)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp	2004-08-24 14:47:24 UTC (rev 7623)
@@ -32,31 +32,16 @@
 #include "httpfilesource.h"
 
 HTTPFileSource::HTTPFileSource(void)
-	:	mWasError(false)
-	,	mIsEOF(false)
-	,	mIsOpen(false)
-	,	mSeenResponse(false)
+	:	HTTPSocket()
 	,	mBufferLock(NULL)
 {
 	mBufferLock = new CCritSec;
 	debugLog.open("G:\\logs\\httpdebug.log", ios_base::out);
 	//fileDump.open("G:\\filedump.ogg", ios_base::out|ios_base::binary);
-	WORD locWinsockVersion = MAKEWORD(1,1);
-	WSADATA locWinsockData;
-	int locRet= 0;
 
-	locRet = WSAStartup(locWinsockVersion, &locWinsockData);
-	if ((locRet != 0) || (locWinsockData.wVersion != locWinsockVersion)) {
-		//Failed to setup.
-		debugLog<<"Failed to start winsock V "<<locWinsockData.wVersion<<endl;
-		WSACleanup();
-		throw 0;
-	}
 
-	debugLog<<"Winsock started"<<endl;
 
 
-
 }
 
 HTTPFileSource::~HTTPFileSource(void)
@@ -65,7 +50,7 @@
 	debugLog.close();
 	//fileDump.close();
 	delete mBufferLock;
-	WSACleanup();
+	
 }
 
 void HTTPFileSource::DataProcessLoop() {
@@ -136,91 +121,7 @@
 
 }
 
-bool HTTPFileSource::setupSocket(string inSourceLocation) {
-	
-	debugLog<<"Setup Socket:"<<endl;
-	IN_ADDR locAddress;  //iaHost
-	LPHOSTENT locHostData;;  //lpHost
 
-	bool locValidURL = splitURL(inSourceLocation);
-
-	locAddress.S_un.S_addr = inet_addr(mServerName.c_str());
-	
-
-	if (locAddress.S_un.S_addr == INADDR_NONE) {
-		locHostData = gethostbyname(mServerName.c_str());
-	} else {
-		locHostData = gethostbyaddr((const char*)&locAddress, sizeof(struct in_addr), AF_INET);
-	}
-
-
-
-	if (locHostData == NULL) {
-		debugLog<<"LocHostData is NULL"<<endl;
-		//Failed
-		return false;
-	}
-
-	mSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-	if (mSocket == INVALID_SOCKET) {
-		debugLog<<"Socket Invalid"<<endl;
-		//Failed
-		return false;
-	}
-
-
-	LPSERVENT locServiceData; //lpServEnt
-	SOCKADDR_IN locServiceSocketAddr; //saServer
-	
-	if (mPort == 0) {
-		locServiceData = getservbyname("http", "tcp");
-		if (locServiceData == NULL) {
-			locServiceSocketAddr.sin_port = htons(80);
-		} else {
-			locServiceSocketAddr.sin_port = locServiceData->s_port;
-		}
-	} else {
-		//Explicit port
-		locServiceSocketAddr.sin_port = htons(mPort);
-	}
-
-
-
-	locServiceSocketAddr.sin_family = AF_INET;
-	locServiceSocketAddr.sin_addr = *((LPIN_ADDR)*locHostData->h_addr_list);
-
-
-	int locRetVal = 0;
-	locRetVal = connect(mSocket, (LPSOCKADDR)&locServiceSocketAddr, sizeof(SOCKADDR_IN));
-	if (locRetVal == SOCKET_ERROR) {
-		debugLog<<"Failed to connect..."<<endl;
-		closesocket(mSocket);
-		return false;
-	}
-
-	return true;
-
-
-}
-
-string HTTPFileSource::assembleRequest(string inFilePath) {
-	string retRequest;
-	retRequest = "GET " + inFilePath+ " HTTP/1.1\n" + "Host: " + mServerName+ "\n\n";
-	debugLog<<"Assembled Req : "<<endl<<retRequest<<endl;
-	return retRequest;
-}
-
-bool HTTPFileSource::httpRequest(string inRequest) {
-	debugLog<<"Http Request:"<<endl;
-	int locRetVal = send(mSocket, inRequest.c_str(), (int)inRequest.length(), 0);
-
-	if (locRetVal == SOCKET_ERROR) {
-		debugLog<<"Socket error on send"<<endl;
-		closesocket(mSocket);
-		return false;
-	}
-	return true;
-}
 DWORD HTTPFileSource::ThreadProc(void) {
 	//debugLog<<"ThreadProc:"<<endl;
 	while(true) {
@@ -253,62 +154,7 @@
 	return 0;
 }
 
-bool HTTPFileSource::splitURL(string inURL) {
-	debugLog<<"Split url:"<<endl;
-	string locProtocol;
-	string locServerName;
-	string locPath;
-	string locPort;
-	string locTemp;
-	size_t locPos2;
-	size_t locPos = inURL.find(':');
-	if (locPos == string::npos) {
-		//No colon... not a url or file... failure.
-		return false;
-	} else {
-		locProtocol = inURL.substr(0, locPos);
-		locTemp = inURL.substr(locPos+1);
-		locPos = locTemp.find("//");
-		if ((locPos == string::npos) || (locPos != 0)) {
-			return false;
-		} else {
-            locTemp = locTemp.substr(locPos+2);
-			locPos = locTemp.find('/');
-			if (locPos == string::npos) {
-				return false;
-			} else {
-				locPos2 = locTemp.find(':');
-				if (locPos2 == string::npos) {
-					locServerName = locTemp.substr(0, locPos);
-					locPath = locTemp.substr(locPos);
-				} else if (locPos2 < locPos) {
-					//Explicit port specification
-					locPort = locTemp.substr(locPos2 + 1, locPos - locPos2 - 1);
-					locServerName = locTemp.substr(0, locPos2);
-					locPath = locTemp.substr(locPos);
-				}
 
-			}
-		}
-		
-	}
-
-	mServerName = locServerName;
-	mFileName = locPath;
-	if (locPort != "") {
-		//Error checking needed
-		mPort = atoi(locPort.c_str());
-	} else {
-		mPort = 0;
-	}
-	debugLog<<"Proto : "<<locProtocol<<endl<<"Server : "<<locServerName<<endl<<" Path : "<<mFileName<<" Port : "<<mPort<<endl;
-	return true;
-
-}
-void HTTPFileSource::closeSocket() {
-	debugLog<<"Close Socket:"<<endl;
-	closesocket(mSocket);
-}
 void HTTPFileSource::close() {
 	//Close the socket down.
 	closeSocket();

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h	2004-08-24 14:30:33 UTC (rev 7622)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h	2004-08-24 14:47:24 UTC (rev 7623)
@@ -32,12 +32,14 @@
 #include "oggdllstuff.h"
 #include <winsock.h>
 //#include <stdlib.h>
+#include "HTTPSocket.h"
 #include <string>
 #include <sstream>
 #include <fstream>
 using namespace std;
 class OGG_DEMUX_API HTTPFileSource
-	:	public IFilterDataSource
+	:	protected HTTPSocket
+	,	public IFilterDataSource
 	,	public CAMThread
 {
 public:
@@ -64,26 +66,15 @@
 
 
 protected:
-	virtual bool setupSocket(string inSourceLocation);
-	virtual void closeSocket();
-	virtual bool splitURL(string inURL);
-	virtual string assembleRequest(string inFilePath);
-	bool httpRequest(string inRequest);
+
 	bool HTTPFileSource::startThread();
 	void DataProcessLoop();
-	string mServerName;
-	string mFileName;
-	unsigned short mPort;
-	string mLastResponse;
-	SOCKET mSocket;
+
 	stringstream mStreamBuffer;
 
 	fstream debugLog;
 	//fstream fileDump;
-	bool mIsEOF;
-	bool mWasError;
-	bool mIsOpen;
-	bool mSeenResponse;
 
+
 	CCritSec* mBufferLock;
 };

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPSocket.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPSocket.cpp	2004-08-24 14:30:33 UTC (rev 7622)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPSocket.cpp	2004-08-24 14:47:24 UTC (rev 7623)
@@ -1,3 +1,33 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+//  notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+//  notice, this list of conditions and the following disclaimer in the
+//  documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors 
+//  may be used to endorse or promote products derived from this software 
+//  without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
 #include "StdAfx.h"
 #include ".\httpsocket.h"
 
@@ -2,7 +32,175 @@
 HTTPSocket::HTTPSocket(void)
+	:	mWasError(false)
+	,	mIsEOF(false)
+	,	mIsOpen(false)
+	,	mSeenResponse(false)
 {
+	debugLog.open("G:\\logs\\httpsocket.log", ios_base::out);
+
+	//Setup the socket API
+	WORD locWinsockVersion = MAKEWORD(1,1);
+	WSADATA locWinsockData;
+	int locRet= 0;
+
+	locRet = WSAStartup(locWinsockVersion, &locWinsockData);
+	if ((locRet != 0) || (locWinsockData.wVersion != locWinsockVersion)) {
+		//Failed to setup.
+		debugLog<<"Failed to start winsock V "<<locWinsockData.wVersion<<endl;
+		WSACleanup();
+		throw 0;
+	}
+
+	debugLog<<"Winsock started"<<endl;
 }
 
 HTTPSocket::~HTTPSocket(void)
 {
+	debugLog<<"Winsock ended"<<endl;
+	debugLog.close();
+	
+	WSACleanup();
 }
+
+
+bool HTTPSocket::setupSocket(string inSourceLocation) {
+	
+	debugLog<<"Setup Socket:"<<endl;
+	IN_ADDR locAddress;  //iaHost
+	LPHOSTENT locHostData;;  //lpHost
+
+	bool locValidURL = splitURL(inSourceLocation);
+
+	locAddress.S_un.S_addr = inet_addr(mServerName.c_str());
+	
+
+	if (locAddress.S_un.S_addr == INADDR_NONE) {
+		locHostData = gethostbyname(mServerName.c_str());
+	} else {
+		locHostData = gethostbyaddr((const char*)&locAddress, sizeof(struct in_addr), AF_INET);
+	}
+
+
+
+	if (locHostData == NULL) {
+		debugLog<<"LocHostData is NULL"<<endl;
+		//Failed
+		return false;
+	}
+
+	mSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+	if (mSocket == INVALID_SOCKET) {
+		debugLog<<"Socket Invalid"<<endl;
+		//Failed
+		return false;
+	}
+
+
+	LPSERVENT locServiceData; //lpServEnt
+	SOCKADDR_IN locServiceSocketAddr; //saServer
+	
+	if (mPort == 0) {
+		locServiceData = getservbyname("http", "tcp");
+		if (locServiceData == NULL) {
+			locServiceSocketAddr.sin_port = htons(80);
+		} else {
+			locServiceSocketAddr.sin_port = locServiceData->s_port;
+		}
+	} else {
+		//Explicit port
+		locServiceSocketAddr.sin_port = htons(mPort);
+	}
+
+
+
+	locServiceSocketAddr.sin_family = AF_INET;
+	locServiceSocketAddr.sin_addr = *((LPIN_ADDR)*locHostData->h_addr_list);
+
+
+	int locRetVal = 0;
+	locRetVal = connect(mSocket, (LPSOCKADDR)&locServiceSocketAddr, sizeof(SOCKADDR_IN));
+	if (locRetVal == SOCKET_ERROR) {
+		debugLog<<"Failed to connect..."<<endl;
+		closesocket(mSocket);
+		return false;
+	}
+
+	return true;
+
+
+}
+
+string HTTPSocket::assembleRequest(string inFilePath) {
+	string retRequest;
+	retRequest = "GET " + inFilePath+ " HTTP/1.1\n" + "Host: " + mServerName+ "\n\n";
+	debugLog<<"Assembled Req : "<<endl<<retRequest<<endl;
+	return retRequest;
+}
+
+bool HTTPSocket::httpRequest(string inRequest) {
+	debugLog<<"Http Request:"<<endl;
+	int locRetVal = send(mSocket, inRequest.c_str(), (int)inRequest.length(), 0);
+
+	if (locRetVal == SOCKET_ERROR) {
+		debugLog<<"Socket error on send"<<endl;
+		closesocket(mSocket);
+		return false;
+	}
+	return true;
+}
+
+bool HTTPSocket::splitURL(string inURL) {
+	debugLog<<"Split url:"<<endl;
+	string locProtocol;
+	string locServerName;
+	string locPath;
+	string locPort;
+	string locTemp;
+	size_t locPos2;
+	size_t locPos = inURL.find(':');
+	if (locPos == string::npos) {
+		//No colon... not a url or file... failure.
+		return false;
+	} else {
+		locProtocol = inURL.substr(0, locPos);
+		locTemp = inURL.substr(locPos+1);
+		locPos = locTemp.find("//");
+		if ((locPos == string::npos) || (locPos != 0)) {
+			return false;
+		} else {
+            locTemp = locTemp.substr(locPos+2);
+			locPos = locTemp.find('/');
+			if (locPos == string::npos) {
+				return false;
+			} else {
+				locPos2 = locTemp.find(':');
+				if (locPos2 == string::npos) {
+					locServerName = locTemp.substr(0, locPos);
+					locPath = locTemp.substr(locPos);
+				} else if (locPos2 < locPos) {
+					//Explicit port specification
+					locPort = locTemp.substr(locPos2 + 1, locPos - locPos2 - 1);
+					locServerName = locTemp.substr(0, locPos2);
+					locPath = locTemp.substr(locPos);
+				}
+
+			}
+		}
+		
+	}
+
+	mServerName = locServerName;
+	mFileName = locPath;
+	if (locPort != "") {
+		//Error checking needed
+		mPort = atoi(locPort.c_str());
+	} else {
+		mPort = 0;
+	}
+	debugLog<<"Proto : "<<locProtocol<<endl<<"Server : "<<locServerName<<endl<<" Path : "<<mFileName<<" Port : "<<mPort<<endl;
+	return true;
+
+}
+void HTTPSocket::closeSocket() {
+	debugLog<<"Close Socket:"<<endl;
+	closesocket(mSocket);
+}
\ No newline at end of file

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPSocket.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPSocket.h	2004-08-24 14:30:33 UTC (rev 7622)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPSocket.h	2004-08-24 14:47:24 UTC (rev 7623)
@@ -1,8 +1,61 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+//  notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+//  notice, this list of conditions and the following disclaimer in the
+//  documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors 
+//  may be used to endorse or promote products derived from this software 
+//  without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
 #pragma once
+#include <fstream>
+#include <string>
+using namespace std;
 
 class HTTPSocket
 {
 public:
 	HTTPSocket(void);
-	~HTTPSocket(void);
+	virtual ~HTTPSocket(void);
+
+	virtual bool setupSocket(string inSourceLocation);
+	virtual void closeSocket();
+	virtual bool splitURL(string inURL);
+	virtual string assembleRequest(string inFilePath);
+	bool httpRequest(string inRequest);
+protected:
+	string mServerName;
+	string mFileName;
+	unsigned short mPort;
+	string mLastResponse;
+	SOCKET mSocket;
+
+	bool mIsEOF;
+	bool mWasError;
+	bool mIsOpen;
+	bool mSeenResponse;
+
+	fstream debugLog;
+
 };

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/dsfOggDemux.vcproj
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/dsfOggDemux.vcproj	2004-08-24 14:30:33 UTC (rev 7622)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/dsfOggDemux.vcproj	2004-08-24 14:47:24 UTC (rev 7623)
@@ -158,6 +158,9 @@
 				RelativePath="HTTPFileSource.cpp">
 			</File>
 			<File
+				RelativePath=".\HTTPSocket.cpp">
+			</File>
+			<File
 				RelativePath="OggDemux.def">
 			</File>
 			<File
@@ -231,6 +234,9 @@
 				RelativePath="HTTPFileSource.h">
 			</File>
 			<File
+				RelativePath=".\HTTPSocket.h">
+			</File>
+			<File
 				RelativePath="IFilterDataSource.h">
 			</File>
 			<File



More information about the commits mailing list