Pārlūkot izejas kodu

Clean up some TODOs and FIXMEs

Bart van Strien 6 gadi atpakaļ
vecāks
revīzija
e1173feb5d
2 mainītis faili ar 21 papildinājumiem un 12 dzēšanām
  1. 16 11
      src/windows/SChannelConnection.cpp
  2. 5 1
      src/windows/SChannelConnection.h

+ 16 - 11
src/windows/SChannelConnection.cpp

@@ -64,12 +64,7 @@ SChannelConnection::SChannelConnection()
 
 SChannelConnection::~SChannelConnection()
 {
-	// TODO?
-	if (CtxtHandle *context = static_cast<CtxtHandle*>(this->context))
-	{
-		DeleteSecurityContext(context);
-		delete context;
-	}
+	destroyContext();
 }
 
 SECURITY_STATUS InitializeSecurityContext(CredHandle *phCredential, std::unique_ptr<CtxtHandle>& phContext, const std::string& szTargetName, ULONG fContextReq, std::vector<char>& inputBuffer, std::vector<char>& outputBuffer, ULONG *pfContextAttr)
@@ -200,9 +195,9 @@ bool SChannelConnection::connect(const std::string &hostname, uint16_t port)
 			sendData = true;
 			break;
 		default:
-			debug << "Initialize done: " << outputBuffer.size() << " bytes of output and status " << ret << "\n";
+			debug << "Initialize done: " << outputBuffer.size() << " bytes of output and unknown status " << ret << "\n";
 			done = true;
-			// TODO: error
+			success = false;
 			break;
 		}
 
@@ -232,7 +227,6 @@ bool SChannelConnection::connect(const std::string &hostname, uint16_t port)
 				break;
 			}
 		}
-		// TODO: A bunch of frees?
 	} while (!done);
 
 	debug << "Done!\n";
@@ -254,7 +248,7 @@ bool SChannelConnection::connect(const std::string &hostname, uint16_t port)
 	}
 
 	if (success)
-		this->context = static_cast<void*>(context.release());
+		this->context = context.release();
 	else if (contextCreated)
 		DeleteSecurityContext(context.get());
 
@@ -444,9 +438,20 @@ size_t SChannelConnection::write(const char *buffer, size_t size)
 	return size;
 }
 
+void SChannelConnection::destroyContext()
+{
+	if (context)
+	{
+		DeleteSecurityContext(context);
+		delete context;
+		context = nullptr;
+	}
+}
+
 void SChannelConnection::close()
 {
-	// TODO
+	destroyContext();
+	socket.close();
 }
 
 bool SChannelConnection::valid()

+ 5 - 1
src/windows/SChannelConnection.h

@@ -5,6 +5,9 @@
 
 #include <vector>
 
+struct _SecHandle;
+using CtxtHandle = _SecHandle;
+
 class SChannelConnection : public Connection
 {
 public:
@@ -19,9 +22,10 @@ public:
 
 private:
 	PlaintextConnection socket;
-	void *context; // FIXME
+	CtxtHandle *context;
 	std::vector<char> encRecvBuffer;
 	std::vector<char> decRecvBuffer;
 
 	size_t decrypt(char *buffer, size_t size, bool recurse = true);
+	void destroyContext();
 };