Skip to content

Commit

Permalink
Refactored plugin names deskflow#4866
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry (Xinyu Hou) committed Aug 3, 2015
1 parent b105bc8 commit 945ccfd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
7 changes: 3 additions & 4 deletions src/lib/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@
#include "base/IEventQueue.h"
#include "base/TMethodEventJob.h"
#include "base/TMethodJob.h"
#include "common/PluginVersion.h"
#include "common/stdexcept.h"

#include <cstring>
#include <cstdlib>
#include <sstream>
#include <fstream>

static const char s_networkSecurity[] = { "ns" };

//
// Client
//
Expand Down Expand Up @@ -103,7 +102,7 @@ Client::Client(
}

if (m_args.m_enableCrypto) {
m_useSecureNetwork = ARCH->plugin().exists(s_networkSecurity);
m_useSecureNetwork = ARCH->plugin().exists(s_pluginNames[kSecureSocket]);
if (m_useSecureNetwork == false) {
LOG((CLOG_NOTE "crypto disabled because of ns plugin not available"));
}
Expand Down Expand Up @@ -585,7 +584,7 @@ Client::cleanupStream()
// we need to tell the dynamic lib that allocated this object
// to do the deletion.
if (m_useSecureNetwork) {
ARCH->plugin().invoke(s_networkSecurity, "deleteSocket", NULL);
ARCH->plugin().invoke(s_pluginNames[kSecureSocket], "deleteSocket", NULL);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/lib/common/PluginVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@

#include <string.h>

static const int kpluginCount = 1;
static const char kUnknownVersion[] = "unknown";
static const char* s_pluginNames[] = { "ns" };
static const char* s_pluginVersions[] = { "1.2" };

const char* getExpectedPluginVersion(const char* name)
{
for (int i = 0; i < kpluginCount; i++) {
for (int i = 0; i < kPluginCount; i++) {
if (strcmp(name, s_pluginNames[i]) == 0) {
return s_pluginVersions[i];
break;
Expand Down
9 changes: 9 additions & 0 deletions src/lib/common/PluginVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@

#pragma once

enum EPluginType {
kSecureSocket,
kPluginCount
};

static const char* s_pluginNames[] = { "ns" };
static const char* s_pluginVersions[] = { "1.2" };


//! Get expected plugin version
/*!
Returns the plugin version expected by the plugin loader.
Expand Down
7 changes: 3 additions & 4 deletions src/lib/net/TCPSocketFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
#include "net/TCPSocket.h"
#include "net/TCPListenSocket.h"
#include "arch/Arch.h"
#include "common/PluginVersion.h"
#include "base/Log.h"

//
// TCPSocketFactory
//

static const char s_networkSecurity[] = { "ns" };

TCPSocketFactory::TCPSocketFactory(IEventQueue* events, SocketMultiplexer* socketMultiplexer) :
m_events(events),
m_socketMultiplexer(socketMultiplexer)
Expand All @@ -51,7 +50,7 @@ TCPSocketFactory::create(bool secure) const
m_socketMultiplexer
};
socket = static_cast<IDataSocket*>(
ARCH->plugin().invoke(s_networkSecurity, "getSocket", args));
ARCH->plugin().invoke(s_pluginNames[kSecureSocket], "getSocket", args));
}
else {
socket = new TCPSocket(m_events, m_socketMultiplexer);
Expand All @@ -70,7 +69,7 @@ TCPSocketFactory::createListen(bool secure) const
m_socketMultiplexer
};
socket = static_cast<IListenSocket*>(
ARCH->plugin().invoke(s_networkSecurity, "getListenSocket", args));
ARCH->plugin().invoke(s_pluginNames[kSecureSocket], "getListenSocket", args));
}
else {
socket = new TCPListenSocket(m_events, m_socketMultiplexer);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/plugin/ns/ns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ SecureSocket* g_secureSocket = NULL;
SecureListenSocket* g_secureListenSocket = NULL;
Arch* g_arch = NULL;
Log* g_log = NULL;
static const char kPluginName[] = "ns";

std::string
helperGetLibsUsed(void)
Expand Down Expand Up @@ -107,7 +106,7 @@ invoke(const char* command, void** args)
}
}
else if (strcmp(command, "version") == 0) {
return (void*)getExpectedPluginVersion(kPluginName);
return (void*)getExpectedPluginVersion(s_pluginNames[kSecureSocket]);
}

return NULL;
Expand Down
7 changes: 3 additions & 4 deletions src/lib/server/ClientListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "net/IListenSocket.h"
#include "net/ISocketFactory.h"
#include "net/XSocket.h"
#include "common/PluginVersion.h"
#include "base/Log.h"
#include "base/IEventQueue.h"
#include "base/TMethodEventJob.h"
Expand All @@ -33,8 +34,6 @@
// ClientListener
//

static const char s_networkSecurity[] = { "ns" };

ClientListener::ClientListener(const NetworkAddress& address,
ISocketFactory* socketFactory,
IEventQueue* events,
Expand All @@ -49,7 +48,7 @@ ClientListener::ClientListener(const NetworkAddress& address,
try {
// create listen socket
if (enableCrypto) {
m_useSecureNetwork = ARCH->plugin().exists(s_networkSecurity);
m_useSecureNetwork = ARCH->plugin().exists(s_pluginNames[kSecureSocket]);
if (m_useSecureNetwork == false) {
LOG((CLOG_NOTE "crypto disabled because of ns plugin not available"));
}
Expand Down Expand Up @@ -249,7 +248,7 @@ ClientListener::cleanupListenSocket()
}
else {
ARCH->plugin().invoke(
s_networkSecurity,
s_pluginNames[kSecureSocket],
"deleteListenSocket",
NULL);
}
Expand Down

0 comments on commit 945ccfd

Please sign in to comment.