Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- AdcHub.cpp Tue Jan 20 00:26:36 1970
- +++ AdcHub.cpp Tue Jan 20 00:26:36 1970
- @@ -276,9 +276,12 @@
- return;
- message.replyTo = findUser(AdcCommand::toSID(temp));
- - if(!message.replyTo || PluginManager::getInstance()->onIncomingPM(message.replyTo, message.text))
- + if(!message.replyTo)
- return;
- - } else if(PluginManager::getInstance()->onIncomingChat(this, message.text))
- +
- + if(PluginManager::getInstance()->runHook(HOOK_CHAT_PM_IN, message.replyTo, message.text))
- + return;
- + } else if(PluginManager::getInstance()->runHook(HOOK_CHAT_IN, this, message.text))
- return;
- message.thirdPerson = c.hasFlag("ME", 1);
- @@ -707,8 +710,12 @@
- }
- void AdcHub::hubMessage(const string& aMessage, bool thirdPerson) {
- - if(state != STATE_NORMAL || PluginManager::getInstance()->onOutgoingChat(this, aMessage))
- + if(state != STATE_NORMAL)
- + return;
- +
- + if(PluginManager::getInstance()->runHook(HOOK_CHAT_OUT, this, aMessage))
- return;
- +
- AdcCommand c(AdcCommand::CMD_MSG, AdcCommand::TYPE_BROADCAST);
- c.addParam(aMessage);
- if(thirdPerson)
- @@ -717,8 +724,9 @@
- }
- void AdcHub::privateMessage(const OnlineUser& user, const string& aMessage, bool thirdPerson) {
- - if(state != STATE_NORMAL || PluginManager::getInstance()->onOutgoingPM(user, aMessage))
- + if(state != STATE_NORMAL)
- return;
- +
- AdcCommand c(AdcCommand::CMD_MSG, user.getIdentity().getSID(), AdcCommand::TYPE_ECHO);
- c.addParam(aMessage);
- if(thirdPerson)
- @@ -1120,7 +1128,7 @@
- return;
- }
- - if(PluginManager::getInstance()->onIncomingHubData(this, aLine))
- + if(PluginManager::getInstance()->runHook(HOOK_NETWORK_HUB_IN, this, aLine))
- return;
- dispatch(aLine);
- --- ChatMessage.h Tue Jan 20 00:26:36 1970
- +++ ChatMessage.h Tue Jan 20 00:26:36 1970
- @@ -32,7 +32,7 @@
- const OnlineUser* from;
- const OnlineUser* to;
- - const OnlineUser* replyTo;
- + OnlineUser* replyTo;
- bool thirdPerson;
- time_t timestamp;
- --- Client.cpp Tue Jan 20 00:26:36 1970
- +++ Client.cpp Tue Jan 20 00:26:36 1970
- @@ -19,12 +19,13 @@
- #include "stdinc.h"
- #include "Client.h"
- +#include "AdcHub.h"
- +
- #include "BufferedSocket.h"
- #include "ClientManager.h"
- #include "ConnectivityManager.h"
- #include "DebugManager.h"
- #include "FavoriteManager.h"
- -#include "PluginManager.h"
- #include "TimerManager.h"
- #include "UserMatchManager.h"
- @@ -125,12 +126,32 @@
- }
- void Client::send(const char* aMessage, size_t aLen) {
- - if(!isConnected() || PluginManager::getInstance()->onOutgoingHubData(this, aMessage))
- + if(!isConnected())
- + return;
- +
- + if(PluginManager::getInstance()->runHook(HOOK_NETWORK_HUB_OUT, this, aMessage))
- return;
- updateActivity();
- sock->write(aMessage, aLen);
- COMMAND_DEBUG(aMessage, DebugManager::HUB_OUT, getIpPort());
- +}
- +
- +HubData* Client::getPluginObject() noexcept {
- + pod.ip = ip.c_str();
- + pod.isOp = isOp() ? True : False;
- + // in case this is called before connection ís established
- + pod.isSecure = isSecure() ? True : False;
- +
- + if(pod.object)
- + return &pod;
- +
- + pod.url = hubUrl.c_str();
- + pod.object = this;
- + pod.port = Util::toInt(port);
- + pod.protocol = dynamic_cast<AdcHub*>(this) ? PROTOCOL_ADC : PROTOCOL_NMDC;
- +
- + return &pod;
- }
- void Client::on(Connected) noexcept {
- --- Client.h Tue Jan 20 00:26:36 1970
- +++ Client.h Tue Jan 20 00:26:36 1970
- @@ -31,13 +31,14 @@
- #include "ClientListener.h"
- #include "OnlineUser.h"
- #include "atomic.h"
- +#include "PluginManager.h"
- namespace dcpp {
- using std::list;
- /** Yes, this should probably be called a Hub */
- -class Client : public Speaker<ClientListener>, public BufferedSocketListener, protected TimerManagerListener {
- +class Client : public PluginEntity<HubData>, public Speaker<ClientListener>, public BufferedSocketListener, protected TimerManagerListener {
- public:
- virtual void connect();
- virtual void disconnect(bool graceless);
- @@ -85,6 +86,8 @@
- void send(const string& aMessage) { send(aMessage.c_str(), aMessage.length()); }
- void send(const char* aMessage, size_t aLen);
- +
- + HubData* getPluginObject() noexcept;
- string getMyNick() const { return getMyIdentity().getNick(); }
- string getHubName() const { return getHubIdentity().getNick().empty() ? getHubUrl() : getHubIdentity().getNick(); }
- --- ClientManager.cpp Tue Jan 20 00:26:36 1970
- +++ ClientManager.cpp Tue Jan 20 00:26:36 1970
- @@ -29,6 +29,7 @@
- #include "SearchManager.h"
- #include "SearchResult.h"
- #include "ShareManager.h"
- +#include "PluginManager.h"
- #include "SimpleXML.h"
- #include "UserCommand.h"
- @@ -434,7 +435,7 @@
- Lock l(cs);
- OnlineUser* u = findOnlineUser(user, priv);
- - if(u) {
- + if(u && !PluginManager::getInstance()->runHook(HOOK_CHAT_PM_OUT, u, msg)) {
- u->getClient().privateMessage(*u, msg, thirdPerson);
- }
- }
- --- NmdcHub.cpp Tue Jan 20 00:26:36 1970
- +++ NmdcHub.cpp Tue Jan 20 00:26:36 1970
- @@ -230,7 +230,7 @@
- chatMessage.from = &o;
- }
- - if(PluginManager::getInstance()->onIncomingChat(this, chatMessage.text))
- + if(PluginManager::getInstance()->runHook(HOOK_CHAT_IN, this, chatMessage.text))
- return;
- fire(ClientListener::Message(), this, chatMessage);
- @@ -756,7 +756,7 @@
- message.from = findUser(fromNick);
- }
- - if(PluginManager::getInstance()->onIncomingPM(message.replyTo, message.text))
- + if(PluginManager::getInstance()->runHook(HOOK_CHAT_PM_IN, message.replyTo, message.text))
- return;
- fire(ClientListener::Message(), this, message);
- @@ -808,7 +808,7 @@
- void NmdcHub::hubMessage(const string& aMessage, bool thirdPerson) {
- checkstate();
- - if(!PluginManager::getInstance()->onOutgoingChat(this, aMessage))
- + if(!PluginManager::getInstance()->runHook(HOOK_CHAT_OUT, this, aMessage))
- send(fromUtf8( "<" + getMyNick() + "> " + escape(thirdPerson ? "/me " + aMessage : aMessage) + "|" ) );
- }
- @@ -949,9 +949,6 @@
- void NmdcHub::privateMessage(const OnlineUser& aUser, const string& aMessage, bool /*thirdPerson*/) {
- checkstate();
- - if(PluginManager::getInstance()->onOutgoingPM(aUser, aMessage))
- - return;
- -
- privateMessage(aUser.getIdentity().getNick(), aMessage);
- // Emulate a returning message...
- Lock l(cs);
- @@ -1011,8 +1008,10 @@
- void NmdcHub::on(Line, const string& aLine) noexcept {
- Client::on(Line(), aLine);
- - if(PluginManager::getInstance()->onIncomingHubData(this, validateMessage(aLine, true)))
- +
- + if(PluginManager::getInstance()->runHook(HOOK_NETWORK_HUB_IN, this, validateMessage(aLine, true)))
- return;
- +
- onLine(aLine);
- }
- --- OnlineUser.h Tue Jan 20 00:26:36 1970
- +++ OnlineUser.h Tue Jan 20 00:26:36 1970
- @@ -30,6 +30,7 @@
- #include "Util.h"
- #include "User.h"
- #include "UserMatch.h"
- +#include "PluginManager.h"
- namespace dcpp {
- @@ -141,7 +142,7 @@
- static FastCriticalSection cs;
- };
- -class OnlineUser : public FastAlloc<OnlineUser>, private boost::noncopyable {
- +class OnlineUser : public FastAlloc<OnlineUser>, private boost::noncopyable, public PluginEntity<UserData> {
- public:
- typedef vector<OnlineUser*> List;
- typedef List::iterator Iter;
- @@ -156,6 +157,8 @@
- Identity& getIdentity() { return identity; }
- Client& getClient() { return client; }
- const Client& getClient() const { return client; }
- +
- + UserData* getPluginObject() noexcept;
- GETSET(Identity, identity, Identity);
- private:
- --- PluginApiImpl.cpp Tue Jan 20 00:26:36 1970
- +++ PluginApiImpl.cpp Tue Jan 20 00:26:36 1970
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
- + * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -19,103 +19,197 @@
- /**
- * The PluginApiImpl class contains implementations of certain callback functions,
- * they are simply separated here.
- + *
- + * Notes:
- + * - Current implementation does not correctly run HOOK_CHAT_PM_OUT for PM's sent as a result of Client::sendUserCmd
- + * - dcpp may run HOOK_HUB_OFFLINE for hubs that never ran HOOK_HUB_ONLINE before (if socket creation fails in Client::connect)
- */
- #include "stdinc.h"
- -#include "DCPlusPlus.h"
- +#include "PluginApiImpl.h"
- +
- +#include "File.h"
- #include "PluginManager.h"
- #include "ConnectionManager.h"
- #include "FavoriteManager.h"
- +#include "QueueManager.h"
- +#include "ClientManager.h"
- -#include "AdcHub.h"
- #include "UserConnection.h"
- namespace dcpp {
- -Socket PluginApiImpl::apiSocket(Socket::TYPE_UDP);
- -
- -hookHandle PluginApiImpl::initAPI(DCCore& dcCore) {
- - dcCore.apiVersion = DCAPI_VER;
- -
- - // Hook creation
- - dcCore.create_hook = &PluginApiImpl::createHook;
- - dcCore.destroy_hook = &PluginApiImpl::destroyHook;
- +#define IMPL_HOOKS_COUNT 19
- - // Hook interaction
- - dcCore.set_hook = &PluginApiImpl::setHook;
- - dcCore.call_hook = &PluginApiImpl::callHook;
- - dcCore.un_hook = &PluginApiImpl::unHook;
- +static const char* hookGuids[IMPL_HOOKS_COUNT] = {
- + HOOK_CHAT_IN,
- + HOOK_CHAT_OUT,
- + HOOK_CHAT_PM_IN,
- + HOOK_CHAT_PM_OUT,
- +
- + HOOK_TIMER_SECOND,
- + HOOK_TIMER_MINUTE,
- +
- + HOOK_HUB_ONLINE,
- + HOOK_HUB_OFFLINE,
- +
- + HOOK_NETWORK_HUB_IN,
- + HOOK_NETWORK_HUB_OUT,
- + HOOK_NETWORK_CONN_IN,
- + HOOK_NETWORK_CONN_OUT,
- +
- + HOOK_QUEUE_ADD,
- + HOOK_QUEUE_MOVE,
- + HOOK_QUEUE_REMOVE,
- + HOOK_QUEUE_FINISHED,
- +
- + HOOK_UI_CREATED,
- + HOOK_UI_CHAT_DISPLAY,
- + HOOK_UI_PROCESS_CHAT_CMD
- +};
- - // Message regitster
- - dcCore.register_message = &PluginApiImpl::registerMessage;
- - dcCore.register_range = &PluginApiImpl::registerRange;
- - dcCore.seek_message = &PluginApiImpl::seekMessage;
- +Socket PluginApiImpl::apiSocket(Socket::TYPE_UDP);
- - // Setting management
- - dcCore.set_cfg = &PluginApiImpl::setConfig;
- - dcCore.get_cfg = &PluginApiImpl::getConfig;
- +// lambdas are not used because certain compiler is being a pain about it (for now)
- +DCHooks PluginApiImpl::dcHooks = {
- + &PluginApiImpl::createHook,
- + &PluginApiImpl::destroyHook,
- +
- + &PluginApiImpl::bindHook,
- + &PluginApiImpl::runHook,
- + &PluginApiImpl::releaseHook
- +};
- +
- +DCConfig PluginApiImpl::dcConfig = {
- + &PluginApiImpl::getPath,
- + &PluginApiImpl::setConfig,
- + &PluginApiImpl::getConfig
- +};
- +
- +DCLog PluginApiImpl::dcLog = {
- + &PluginApiImpl::log
- +};
- +
- +DCConnection PluginApiImpl::dcConnection = {
- + &PluginApiImpl::sendUdpData,
- + &PluginApiImpl::sendProtocolCmd,
- + &PluginApiImpl::terminateConnection
- +};
- +
- +DCHub PluginApiImpl::dcHub = {
- + &PluginApiImpl::newClient,
- + &PluginApiImpl::findOnlineHub,
- + &PluginApiImpl::deleteClient,
- +
- + &PluginApiImpl::emulateProtocolCmd,
- + &PluginApiImpl::sendProtocolCmd,
- +
- + &PluginApiImpl::sendHubMessage,
- + &PluginApiImpl::sendLocalMessage,
- + &PluginApiImpl::sendPrivateMessage
- +};
- +
- +DCQueue PluginApiImpl::dcQueue = {
- + &PluginApiImpl::addDownload,
- + &PluginApiImpl::removeDownload,
- + &PluginApiImpl::setPriority
- +};
- +
- +DCUtils PluginApiImpl::dcUtils = {
- + &PluginApiImpl::toUtf8,
- + &PluginApiImpl::fromUtf8,
- +
- + &PluginApiImpl::Utf8toWide,
- + &PluginApiImpl::WidetoUtf8,
- +
- + &PluginApiImpl::toBase32,
- + &PluginApiImpl::fromBase32
- +};
- - dcCore.memalloc = &PluginApiImpl::memalloc;
- - dcCore.strconv = &PluginApiImpl::strconv;
- +void PluginApiImpl::initAPI(DCCore& dcCore) {
- + dcCore.apiVersion = DCAPI_VER;
- - return PluginManager::getInstance()->createHook(CALLBACK_BASE, HOOK_CALLBACK, &PluginApiImpl::coreCallback);
- + // Interface registry
- + dcCore.register_interface = &PluginApiImpl::registerInterface;
- + dcCore.query_interface = &PluginApiImpl::queryInterface;
- + dcCore.release_interface = &PluginApiImpl::releaseInterface;
- +
- + // Interfaces (since these outlast any plugin they don't need to be explictly released)
- + dcCore.register_interface(INTERFACE_HOOKS, &dcHooks);
- + dcCore.register_interface(INTERFACE_CONFIG, &dcConfig);
- + dcCore.register_interface(INTERFACE_LOGGING, &dcLog);
- +
- + dcCore.register_interface(INTERFACE_DCPP_CONNECTIONS, &dcConnection);
- + dcCore.register_interface(INTERFACE_DCPP_HUBS, &dcHub);
- + dcCore.register_interface(INTERFACE_DCPP_QUEUE, &dcQueue);
- + dcCore.register_interface(INTERFACE_DCPP_UTILS, &dcUtils);
- +
- + // Create provided hooks (since these outlast any plugin they don't need to be explictly released)
- + for(int i = 0; i < IMPL_HOOKS_COUNT; ++i)
- + dcHooks.create_hook(hookGuids[i], NULL);
- }
- -void PluginApiImpl::releaseAPI(hookHandle hHook) {
- - PluginManager::getInstance()->destroyHook(hHook);
- +void PluginApiImpl::releaseAPI() {
- apiSocket.disconnect();
- }
- // Functions for DCCore
- -hookHandle PluginApiImpl::createHook(HookID hookId, HookType hookType, DCHOOK defProc) {
- - return PluginManager::getInstance()->createHook(hookId, hookType, defProc);
- +intfHandle PluginApiImpl::registerInterface(const char* guid, dcptr_t funcs) {
- + return PluginManager::getInstance()->registerInterface(guid, funcs);
- }
- -void PluginApiImpl::destroyHook(hookHandle hHook) {
- - PluginManager::getInstance()->destroyHook(hHook);
- - hHook = NULL;
- +dcptr_t PluginApiImpl::queryInterface(const char* guid) {
- + return PluginManager::getInstance()->queryInterface(guid);
- +}
- +
- +Bool PluginApiImpl::releaseInterface(intfHandle hInterface) {
- + return PluginManager::getInstance()->releaseInterface(hInterface) ? True : False;
- }
- -subsHandle PluginApiImpl::setHook(HookID hookId, DCHOOK hookProc, void* pCommon) {
- - return PluginManager::getInstance()->setHook(hookId, hookProc, pCommon);
- +// Functions for DCHook
- +hookHandle PluginApiImpl::createHook(const char* guid, DCHOOK defProc) {
- + return PluginManager::getInstance()->createHook(guid, defProc);
- }
- -Bool PluginApiImpl::callHook(HookID hookId, uint32_t eventId, dcptr_t pData) {
- - return PluginManager::getInstance()->callHook(hookId, eventId, pData) ? True : False;
- +Bool PluginApiImpl::destroyHook(hookHandle hHook) {
- + Bool bRes = PluginManager::getInstance()->destroyHook(reinterpret_cast<PluginHook*>(hHook)) ? True : False;
- + hHook = NULL;
- + return bRes;
- }
- -size_t PluginApiImpl::unHook(subsHandle hHook) {
- - return PluginManager::getInstance()->unHook(hHook);
- +subsHandle PluginApiImpl::bindHook(const char* guid, DCHOOK hookProc, void* pCommon) {
- + return PluginManager::getInstance()->bindHook(guid, hookProc, pCommon);
- }
- -uint32_t PluginApiImpl::registerMessage(HookType type, const char* name) {
- - return PluginManager::getInstance()->registerMessage(type, name);
- +Bool PluginApiImpl::runHook(const char* guid, dcptr_t pObject, dcptr_t pData) {
- + return PluginManager::getInstance()->runHook(guid, pObject, pData) ? True : False;
- }
- -uint32_t PluginApiImpl::registerRange(HookType type, const char* name, uint32_t count) {
- - return PluginManager::getInstance()->registerRange(type, name, count);
- +size_t PluginApiImpl::releaseHook(subsHandle hHook) {
- + return PluginManager::getInstance()->releaseHook(reinterpret_cast<HookSubscriber*>(hHook));
- }
- -uint32_t PluginApiImpl::seekMessage(const char* name) {
- - return PluginManager::getInstance()->seekMessage(name);
- +// Functions for DCConfig
- +const char* DCAPI PluginApiImpl::getPath(PathType type) {
- + return Util::getPath(static_cast<Util::Paths>(type)).c_str();
- }
- void PluginApiImpl::setConfig(const char* guid, const char* setting, ConfigValuePtr val) {
- PluginManager* pm = PluginManager::getInstance();
- switch(val->type) {
- case CFG_TYPE_REMOVE:
- - pm->removeSetting(guid, setting);
- + pm->removePluginSetting(guid, setting);
- break;
- case CFG_TYPE_STRING:
- if(val->value.str)
- - pm->setSetting(guid, setting, val->value.str);
- + pm->setPluginSetting(guid, setting, val->value.str);
- break;
- case CFG_TYPE_INT:
- - pm->setSetting(guid, setting, Util::toString(val->value.int32));
- + pm->setPluginSetting(guid, setting, Util::toString(val->value.int32));
- break;
- case CFG_TYPE_INT64:
- - pm->setSetting(guid, setting, Util::toString(val->value.int64));
- + pm->setPluginSetting(guid, setting, Util::toString(val->value.int64));
- break;
- default:
- dcassert(0);
- @@ -149,13 +243,13 @@
- PluginManager* pm = PluginManager::getInstance();
- switch(val->type) {
- case CFG_TYPE_STRING:
- - val->value.str = pm->getSetting(guid, setting).c_str();
- + val->value.str = pm->getPluginSetting(guid, setting).c_str();
- break;
- case CFG_TYPE_INT:
- - val->value.int32 = Util::toInt(pm->getSetting(guid, setting));
- + val->value.int32 = Util::toInt(pm->getPluginSetting(guid, setting));
- break;
- case CFG_TYPE_INT64:
- - val->value.int64 = Util::toInt64(pm->getSetting(guid, setting));
- + val->value.int64 = Util::toInt64(pm->getPluginSetting(guid, setting));
- break;
- default:
- dcassert(0);
- @@ -163,242 +257,172 @@
- return True;
- }
- -void* PluginApiImpl::memalloc(void* ptr, size_t bytes) {
- - if(ptr != NULL && bytes > 0) {
- - return realloc(ptr, bytes);
- - } else if(ptr != NULL) {
- - free(ptr);
- - } else if(bytes > 0) {
- - return malloc(bytes);
- - }
- - return NULL;
- +// Functions for DCLog
- +void PluginApiImpl::log(const char* msg) {
- + LogManager::getInstance()->message(msg);
- }
- -size_t PluginApiImpl::strconv(ConversionType type, void* dst, void* src, size_t len) {
- - switch(type) {
- - case CONV_TO_UTF8: {
- - string sSrc(Text::toUtf8(reinterpret_cast<char*>(src)));
- - char* cDst = static_cast<char*>(dst);
- - len = (sSrc.size() < len) ? sSrc.size() : len;
- - strncpy(cDst, sSrc.c_str(), len);
- - return len;
- - }
- - case CONV_FROM_UTF8: {
- - string sSrc(Text::fromUtf8(reinterpret_cast<char*>(src)));
- - char* cDst = static_cast<char*>(dst);
- - len = (sSrc.size() < len) ? sSrc.size() : len;
- - strncpy(cDst, sSrc.c_str(), len);
- - return len;
- - }
- - case CONV_UTF8_TO_WIDE: {
- - wstring sSrc(Text::utf8ToWide(reinterpret_cast<char*>(src)));
- - wchar_t* cDst = static_cast<wchar_t*>(dst);
- - len = (sSrc.size() < len) ? sSrc.size() : len;
- - wcsncpy(cDst, sSrc.c_str(), len);
- - return len;
- - }
- - case CONV_WIDE_TO_UTF8: {
- - string sSrc(Text::wideToUtf8(reinterpret_cast<wchar_t*>(src)));
- - char* cDst = static_cast<char*>(dst);
- - len = (sSrc.size() < len) ? sSrc.size() : len;
- - strncpy(cDst, sSrc.c_str(), len);
- - return len;
- - }
- - case CONV_TO_BASE32: {
- - string sSrc(Encoder::toBase32(reinterpret_cast<uint8_t*>(src), len));
- - char* cDst = static_cast<char*>(dst);
- - len = (sSrc.size() < len) ? sSrc.size() : len;
- - strncpy(cDst, sSrc.c_str(), len);
- - return len;
- - }
- - case CONV_FROM_BASE32:
- - Encoder::fromBase32(reinterpret_cast<char*>(src), reinterpret_cast<uint8_t*>(dst), len);
- - return 0;
- - default:
- - // No value is better than the other
- - return string::npos;
- - }
- +// Functions for DCConnection
- +void PluginApiImpl::sendProtocolCmd(ConnectionDataPtr conn, const char* cmd) {
- + reinterpret_cast<UserConnection*>(conn->object)->sendRaw(cmd);
- }
- -// Default callback for hook CALLBACK_BASE
- -Bool PluginApiImpl::coreCallback(uint32_t eventId, dcptr_t pData) {
- - switch(eventId) {
- - case DBG_MESSAGE:
- - case LOG_MESSAGE:
- - LogManager::getInstance()->message(reinterpret_cast<const char*>(pData));
- - break;
- - case GET_PATHS: {
- - TextDataCondPtr args = reinterpret_cast<TextDataCondPtr>(pData);
- - args->res = const_cast<char*>(Util::getPath(static_cast<Util::Paths>(args->cond)).c_str());
- - break;
- - }
- - case PROTOCOL_SEND_UDP: {
- - TextDataCondPtr args = reinterpret_cast<TextDataCondPtr>(pData);
- - try { apiSocket.writeTo(args->data, Util::toString(args->cond), args->res); }
- - catch(const Exception& e) { dcdebug("CoreCallback, PROTOCOL_SEND_UDP: %s\n", e.getError().c_str()); }
- - break;
- - }
- - case PROTOCOL_HUB_EMULATE_CMD: {
- - TextArgsResPtr args = reinterpret_cast<TextArgsResPtr>(pData);
- - if(args->object) reinterpret_cast<Client*>(args->object)->emulateCommand(args->data);
- - break;
- - }
- - case PROTOCOL_HUB_SEND_CMD: {
- - TextArgsResPtr args = reinterpret_cast<TextArgsResPtr>(pData);
- - if(args->object) reinterpret_cast<Client*>(args->object)->send(args->data);
- - break;
- - }
- - case PROTOCOL_CONN_SEND_CMD: {
- - TextArgsResPtr args = reinterpret_cast<TextArgsResPtr>(pData);
- - if(args->object) reinterpret_cast<UserConnection*>(args->object)->sendRaw(args->data);
- - break;
- - }
- - case PROTOCOL_CONN_TERMINATE: {
- - TextArgsCondPtr args = reinterpret_cast<TextArgsCondPtr>(pData);
- - if(args->object) reinterpret_cast<UserConnection*>(args->object)->disconnect(args->cond != False);
- - break;
- - }
- - case HUBS_CREATE_HUB: {
- - TextArgsResPtr args = reinterpret_cast<TextArgsResPtr>(pData);
- - return newClient(args->data, reinterpret_cast<ClientDataPtr>(args->res));
- - }
- - case HUBS_DESTROY_HUB:
- - if(pData) ClientManager::getInstance()->putClient(reinterpret_cast<Client*>(pData));
- - break;
- - case HUBS_FIND_HUB: {
- - TextArgsResPtr args = reinterpret_cast<TextArgsResPtr>(pData);
- - return findOnlineHub(args->data, reinterpret_cast<ClientDataPtr>(args->res));
- - }
- - case HUBS_SEND_CHAT: {
- - TextArgsCondPtr args = reinterpret_cast<TextArgsCondPtr>(pData);
- - sendHubMessage(reinterpret_cast<Client*>(args->object), args->data, args->cond != False);
- - break;
- - }
- - case HUBS_SEND_PM: {
- - TextArgsCondPtr args = reinterpret_cast<TextArgsCondPtr>(pData);
- - sendPrivateMessage(reinterpret_cast<OnlineUser*>(args->object), args->data, args->cond != False);
- - break;
- - }
- - case HUBS_SEND_LOCAL: {
- - TextArgsCondPtr args = reinterpret_cast<TextArgsCondPtr>(pData);
- - Client* client = reinterpret_cast<Client*>(args->object);
- - if(client) client->fire(ClientListener::ClientLine(), client, args->data, args->cond);
- - break;
- - }
- - case QUEUE_ADD_DL: {
- - QueueArgsPtr args = reinterpret_cast<QueueArgsPtr>(pData);
- - return addDownload(args->target, args->size, args->hash, args->res);
- - }
- - case QUEUE_REMOVE_DL:
- - QueueManager::getInstance()->remove(reinterpret_cast<const char*>(pData));
- - break;
- - case QUEUE_SET_PRIORITY: {
- - TextArgsCondPtr args = reinterpret_cast<TextArgsCondPtr>(pData);
- - if(args->object) reinterpret_cast<QueueItem*>(args->object)->setPriority(static_cast<QueueItem::Priority>(args->cond));
- - break;
- - }
- - default:
- - return False;
- - }
- - return True;
- +void PluginApiImpl::terminateConnection(ConnectionDataPtr conn, Bool graceless) {
- + reinterpret_cast<UserConnection*>(conn->object)->disconnect(graceless != False);
- +}
- +
- +void PluginApiImpl::sendUdpData(const char* ip, uint32_t port, dcptr_t data, size_t n) {
- + apiSocket.writeTo(ip, Util::toString(port), data, n);
- +}
- +
- +// Functions for DCUtils
- +size_t PluginApiImpl::toUtf8(char* dst, const char* src, size_t n) {
- + string sSrc(Text::toUtf8(src));
- + n = (sSrc.size() < n) ? sSrc.size() : n;
- + strncpy(dst, sSrc.c_str(), n);
- + return n;
- +}
- +
- +size_t PluginApiImpl::fromUtf8(char* dst, const char* src, size_t n) {
- + string sSrc(Text::fromUtf8(src));
- + n = (sSrc.size() < n) ? sSrc.size() : n;
- + strncpy(dst, sSrc.c_str(), n);
- + return n;
- +}
- +
- +size_t PluginApiImpl::Utf8toWide(wchar_t* dst, const char* src, size_t n) {
- + wstring sSrc(Text::utf8ToWide(src));
- + n = (sSrc.size() < n) ? sSrc.size() : n;
- + wcsncpy(dst, sSrc.c_str(), n);
- + return n;
- +}
- +
- +size_t PluginApiImpl::WidetoUtf8(char* dst, const wchar_t* src, size_t n) {
- + string sSrc(Text::wideToUtf8(src));
- + n = (sSrc.size() < n) ? sSrc.size() : n;
- + strncpy(dst, sSrc.c_str(), n);
- + return n;
- +}
- +
- +size_t PluginApiImpl::toBase32(char* dst, const uint8_t* src, size_t n) {
- + string sSrc(Encoder::toBase32(src, n));
- + n = (sSrc.size() < n) ? sSrc.size() : n;
- + strncpy(dst, sSrc.c_str(), n);
- + return n;
- +}
- +
- +size_t PluginApiImpl::fromBase32(uint8_t* dst, const char* src, size_t n) {
- + Encoder::fromBase32(src, dst, n);
- + return n;
- }
- -// Queue functions
- -Bool PluginApiImpl::addDownload(const string& fname, int64_t fsize, const string& fhash, QueueDataPtr data) {
- - Bool bRes = False;
- +// Functions for DCQueue
- +QueueDataPtr PluginApiImpl::addDownload(const char* hash, uint64_t size, const char* target) {
- + QueueData* data = NULL;
- try {
- - string target = File::isAbsolute(fname) ? fname : SETTING(DOWNLOAD_DIRECTORY) + fname;
- - QueueManager::getInstance()->add(target, fsize, TTHValue(fhash), HintedUser(UserPtr(), Util::emptyString));
- + string sTarget = File::isAbsolute(target) ? target : SETTING(DOWNLOAD_DIRECTORY) + target;
- + QueueManager::getInstance()->add(sTarget, size, TTHValue(hash), HintedUser(UserPtr(), Util::emptyString));
- - QueueManager::getInstance()->lockedOperation([data, &target, &bRes](const QueueItem::StringMap& lst) {
- - QueueItem::StringMap::const_iterator i;
- - if ((i = lst.find(&target)) != lst.end()) {
- - QueueItem* qi = i->second;
- - data->file = qi->getTargetFileName().c_str();
- - data->target = qi->getTarget().c_str();
- - data->location = qi->getTempTarget().c_str();
- - data->hash = qi->getTTH().data;
- - data->object = qi;
- - data->size = qi->getSize();
- - data->isFileList = qi->isSet(QueueItem::FLAG_USER_LIST) ? True : False;
- - bRes = True;
- + QueueManager::getInstance()->lockedOperation([&data, &sTarget](const QueueItem::StringMap& lst) {
- + auto i = lst.find(&sTarget);
- + if (i != lst.end()) {
- + data = i->second->getPluginObject();
- }
- });
- } catch(const Exception& e) {
- LogManager::getInstance()->message(e.getError());
- }
- - return bRes;
- + return data;
- }
- -// Hub functions
- -Bool PluginApiImpl::findOnlineHub(string hubUrl, ClientDataPtr data) {
- - auto& clients = ClientManager::getInstance()->getClients();
- -
- - for(auto i = clients.begin(); i != clients.end(); ++i) {
- - if(((*i)->getHubUrl() == hubUrl) && (*i)->isConnected()) {
- - Client* client = *i;
- - data->url = client->getHubUrl().c_str();
- - data->ip = client->getIp().c_str();
- - data->object = client;
- - Util::toString(data->port) = client->getPort();
- - data->protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
- - data->isOp = client->isOp() ? True : False;
- - data->isSecure = client->isSecure() ? True : False;
- - return True;
- - }
- +void PluginApiImpl::removeDownload(const char* target) {
- + QueueManager::getInstance()->remove(target);
- +}
- +
- +void PluginApiImpl::setPriority(QueueDataPtr qi, QueuePrio priority) {
- + reinterpret_cast<QueueItem*>(qi->object)->setPriority(static_cast<QueueItem::Priority>(priority));
- +}
- +
- +// Functions for DCHub
- +HubDataPtr PluginApiImpl::findOnlineHub(const char* url) {
- + ClientManager::getInstance()->lock();
- + const auto& list = ClientManager::getInstance()->getClients();
- +
- + for(auto i = list.begin(); i != list.end(); ++i) {
- + if(((*i)->getHubUrl() == url) && (*i)->isConnected())
- + return (*i)->getPluginObject();
- }
- - return False;
- + return NULL;
- }
- -Bool PluginApiImpl::newClient(const string& hubUrl, ClientDataPtr data) {
- - if(!SETTING(NICK).empty()) {
- - // Note, it is no use specifying any other info here...
- - Client* client = ClientManager::getInstance()->getClient(hubUrl);
- - client->setPassword(Util::emptyString);
- +HubDataPtr PluginApiImpl::newClient(const char* url, const char* nick, const char* password) {
- + HubData* data = findOnlineHub(url);
- +
- + if(data == NULL && !SETTING(NICK).empty()) {
- + Client* client = ClientManager::getInstance()->getClient(url);
- client->connect();
- + client->setPassword(password);
- + client->setCurrentNick(nick);
- - data->url = client->getHubUrl().c_str();
- - data->ip = client->getIp().c_str();
- - data->object = client;
- - Util::toString(data->port) = client->getPort();
- - data->protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
- - data->isOp = False;
- - data->isSecure = client->isSecure() ? True : False;
- - return True;
- + // check that socket is waitting for connection...
- + if(client->isConnected()) {
- + return client->getPluginObject();
- + }
- }
- - return False;
- + return data;
- }
- -void PluginApiImpl::sendHubMessage(Client* client, const string& message, bool thirdPerson) {
- - if(client) {
- +void PluginApiImpl::sendHubMessage(HubDataPtr hub, const char* message, Bool thirdPerson) {
- + if(hub && hub->object) {
- + Client* client = reinterpret_cast<Client*>(hub->object);
- +
- // Lets make plugins life easier...
- ParamMap params;
- client->getMyIdentity().getParams(params, "my", true);
- client->getHubIdentity().getParams(params, "hub", false);
- - client->hubMessage(Util::formatParams(message, params, false), thirdPerson);
- + client->hubMessage(Util::formatParams(message, params), thirdPerson != False);
- }
- }
- -void PluginApiImpl::sendPrivateMessage(OnlineUserPtr ou, const string& message, bool thirdPerson) {
- - if(ou) {
- +void PluginApiImpl::sendPrivateMessage(UserDataPtr user, const char* message, Bool thirdPerson) {
- + if(user && user->object) {
- + OnlineUserPtr ou = reinterpret_cast<OnlineUser*>(user->object);
- +
- // Lets make plugins life easier...
- ParamMap params;
- ou->getIdentity().getParams(params, "user", true);
- ou->getClient().getMyIdentity().getParams(params, "my", true);
- ou->getClient().getHubIdentity().getParams(params, "hub", false);
- - ou->getClient().privateMessage(*ou, Util::formatParams(message, params, false), thirdPerson);
- + ClientManager::getInstance()->privateMessage(HintedUser(ou->getUser(), user->hubHint), Util::formatParams(message, params), thirdPerson != False);
- }
- }
- +void PluginApiImpl::deleteClient(HubDataPtr hub) {
- + ClientManager::getInstance()->putClient(reinterpret_cast<Client*>(hub->object));
- +}
- +
- +void PluginApiImpl::emulateProtocolCmd(HubDataPtr hub, const char* cmd) {
- + reinterpret_cast<Client*>(hub->object)->emulateCommand(cmd);
- +}
- +
- +void PluginApiImpl::sendProtocolCmd(HubDataPtr hub, const char* cmd) {
- + reinterpret_cast<Client*>(hub->object)->send(cmd);
- +}
- +
- +void PluginApiImpl::sendLocalMessage(HubDataPtr hub, const char* msg, MsgType type) {
- + Client* client = reinterpret_cast<Client*>(hub->object);
- + client->fire(ClientListener::ClientLine(), client, msg, type);
- +}
- +
- } // namespace dcpp
- /**
- * @file
- - * $Id: PluginApiImpl.cpp 722 2010-10-09 11:51:36Z crise $
- + * $Id: PluginApiImpl.cpp 1217 2012-01-08 16:15:57Z crise $
- */
- --- PluginApiImpl.h Tue Jan 20 00:26:36 1970
- +++ PluginApiImpl.h Tue Jan 20 00:26:36 1970
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
- + * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -24,44 +24,80 @@
- #ifndef DCPLUSPLUS_DCPP_PLUGIN_API_IMPL_H
- #define DCPLUSPLUS_DCPP_PLUGIN_API_IMPL_H
- +#include <cstdint>
- +
- +#include "typedefs.h"
- +#include "PluginDefs.h"
- +
- namespace dcpp {
- class PluginApiImpl
- {
- public:
- - static hookHandle initAPI(DCCore& dcCore);
- - static void releaseAPI(hookHandle hHook);
- + static void initAPI(DCCore& dcCore);
- + static void releaseAPI();
- private:
- // Functions for DCCore
- - static hookHandle DCAPI createHook(HookID hookId, HookType hookType, DCHOOK defProc);
- - static void DCAPI destroyHook(hookHandle hHook);
- -
- - static subsHandle DCAPI setHook(HookID hookId, DCHOOK hookProc, void* pCommon);
- - static Bool DCAPI callHook(HookID hookId, uint32_t eventId, dcptr_t pData);
- - static size_t DCAPI unHook(subsHandle hHook);
- -
- - static uint32_t DCAPI registerMessage(HookType type, const char* name);
- - static uint32_t DCAPI registerRange(HookType type, const char* name, uint32_t count);
- - static uint32_t DCAPI seekMessage(const char* name);
- + static intfHandle DCAPI registerInterface(const char* guid, dcptr_t funcs);
- + static dcptr_t DCAPI queryInterface(const char* guid);
- + static Bool DCAPI releaseInterface(intfHandle hInterface);
- +
- + // Functions for DCHooks
- + static hookHandle DCAPI createHook(const char* guid, DCHOOK defProc);
- + static Bool DCAPI destroyHook(hookHandle hHook);
- +
- + static subsHandle DCAPI bindHook(const char* guid, DCHOOK hookProc, void* pCommon);
- + static Bool DCAPI runHook(const char* guid, dcptr_t pObject, dcptr_t pData);
- + static size_t DCAPI releaseHook(subsHandle hHook);
- + // Functions For DCConfig
- + static const char* DCAPI getPath(PathType type);
- static void DCAPI setConfig(const char* guid, const char* setting, ConfigValuePtr val);
- static Bool DCAPI getConfig(const char* guid, const char* setting, ConfigValuePtr val);
- - static void* DCAPI memalloc(void* ptr, size_t bytes);
- - static size_t DCAPI strconv(ConversionType type, void* dst, void* src, size_t len);
- -
- - // Default callback for hook CALLBACK_BASE
- - static Bool DCAPI coreCallback(uint32_t eventId, dcptr_t pData);
- -
- - // Queue functions
- - static Bool addDownload(const string& fname, int64_t fsize, const string& fhash, QueueDataPtr data);
- + // Functions for DCLog
- + static void DCAPI log(const char* msg);
- - // Hub functions
- - static Bool findOnlineHub(string hubUrl, ClientDataPtr data);
- - static Bool newClient(const string& hubUrl, ClientDataPtr data);
- - static void sendHubMessage(Client* client, const string& message, bool thirdPerson);
- - static void sendPrivateMessage(OnlineUserPtr ou, const string& message, bool thirdPerson);
- + // Functions for DCConnection
- + static void DCAPI sendProtocolCmd(ConnectionDataPtr conn, const char* cmd);
- + static void DCAPI terminateConnection(ConnectionDataPtr conn, Bool graceless);
- + static void DCAPI sendUdpData(const char* ip, uint32_t port, dcptr_t data, size_t n);
- +
- + // Functions for DCUtils
- + static size_t DCAPI toUtf8(char* dst, const char* src, size_t n);
- + static size_t DCAPI fromUtf8(char* dst, const char* src, size_t n);
- +
- + static size_t DCAPI Utf8toWide(wchar_t* dst, const char* src, size_t n);
- + static size_t DCAPI WidetoUtf8(char* dst, const wchar_t* src, size_t n);
- +
- + static size_t DCAPI toBase32(char* dst, const uint8_t* src, size_t n);
- + static size_t DCAPI fromBase32(uint8_t* dst, const char* src, size_t n);
- +
- + // Functions for DCQueue
- + static QueueDataPtr DCAPI addDownload(const char* hash, uint64_t size, const char* target);
- + static void DCAPI removeDownload(const char* target);
- + static void DCAPI setPriority(QueueDataPtr qi, QueuePrio priority);
- +
- + // Functions for DCHub
- + static HubDataPtr DCAPI findOnlineHub(const char* url);
- + static HubDataPtr DCAPI newClient(const char* url, const char* nick, const char* password);
- + static void DCAPI sendHubMessage(HubDataPtr hub, const char* message, Bool thirdPerson);
- + static void DCAPI sendPrivateMessage(UserDataPtr user, const char* message, Bool thirdPerson);
- +
- + static void DCAPI deleteClient(HubDataPtr hub);
- + static void DCAPI emulateProtocolCmd(HubDataPtr hub, const char* cmd);
- + static void DCAPI sendProtocolCmd(HubDataPtr hub, const char* cmd);
- + static void DCAPI sendLocalMessage(HubDataPtr hub, const char* msg, MsgType type);
- +
- + static DCHooks dcHooks;
- + static DCConfig dcConfig;
- + static DCLog dcLog;
- +
- + static DCConnection dcConnection;
- + static DCHub dcHub;
- + static DCQueue dcQueue;
- + static DCUtils dcUtils;
- static Socket apiSocket;
- };
- @@ -72,5 +108,5 @@
- /**
- * @file
- - * $Id: PluginApiImpl.h 707 2010-09-03 15:40:16Z crise $
- + * $Id: PluginApiImpl.h 1217 2012-01-08 16:15:57Z crise $
- */
- --- PluginDefs.h Tue Jan 20 00:26:36 1970
- +++ PluginDefs.h Tue Jan 20 00:26:36 1970
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
- + * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -16,71 +16,6 @@
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- -/**
- - * API Stuff (just to put some things down)
- - *
- - * API Terms:
- - * 1. Node: User of the plugin API (both plugins and the host itself).
- - * 2. Hook: Generic term for message based channel between two nodes. Hook can be either inbound
- - * (called) our outboud (listened). Inbound hooks are referred as callbacks but their
- - * mechanics are mostly identical.
- - * - Main hook: a special hook which notifies plugins about changes in the API and
- - * its state (separate of the hooks system).
- - * - Default hook procedure: called after subscribers have been processed, if available.
- - *
- - * Host node implementation:
- - * 1§ Host is expected to implement all functions pointed directly by DCCore struct, with the
- - * notable exception of "strconv" which should be implemented to be platform, useage and
- - * environment relevant.
- - *
- - * 2§ set_hook and un_hook implementations must automatically create (if missing) and free hooks from
- - * HookID range [1, HOOK_USER] respectively. The type of any automatically created hooks should be
- - * HOOK_EVENT.
- - *
- - * 3§ Host node must create the callback CALLBACK_BASE, which is the only guaranteed callback between
- - * host node and (all of) the plugin nodes (this callback should be a hook of type HOOK_CALLBACK).
- - *
- - * 4§ Host is expected to implement at least one of the "common" outbound hooks, rest are optional.
- - *
- - * 5§ Hooks the host node chooses implement are expected to be complete or complemented, to a satisfactory
- - * degree, by plugin for the host.
- - *
- - * 6§ Host is required to implement only the callback events relevant to the implemented outbound hooks.
- - * Alternatively a plugin may complement (complete) the hosts supply of these by the means of
- - * callback overloading.
- - *
- - * 7§ Any completely platform specific callbacks or hooks are considered completely optional and
- - * plugins can be expected to handle this accordingly.
- - *
- - * Plugin node implementation:
- - * 1§ Plugin is required to export function pluginInit which must return pointer to a hook procedure
- - * that can handle main hook events (basic DCHOOK). Unless plugin explictly sets the common data
- - * when subscribing to a hook or a callback all hook procedures are of the simple variant.
- - *
- - * 2§ Most hooks are simple blocking type, however, even an event blocked by one node will get sent
- - * to any remaining nodes (sending process is linear, based on subscription order) though they can't
- - * unblock the event.
- - *
- - * 3§ Callback hooks are overloadable and differ slightly from above. They suppport both terminating the
- - * sending of the current event to remaining nodes as well as changing the blocking state on the fly.
- - * This allows callbacks to be overloaded by plugins. Example: host node uses default hook procedure
- - * to provide callbacks. Plugin subscribes to the hook and catches the event it needs then terminates
- - * so the default hook procedure won't get processed (callbacks can be implemented by all nodes, see below).
- - *
- - * 4§ Plugins can also intercommunicate and depend on each other because everyone can create and call hooks freely
- - * this also allows plugins to complement the hosts implementations of the API (as noted under Host node
- - * implementation). However, plugin intercom is something largely independant of the host and the API itself.
- - * To put it simply plugins have to "know each other", the API only allows for basic checking of dependencies
- - * based on plugin GUIDs.
- - *
- - * Misc implementation
- - * §1 Implementations that add additional messages or types to any of the groups of constants must always aim to
- - * preserve the existing constants and their values so that backwards compatibility is maintained.
- - *
- - * §2 Any constants should not exceed the absolute minium size requirements for an integer (ie. 16bit, [-32767, 32767])
- - * even though on most architectures today integer can be larger.
- - */
- -
- #ifndef DCPLUSPLUS_DCPP_PLUGIN_DEFS_H
- #define DCPLUSPLUS_DCPP_PLUGIN_DEFS_H
- @@ -89,10 +24,10 @@
- #endif
- /* Version of the plugin api (must change every time the API has changed) */
- -#define DCAPI_VER 0.50
- +#define DCAPI_VER 0.56
- /* The earliest version of the API that this version is backwards compatible with */
- -#define DCAPI_COMPATIBLE_VER 0.50
- +#define DCAPI_COMPATIBLE_VER 0.56
- #ifdef _WIN32
- # define DCAPI __stdcall
- @@ -103,14 +38,17 @@
- # define DCIMP __declspec(dllimport)
- # endif
- #else
- -# define DCAPI STDCALL
- +# ifdef STDCALL
- +# define DCAPI STDCALL
- +# else
- +# define DCAPI
- +# endif
- # define DCEXP __attribute__ ((visibility("default")))
- # define DCIMP __attribute__ ((visibility("default")))
- #endif
- #ifndef DCAPI_HOST
- -/* current STLPort GIT implements this */
- -# if _MSC_VER <= 1500 && (!defined(_STLPORT_VERSION) || (_STLPORT_VERSION < 0x600))
- +# if defined(_MSC_VER) && _MSC_VER <= 1500 && (!defined(_STLPORT_VERSION) || (_STLPORT_VERSION < 0x600))
- typedef signed __int8 int8_t;
- typedef signed __int16 int16_t;
- typedef signed __int32 int32_t;
- @@ -125,141 +63,79 @@
- # endif
- #endif
- -/* Hook types */
- -typedef enum tagHookType {
- - HOOK_ID = 0, /* Used by the message register functions, to register new hooks */
- - HOOK_CALLBACK, /* Callback (inbound) hook */
- - HOOK_EVENT /* Regular (outbound) hook */
- -} HookType;
- -
- -/* Hook IDs */
- -typedef enum tagHookID {
- - /* Mandatory callback hook */
- - CALLBACK_BASE = 0,
- -
- - /* Common hooks (none manadatory, however, one required) */
- - HOOK_PROTOCOL = 500,
- - HOOK_CHAT,
- - HOOK_HUBS,
- - HOOK_TIMER,
- - HOOK_QUEUE,
- - HOOK_UI,
- -
- - /* Plugin created hooks and callbacks (HOOK_USER + n) */
- - HOOK_USER = 1000
- -} HookID;
- -
- -typedef enum tagCallbackEvent {
- - /* Generic callback events */
- - DBG_MESSAGE = 0,
- - LOG_MESSAGE,
- - GET_PATHS,
- -
- - /* Protocol callback events */
- - PROTOCOL_SEND_UDP = 500,
- - PROTOCOL_HUB_EMULATE_CMD,
- - PROTOCOL_HUB_SEND_CMD,
- - PROTOCOL_CONN_SEND_CMD,
- - PROTOCOL_CONN_TERMINATE,
- -
- - /* Hub callback events */
- - HUBS_CREATE_HUB = 1000,
- - HUBS_DESTROY_HUB,
- - HUBS_FIND_HUB,
- - HUBS_SEND_CHAT,
- - HUBS_SEND_PM,
- - HUBS_SEND_LOCAL,
- -
- - /* Queue callback events */
- - QUEUE_ADD_DL = 1500,
- - QUEUE_REMOVE_DL,
- - QUEUE_SET_PRIORITY,
- -
- - /* [2000, 2499] Reserved for UI callback events */
- -
- - /* Plugin created callback events (CALLBACK_USER + n) */
- - CALLBACK_USER = 2500
- -} CallbackEvent;
- -
- -typedef enum tagHookEvent {
- - /* Main hook events (returned by pluginInit) */
- - ON_INSTALL = 0, /* Replaces ON_LOAD for the very first loading of the plugin */
- - ON_UNINSTALL, /* Replaces ON_UNLOAD when plugin is being uninstalled */
- - ON_LOAD, /* Sent after successful call to pluginInit */
- - ON_UNLOAD, /* Sent right before plugin is unloaded (no params) */
- - ON_CONFIGURE, /* Sent when user wants to configure the plugin (obj: obj: impl. dependant or NULL) */
- -
- - /* Chat hook events (HOOK_CHAT) */
- - CHAT_IN = 500, /* Incoming chat from hub (obj: ClientData) */
- - CHAT_OUT, /* Outgoing chat (obj: ClientData) */
- - CHAT_PM_IN, /* Incoming private message (obj: UserData) */
- - CHAT_PM_OUT, /* Outgoing private message (obj: UserData) */
- -
- - /* Timer hook events (HOOK_TIMER) */
- - TIMER_SECOND = 1000, /* Timer event fired once per second (tick value) */
- - TIMER_MINUTE, /* Timer event fired once per minute (tick value) */
- -
- - /* Hubs hook events (HOOK_HUBS) */
- - HUB_OFFLINE = 1500, /* Hub has just gone offline (obj: ClientData) */
- - HUB_ONLINE, /* (New) hub has just gone online (obj: ClientData) */
- -
- - /* Connections hook events (HOOK_PROTOCOL) */
- - HUB_IN = 2000, /* Incoming protocol messages from hub (obj: ClientData) */
- - HUB_OUT, /* Outgoing protocol message to hub (obj: ClientData) */
- - CONN_IN, /* Incoming client<->client protocol message (obj: ConnectionData) */
- - CONN_OUT, /* Outgoing client<->client protocol message (obj: ConnectionData) */
- -
- - /* Queue hook events (HOOK_QUEUE) */
- - QUEUE_ADD = 2500, /* (New) item has been added to download queue (obj: QueueData) */
- - QUEUE_MOVE, /* Download queue item has been moved to new location (obj: QueueData) */
- - QUEUE_REMOVE, /* Item has just been removed from download queue (obj: QueueData) */
- - QUEUE_FINISHED, /* Item has just finished downloading (obj: QueueData) */
- -
- - /* UI hook events (HOOK_UI) */
- - UI_CREATED = 3000, /* Host node UI has been created (if any, obj: impl. dependant) */
- - UI_CHAT_DISPLAY, /* Chat messages before displayed in chat (obj: StringData) */
- - UI_PROCESS_CHAT_CMD, /* Client side commands in chat (obj: CommandData) */
- -
- - /* Plugin created hook events (EVENT_USER + n) */
- - EVENT_USER = 3500
- -} HookEvent;
- -
- -/* Conversion functions */
- -typedef enum tagConversionType {
- - CONV_TO_UTF8 = 0, /* Convert string to UTF-8 */
- - CONV_FROM_UTF8, /* Reverse of CONV_TO_UTF8 */
- - CONV_UTF8_TO_WIDE, /* Convert UTF-8 string to wide character string */
- - CONV_WIDE_TO_UTF8, /* Reverse of CONV_UTF8_TO_WIDE */
- - CONV_TO_BASE32, /* Convert unsigned short data (uint8_t*, array) to string */
- - CONV_FROM_BASE32 /* Reverse of CONV_TO_BASE32 */
- -} ConversionType;
- +/* Interface GUID's */
- +#define INTERFACE_HOOKS "generic.plugins.DCHooks" /* This is *required* for plugins to actually be able to do anything */
- +
- +#define INTERFACE_CONFIG "generic.plugins.DCConfig" /* Config managemen */
- +#define INTERFACE_LOGGING "generic.plugins.DCLog" /* Logging functions */
- +
- +#define INTERFACE_DCPP_CONNECTIONS "dcpp.network.DCConnection" /* Client<->client connections */
- +#define INTERFACE_DCPP_HUBS "dcpp.network.DCHub" /* Hubs */
- +#define INTERFACE_DCPP_QUEUE "dcpp.queue.DCQueue" /* Download Queue (TODO: expand) */
- +#define INTERFACE_DCPP_UTILS "dcpp.utils.DCUtils" /* Utility and convenience functions */
- +
- +/* Hook GUID's for event system */
- +#define HOOK_CHAT_IN "dcpp.chat.onIncomingChat" /* Incoming chat from hub (obj: HubData) */
- +#define HOOK_CHAT_OUT "dcpp.chat.onOutgoingChat" /* Outgoing chat (obj: HubData) */
- +#define HOOK_CHAT_PM_IN "dcpp.chat.onIncomingPM" /* Incoming private message (obj: UserData) */
- +#define HOOK_CHAT_PM_OUT "dcpp.chat.onOutgoingPM" /* Outgoing private message (obj: UserData) */
- +
- +#define HOOK_TIMER_SECOND "dcpp.timer.onSecond" /* Timer event fired once per second (tick value) */
- +#define HOOK_TIMER_MINUTE "dcpp.timer.onMinute" /* Timer event fired once per minute (tick value) */
- +
- +#define HOOK_HUB_ONLINE "dcpp.hubs.onOnline" /* (New) hub has just gone online (obj: HubData) */
- +#define HOOK_HUB_OFFLINE "dcpp.hubs.onOffline" /* Hub has just gone offline (obj: HubData) */
- +
- +#define HOOK_NETWORK_HUB_IN "dcpp.network.onHubDataIn" /* Incoming protocol messages from hub (obj: HubData) */
- +#define HOOK_NETWORK_HUB_OUT "dcpp.network.onHubDataOut" /* Outgoing protocol message to hub (obj: HubData) */
- +#define HOOK_NETWORK_CONN_IN "dcpp.network.onClientDataIn" /* Incoming client<->client protocol message (obj: ConnectionData) */
- +#define HOOK_NETWORK_CONN_OUT "dcpp.network.onClientDataOut" /* Outgoing client<->client protocol message (obj: ConnectionData) */
- +
- +#define HOOK_QUEUE_ADD "dcpp.queue.onAdd" /* (New) item has been added to download queue (obj: QueueData) */
- +#define HOOK_QUEUE_MOVE "dcpp.queue.onMove" /* Download queue item has been moved to new location (obj: QueueData) */
- +#define HOOK_QUEUE_REMOVE "dcpp.queue.onRemove" /* Item has just been removed from download queue (obj: QueueData) */
- +#define HOOK_QUEUE_FINISHED "dcpp.queue.onFinished" /* Item has just finished downloading (obj: QueueData) */
- +
- +#define HOOK_UI_CREATED "dcpp.ui.onCreated" /* Host application UI has been created (if any, obj: impl. dependant) */
- +#define HOOK_UI_CHAT_DISPLAY "dcpp.ui.onChatDisplay" /* Chat messages before displayed in chat (obj: StringData) */
- +#define HOOK_UI_PROCESS_CHAT_CMD "dcpp.ui.onProcessCmd" /* Client side commands in chat (obj: CommandData) */
- +
- +/* Main hook events (returned by pluginInit) */
- +typedef enum tagPluginState {
- + ON_INSTALL = 0, /* Replaces ON_LOAD for the very first loading of the plugin */
- + ON_UNINSTALL, /* Replaces ON_UNLOAD when plugin is being uninstalled */
- + ON_LOAD, /* Sent after successful call to pluginInit (obj: DCCore) */
- + ON_UNLOAD, /* Sent right before plugin is unloaded (no params) */
- + ON_CONFIGURE /* Sent when user wants to configure the plugin (obj: DCCore, data: impl. dependant) */
- +} PluginState;
- +/* Argument types */
- typedef enum tagConfigType {
- - CFG_TYPE_REMOVE = -1, /* Config value will be removed */
- - CFG_TYPE_STRING, /* Config value is string */
- - CFG_TYPE_INT, /* Config value is 32bit integer */
- - CFG_TYPE_INT64 /* Config value is 64bit integer */
- + CFG_TYPE_REMOVE = -1, /* Config value will be removed */
- + CFG_TYPE_STRING, /* Config value is string */
- + CFG_TYPE_INT, /* Config value is 32bit integer */
- + CFG_TYPE_INT64 /* Config value is 64bit integer */
- } ConfigType;
- typedef enum tagProtocolType {
- - PROTOCOL_ADC = 0, /* Protocol used ís ADC */
- - PROTOCOL_NMDC, /* Protocol used is NMDC */
- - PROTOCOL_DHT /* DHT node (not used, reserved) */
- + PROTOCOL_ADC = 0, /* Protocol used ís ADC */
- + PROTOCOL_NMDC, /* Protocol used is NMDC */
- + PROTOCOL_DHT /* DHT node (not used, reserved) */
- } ProtocolType;
- typedef enum tagPathType {
- - PATH_GLOBAL_CONFIG = 0, /* Global configuration */
- - PATH_USER_CONFIG, /* Per-user configuration (queue, favorites, ...) */
- - PATH_USER_LOCAL, /* Per-user local data (cache, temp files, ...) */
- - PATH_RESOURCES, /* Various resources (help files etc) */
- - PATH_LOCALE /* Translations */
- + PATH_GLOBAL_CONFIG = 0, /* Global configuration */
- + PATH_USER_CONFIG, /* Per-user configuration (queue, favorites, ...) */
- + PATH_USER_LOCAL, /* Per-user local data (cache, temp files, ...) */
- + PATH_RESOURCES, /* Various resources (help files etc) */
- + PATH_LOCALE /* Translations */
- } PathType;
- typedef enum tagMsgType {
- - MSG_CLIENT = 0, /* General text style */
- - MSG_STATUS, /* Message in status bar */
- - MSG_SYSTEM, /* Message with system message format */
- - MSG_CHEAT /* Message with cheat message format */
- + MSG_CLIENT = 0, /* General text style */
- + MSG_STATUS, /* Message in status bar */
- + MSG_SYSTEM, /* Message with system message format */
- + MSG_CHEAT /* Message with cheat message format */
- } MsgType;
- typedef enum tagQueuePrio {
- @@ -272,8 +148,8 @@
- PRIO_HIGHEST
- } QueuePrio;
- -/* Types */
- -typedef void *hookHandle, *dcptr_t, *subsHandle;
- +/* Data types */
- +typedef void *hookHandle, *subsHandle, *intfHandle, *dcptr_t;
- typedef enum tagDCBool { dcFalse = 0, dcTrue } dcBool;
- /* Workaround for other bool defs */
- @@ -281,15 +157,9 @@
- #define True dcTrue
- #define False dcFalse
- -/* Hook function prototypes */
- -typedef Bool (DCAPI *DCHOOK) (uint32_t eventId, dcptr_t pData);
- -typedef Bool (DCAPI* DCHOOKEX) (uint32_t eventId, dcptr_t pData, Bool* bBreak);
- -typedef Bool (DCAPI* DCHOOKCOMMON) (uint32_t eventId, dcptr_t pData, void* pCommon);
- -typedef Bool (DCAPI* DCHOOKCOMMONEX)(uint32_t eventId, dcptr_t pData, void* pCommon, Bool* bBreak);
- -
- -/* Config Value (for get_cfg/set_cfg) */
- +/* Config Value */
- typedef struct tagConfigValue {
- - ConfigType type; /* Indicates which type value holds */
- + ConfigType type; /* Indicates which type value holds */
- union {
- const char* str;
- int32_t int32;
- @@ -299,265 +169,161 @@
- /* String Data (for substitutions) */
- typedef struct tagStringData {
- - dcptr_t object; /* Any related object (internal, may be omitted) */
- - const char* in; /* Incoming string */
- - char* out; /* Resulting new string (allocated with DCCore::memalloc) */
- + const char* in; /* Incoming string */
- + char* out; /* Resulting new string */
- } StringData, *StringDataPtr;
- /* Client side chat commands */
- typedef struct tagCommandData {
- - dcptr_t object; /* UserData or ClientData based on isPrivate */
- - const char* command; /* Command name */
- - const char* params; /* Command parameters passed */
- - Bool isPrivate; /* Used in a private context (private messages) */
- + const char* command; /* Command name */
- + const char* params; /* Command parameters passed */
- + Bool isPrivate; /* Used in a private context (private messages) */
- } CommandData, *CommandDataPtr;
- /* Users */
- typedef struct tagUserData {
- - const char* data; /* Data sent/received */
- - const char* hubHint; /* Contains hub url to find the user from */
- - const uint8_t* cid; /* User CID (raw data, size: 192 / 8) */
- - dcptr_t object; /* The source/destination for the data */
- - ProtocolType protocol; /* The protocol used */
- - Bool isOp; /* Whether user has a key or not */
- + const char* hubHint; /* Contains hub url to find the user from */
- + const uint8_t* cid; /* User CID (raw data, size: 192 / 8) */
- + dcptr_t object; /* The source/destination for the data */
- + ProtocolType protocol; /* The protocol used */
- + Bool isOp; /* Whether user has a key or not */
- union {
- - char nick[36]; /* Users nick (only valid in NMDC) */
- - uint32_t sid; /* Users SID (only valid in ADC) */
- + char nick[36]; /* Users nick (only valid in NMDC) */
- + uint32_t sid; /* Users SID (only valid in ADC) */
- } uid;
- } UserData, *UserDataPtr;
- -/* Hubs (clients) */
- -typedef struct tagClientData {
- - const char* data; /* Data sent/received */
- - const char* url; /* Hub url address */
- - const char* ip; /* Hub ip address */
- - dcptr_t object; /* The source/destination for the data */
- - uint16_t port; /* Hub port */
- - ProtocolType protocol; /* The protocol used */
- - Bool isOp; /* Whether we have a key on this hub or not */
- - Bool isSecure; /* True for TLS encrypted connections */
- -} ClientData, *ClientDataPtr;
- +/* Hubs */
- +typedef struct tagHubData {
- + const char* url; /* Hub url address */
- + const char* ip; /* Hub ip address */
- + dcptr_t object; /* The source/destination for the data */
- + uint16_t port; /* Hub port */
- + ProtocolType protocol; /* The protocol used */
- + Bool isOp; /* Whether we have a key on this hub or not */
- + Bool isSecure; /* True for TLS encrypted connections */
- +} HubData, *HubDataPtr;
- /* Client<->client connections */
- typedef struct tagConnectionData {
- - const char* data; /* The data sent/received */
- - const char* ip; /* The ip address (remote) for this connection */
- - dcptr_t object; /* The source/destination for the data */
- - uint16_t port; /* The port for this connection */
- - ProtocolType protocol; /* The protocol used */
- - Bool isOp; /* Whether user has a key or not */
- - Bool isSecure; /* True for TLS encrypted connections */
- + const char* ip; /* The ip address (remote) for this connection */
- + dcptr_t object; /* The source/destination for the data */
- + uint16_t port; /* The port for this connection */
- + ProtocolType protocol; /* The protocol used */
- + Bool isOp; /* Whether user has a key or not */
- + Bool isSecure; /* True for TLS encrypted connections */
- } ConnectionData, *ConnectionDataPtr;
- /* Queue items and files */
- typedef struct tagQueueData {
- - const char* file; /* File name */
- - const char* target; /* The *final* location for the file */
- - const char* location; /* The *current* location for the file (may be same as target) */
- - const uint8_t* hash; /* TTH hash of the file (raw data, size: 192 / 8) */
- - dcptr_t object; /* The source/destination for the data */
- - uint64_t size; /* File size (bytes) */
- - Bool isFileList; /* FileList download */
- + const char* file; /* File name */
- + const char* target; /* The *final* location for the file */
- + const char* location; /* The *current* location for the file (may be same as target) */
- + const uint8_t* hash; /* TTH hash of the file (raw data, size: 192 / 8) */
- + dcptr_t object; /* The source/destination for the data */
- + uint64_t size; /* File size (bytes) */
- + Bool isFileList; /* FileList download */
- } QueueData, *QueueDataPtr;
- /* Plugin meta data */
- typedef struct tagMetaData {
- - const char* name; /* Name of the plugin */
- - const char* author; /* Name/Nick of the plugin author */
- - const char* description; /* *Short* description of plugin functionality (may be multiple lines) */
- - const char* web; /* Authors website if any */
- - const char* guid; /* Plugins unique GUID */
- - const char** dependencies; /* Array of plugin dependencies */
- - uint32_t numDependencies; /* Number of plugin GUIDs in dependencies array */
- - double version; /* Plugin version */
- - double apiVersion; /* API version the plugin was compiled against */
- - double compatibleVersion; /* Earliest API version the plugin can be used with */
- + const char* name; /* Name of the plugin */
- + const char* author; /* Name/Nick of the plugin author */
- + const char* description; /* *Short* description of plugin functionality (may be multiple lines) */
- + const char* web; /* Authors website if any */
- + const char* guid; /* Plugins unique GUID */
- + const char** dependencies; /* Array of plugin dependencies */
- + uint32_t numDependencies; /* Number of plugin GUIDs in dependencies array */
- + double version; /* Plugin version */
- + double apiVersion; /* API version the plugin was compiled against */
- + double compatibleVersion; /* Earliest API version the plugin can be used with */
- } MetaData, *MetaDataPtr;
- -/* Interaction layer */
- +/* Plugin management */
- typedef struct tagDCCore {
- /* Core API version */
- double apiVersion;
- - /* Hook creation */
- - hookHandle (DCAPI *create_hook) (HookID hookId, HookType hookType, DCHOOK defProc);
- - void (DCAPI *destroy_hook) (hookHandle hHook);
- -
- - /* Hook interaction */
- - subsHandle (DCAPI *set_hook) (HookID hookId, DCHOOK hookProc, void* pCommon);
- - Bool (DCAPI *call_hook) (HookID hookId, uint32_t eventId, dcptr_t pData);
- - size_t (DCAPI *un_hook) (subsHandle hHook);
- -
- - /* Message regitster */
- - uint32_t (DCAPI *register_message) (HookType type, const char* name);
- - uint32_t (DCAPI *register_range) (HookType type, const char* name, uint32_t count);
- - uint32_t (DCAPI *seek_message) (const char* name);
- -
- - /* Settings management */
- - void (DCAPI *set_cfg) (const char* guid, const char* setting, ConfigValuePtr val);
- - Bool (DCAPI *get_cfg) (const char* guid, const char* setting, ConfigValuePtr val);
- -
- - /* General */
- - void* (DCAPI *memalloc) (void* ptr, size_t bytes);
- - size_t (DCAPI *strconv) (ConversionType type, void* dst, void* src, size_t len);
- + /* Interface registry */
- + intfHandle (DCAPI *register_interface) (const char* guid, dcptr_t cbFuncs);
- + dcptr_t (DCAPI *query_interface) (const char* guid);
- + Bool (DCAPI *release_interface) (intfHandle hCallbacks);
- } DCCore, *DCCorePtr;
- -/* For callback function arguments (after long thinking and with much regret) */
- -typedef struct tagTextDataCond {
- - const char* data;
- - uint32_t cond;
- - char* res;
- -} TextDataCond, *TextDataCondPtr;
- -
- -typedef struct tagTextArgsRes {
- - dcptr_t object;
- - const char* data;
- - dcptr_t res;
- -} TextArgsRes, *TextArgsResPtr;
- -
- -typedef struct tagTextArgsCond {
- - dcptr_t object;
- - const char* data;
- - uint32_t cond;
- -} TextArgsCond, *TextArgsCondPtr;
- -
- -typedef struct tagQueueArgs {
- - const char* target;
- - int64_t size;
- - const char* hash;
- - QueueDataPtr res;
- -} QueueArgs, *QueueArgsPtr;
- +/* Plugin main function */
- +typedef Bool (DCAPI* DCMAIN) (PluginState pluginState, DCCorePtr core, dcptr_t pData);
- -#ifndef DCAPI_HOST
- -/* And then some macros so no-one has to figure out what goes where above */
- -#define BASE_DBG_MESSAGE(core, aMsg) { core->call_hook(CALLBACK_BASE, DBG_MESSAGE, (dcptr_t)aMsg); }
- -#define BASE_LOG_MESSAGE(core, aMsg) { core->call_hook(CALLBACK_BASE, LOG_MESSAGE, (dcptr_t)aMsg); }
- -#define BASE_DESTROY_HUB(core, client) { core->call_hook(CALLBACK_BASE, HUBS_DESTROY_HUB, client); }
- -#define BASE_QUEUE_REMOVE_DL(core, aTarget) { core->call_hook(CALLBACK_BASE, QUEUE_REMOVE_DL, (dcptr_t)aTarget); }
- -
- -#define BASE_GET_PATHS(core, type, aData) \
- -{ \
- - TextDataCond args; \
- - memset(&args, 0, sizeof(TextDataCond)); \
- - args.cond = type; \
- - core->call_hook(CALLBACK_BASE, GET_PATHS, &args); \
- - aData = args.res; \
- -}
- -
- -#define BASE_SEND_UDP(core, aIP, aPort, aData) \
- -{ \
- - TextDataCond args; \
- - memset(&args, 0, sizeof(TextDataCond)); \
- - args.data = aIP; \
- - args.cond = aPort; \
- - args.res = (char*)aData; \
- - core->call_hook(CALLBACK_BASE, PROTOCOL_SEND_UDP, &args); \
- -}
- -
- -#define BASE_HUB_EMULATE_CMD(core, client, cmd) \
- -{ \
- - TextArgsRes args; \
- - memset(&args, 0, sizeof(TextArgsRes)); \
- - args.object = client; \
- - args.data = cmd; \
- - core->call_hook(CALLBACK_BASE, PROTOCOL_HUB_EMULATE_CMD, &args); \
- -}
- -
- -#define BASE_HUB_SEND_CMD(core, client, cmd) \
- -{ \
- - TextArgsRes args; \
- - memset(&args, 0, sizeof(TextArgsRes)); \
- - args.object = client; \
- - args.data = cmd; \
- - core->call_hook(CALLBACK_BASE, PROTOCOL_HUB_SEND_CMD, &args); \
- -}
- -
- -#define BASE_CONN_SEND_CMD(core, uc, cmd) \
- -{ \
- - TextArgsRes args; \
- - memset(&args, 0, sizeof(TextArgsRes)); \
- - args.object = uc; \
- - args.data = cmd; \
- - core->call_hook(CALLBACK_BASE, PROTOCOL_CONN_SEND_CMD, &args); \
- -}
- -
- -#define BASE_CONN_TERMINATE(core, uc, graceless) \
- -{ \
- - TextArgsCond args; \
- - memset(&args, 0, sizeof(TextArgsCond)); \
- - args.object = uc; \
- - args.cond = graceless; \
- - core->call_hook(CALLBACK_BASE, PROTOCOL_CONN_TERMINATE, &args); \
- -}
- -
- -#define BASE_CREATE_HUB(core, aUrl, aData) \
- -{ \
- - TextArgsRes args; \
- - memset(&args, 0, sizeof(TextArgsRes)); \
- - args.data = aUrl; \
- - args.res = aData; \
- - core->call_hook(CALLBACK_BASE, HUBS_CREATE_HUB, &args); \
- -}
- +/* Event system (required!) */
- -#define BASE_FIND_HUB(core, aUrl, aData) \
- -{ \
- - TextArgsRes args; \
- - memset(&args, 0, sizeof(TextArgsRes)); \
- - args.data = aUrl; \
- - args.res = aData; \
- - core->call_hook(CALLBACK_BASE, HUBS_FIND_HUB, &args); \
- -}
- -
- -#define BASE_HUB_SEND_CHAT(core, client, aMsg, third_person) \
- -{ \
- - TextArgsCond args; \
- - memset(&args, 0, sizeof(TextArgsCond)); \
- - args.object = client; \
- - args.data = aMsg; \
- - args.cond = third_person; \
- - core->call_hook(CALLBACK_BASE, HUBS_SEND_CHAT, &args); \
- -}
- -
- -#define BASE_HUB_SEND_PM(core, ou, aMsg, third_person) \
- -{ \
- - TextArgsCond args; \
- - memset(&args, 0, sizeof(TextArgsCond)); \
- - args.object = ou; \
- - args.data = aMsg; \
- - args.cond = third_person; \
- - core->call_hook(CALLBACK_BASE, HUBS_SEND_PM, &args); \
- -}
- +/* Hook function prototypes */
- +typedef Bool (DCAPI* DCHOOK) (dcptr_t pObject, dcptr_t pData, Bool* bBreak);
- +typedef Bool (DCAPI* DCHOOKCOMMON) (dcptr_t pObject, dcptr_t pData, void* pCommon, Bool* bBreak);
- -#define BASE_HUB_SEND_LOCAL(core, type, client, aMsg) \
- -{ \
- - TextArgsCond args; \
- - memset(&args, 0, sizeof(TextArgsCond)); \
- - args.object = client; \
- - args.data = aMsg; \
- - args.cond = type; \
- - core->call_hook(CALLBACK_BASE, HUBS_SEND_LOCAL, &args); \
- -}
- +/* Hook management */
- +typedef struct tagDCHooks {
- + /* Hook creation */
- + hookHandle (DCAPI *create_hook) (const char* guid, DCHOOK defProc);
- + Bool (DCAPI *destroy_hook) (hookHandle hHook);
- -#define BASE_QUEUE_ADD_DL(core, aTarget, aSize, aHash, aFlags, aData) \
- -{ \
- - QueueArgs args; \
- - memset(&args, 0, sizeof(QueueArgs)); \
- - args.target = aTarget; \
- - args.size = aSize; \
- - args.hash = aHash; \
- - args.res = aData; \
- - core->call_hook(CALLBACK_BASE, QUEUE_ADD_DL, &args); \
- -}
- + /* Hook interaction */
- + subsHandle (DCAPI *bind_hook) (const char* guid, DCHOOK hookProc, void* pCommon);
- + Bool (DCAPI *run_hook) (const char* guid, dcptr_t pObject, dcptr_t pData);
- + size_t (DCAPI *release_hook) (subsHandle hHook);
- +} DCHooks, *DCHooksPtr;
- +
- +/* Optional interfaces */
- +
- +/* Config management */
- +typedef struct tagDCConfig {
- + const char* (DCAPI *get_path) (PathType type);
- + void (DCAPI *set_cfg) (const char* guid, const char* setting, ConfigValuePtr val);
- + Bool (DCAPI *get_cfg) (const char* guid, const char* setting, ConfigValuePtr val);
- +} DCConfig, *DCConfigPtr;
- +
- +/* Logging functions */
- +typedef struct tagDCLog {
- + void (DCAPI *log) (const char* msg);
- +} DCLog, *DCLogPtr;
- -#define BASE_QUEUE_SET_PRIO(core, qi, aPrio) \
- -{ \
- - TextArgsCond args; \
- - memset(&args, 0, sizeof(TextArgsCond)); \
- - args.object = qi; \
- - args.cond = aPrio; \
- - core->call_hook(CALLBACK_BASE, QUEUE_SET_PRIO, &args); \
- -}
- -#endif
- +/* Client<->client connections */
- +typedef struct tagDCConnection {
- + void (DCAPI *send_udp_data) (const char* ip, uint32_t port, dcptr_t data, size_t n);
- + void (DCAPI *send_protocol_cmd) (ConnectionDataPtr hConn, const char* cmd);
- + void (DCAPI *terminate_conn) (ConnectionDataPtr hConn, Bool graceless);
- +} DCConnection, *DCConnectionPtr;
- +
- +/* Hubs */
- +typedef struct tagDCHub {
- + HubDataPtr (DCAPI *add_hub) (const char* url, const char* nick, const char* password);
- + HubDataPtr (DCAPI *find_hub) (const char* url);
- + void (DCAPI *remove_hub) (HubDataPtr hHub);
- +
- + void (DCAPI *emulate_protocol_cmd) (HubDataPtr hHub, const char* cmd);
- + void (DCAPI *send_protocol_cmd) (HubDataPtr hHub, const char* cmd);
- +
- + void (DCAPI *send_message) (HubDataPtr hHub, const char* msg, Bool thirdPerson);
- + void (DCAPI *local_message) (HubDataPtr hHub, const char* msg, MsgType type);
- + void (DCAPI *send_private_message) (UserDataPtr hUser, const char* msg, Bool thirdPerson);
- +} DCHub, *DCHubPtr;
- +
- +/* Download Queue (TODO: expand) */
- +typedef struct tagDCQueue {
- + QueueDataPtr (DCAPI *add_download) (const char* hash, uint64_t size, const char* target);
- + void (DCAPI *remove_download) (const char* target);
- + void (DCAPI *set_priority) (QueueDataPtr hItem, QueuePrio priority);
- +} DCQueue, *DCQueuePtr;
- +
- +/* Utility and convenience functions */
- +typedef struct tagDCUtils {
- + size_t (DCAPI *to_utf8) (char* dst, const char* src, size_t n);
- + size_t (DCAPI *from_utf8) (char* dst, const char* src, size_t n);
- +
- + size_t (DCAPI *utf8_to_wcs) (wchar_t* dst, const char* src, size_t n);
- + size_t (DCAPI *wcs_to_utf8) (char* dst, const wchar_t* src, size_t n);
- +
- + size_t (DCAPI *to_base32) (char* dst, const uint8_t* src, size_t n);
- + size_t (DCAPI *from_base32) (uint8_t* dst, const char* src, size_t n);
- +} DCUtils, *DCUtilsPtr;
- #ifdef __cplusplus
- }
- @@ -567,5 +333,5 @@
- /**
- * @file
- - * $Id: PluginDefs.h 715 2010-09-09 12:13:53Z crise $
- + * $Id: PluginDefs.h 1217 2012-01-08 16:15:57Z crise $
- */
- --- PluginManager.cpp Tue Jan 20 00:26:36 1970
- +++ PluginManager.cpp Tue Jan 20 00:26:36 1970
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
- + * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -17,13 +17,17 @@
- */
- #include "stdinc.h"
- -#include "DCPlusPlus.h"
- -
- #include "PluginManager.h"
- +
- +#include <utility>
- +
- #include "ConnectionManager.h"
- +#include "QueueManager.h"
- +#include "ClientManager.h"
- #include "StringTokenizer.h"
- #include "SimpleXML.h"
- #include "AdcHub.h"
- +#include "UserConnection.h"
- #ifdef _WIN32
- # define PLUGIN_EXT "*.dll"
- @@ -44,11 +48,11 @@
- namespace dcpp {
- -uint32_t PluginManager::msgMaps[3] = { HOOK_USER, CALLBACK_USER, EVENT_USER };
- +using std::swap;
- PluginInfo::~PluginInfo() {
- bool isSafe = true;
- - if(mainHook((PluginManager::getInstance()->getShutdown() ? ON_UNLOAD : ON_UNINSTALL), NULL) == False) {
- + if(dcMain((PluginManager::getInstance()->getShutdown() ? ON_UNLOAD : ON_UNINSTALL), NULL, NULL) == False) {
- // Plugin performs operation critical tasks (runtime unload not possible)
- isSafe = !PluginManager::getInstance()->addInactivePlugin(handle);
- } if(isSafe && handle != NULL) {
- @@ -58,9 +62,13 @@
- }
- void PluginManager::loadPlugins(void (*f)(void*, const string&), void* p) {
- - coreHook = PluginApiImpl::initAPI(dcCore);
- + PluginApiImpl::initAPI(dcCore);
- - StringTokenizer<string> st(getSetting("CoreSetup", "Plugins"), ";");
- + TimerManager::getInstance()->addListener(this);
- + ClientManager::getInstance()->addListener(this);
- + QueueManager::getInstance()->addListener(this);
- +
- + StringTokenizer<string> st(getPluginSetting("CoreSetup", "Plugins"), ";");
- for(StringIter i = st.getTokens().begin(); i != st.getTokens().end(); ++i) {
- if(!loadPlugin(*i) || !f) continue;
- (*f)(p, Util::getFileName(*i));
- @@ -69,9 +77,12 @@
- bool PluginManager::loadPlugin(const string& fileName, bool isInstall /*= false*/) {
- Lock l(cs);
- +
- + dcassert(dcCore.apiVersion != 0);
- +
- pluginHandle hr = LOAD_LIBRARY(fileName);
- if(!hr) {
- - LogManager::getInstance()->message("Error loading " + Util::getFileName(fileName) + ": " + GET_ERROR());
- + LogManager::getInstance()->message(str(F_("Error loading %1%: %2%") % Util::getFileName(fileName) % GET_ERROR()));
- return false;
- }
- @@ -79,13 +90,13 @@
- if(pluginInfo != NULL) {
- MetaData info;
- - memset(&info, 0, sizeof(MetaData));
- + memzero(&info, sizeof(MetaData));
- - DCHOOK mainHook;
- - if((mainHook = pluginInfo(&info)) != NULL) {
- + DCMAIN dcMain;
- + if((dcMain = pluginInfo(&info)) != NULL) {
- if(checkPlugin(info)) {
- - if(mainHook((isInstall ? ON_INSTALL : ON_LOAD), &dcCore) != False) {
- - plugins.push_back(new PluginInfo(fileName, hr, info, mainHook));
- + if(dcMain((isInstall ? ON_INSTALL : ON_LOAD), &dcCore, NULL) != False) {
- + plugins.push_back(new PluginInfo(fileName, hr, info, dcMain));
- return true;
- }
- }
- @@ -133,30 +144,28 @@
- }
- // Update plugin order
- - setSetting("CoreSetup", "Plugins", installed);
- + setPluginSetting("CoreSetup", "Plugins", installed);
- // Really unload plugins that have been flagged inactive (ON_UNLOAD returns False)
- - for(inactiveList::iterator i = inactive.begin(); i != inactive.end(); ++i)
- + for(auto i = inactive.begin(); i != inactive.end(); ++i)
- FREE_LIBRARY(*i);
- - if(hooks.size() > 1) {
- + if(!hooks.empty()) {
- // Destroy all hooks not freed correctly
- - for(hookList::iterator i = hooks.begin(); hooks.size() > 1;) {
- - if(i->second != coreHook) {
- - PluginHook* hook = i->second;
- - for_each(hook->subscribers.begin(), hook->subscribers.end(), DeleteFunction());
- - hook->subscribers.clear();
- - hooks.erase(i++);
- - delete hook;
- - } else ++i;
- + for(auto i = hooks.begin(); !hooks.empty();) {
- + PluginHook* hook = i->second;
- + for_each(hook->subscribers.begin(), hook->subscribers.end(), DeleteFunction());
- + hook->subscribers.clear();
- + hooks.erase(i++);
- + delete hook;
- }
- -
- - TimerManager::getInstance()->removeListener(this);
- - ClientManager::getInstance()->removeListener(this);
- - QueueManager::getInstance()->removeListener(this);
- }
- - PluginApiImpl::releaseAPI(coreHook);
- + TimerManager::getInstance()->removeListener(this);
- + ClientManager::getInstance()->removeListener(this);
- + QueueManager::getInstance()->removeListener(this);
- +
- + PluginApiImpl::releaseAPI();
- }
- void PluginManager::unloadPlugin(int index) {
- @@ -183,22 +192,16 @@
- // Functions that call the plugin
- bool PluginManager::onChatDisplay(Client* client, tstring& line) {
- - hookList::iterator i = hooks.find(HOOK_UI);
- - if(i == hooks.end()) return false;
- -
- StringData data;
- - memset(&data, 0, sizeof(StringData));
- + memzero(&data, sizeof(StringData));
- string tmpLine;
- - data.object = (client && client->isConnected()) ? client : NULL;
- data.in = Text::fromT(line, tmpLine).c_str();
- + HubData* object = client->getPluginObject();
- - if(callHook(i->second, UI_CHAT_DISPLAY, &data) && data.out != NULL) {
- + if(runHook(HOOK_UI_CHAT_DISPLAY, object, &data) && data.out != NULL) {
- line.clear();
- Text::toT(data.out, line);
- -
- - // NOTE: Here we rely on plugins using DCCore::memalloc
- - free(data.out);
- return true;
- }
- @@ -206,11 +209,8 @@
- }
- bool PluginManager::onChatCommand(Client* client, const string& line) {
- - hookList::iterator i = hooks.find(HOOK_UI);
- - if(i == hooks.end()) return false;
- -
- CommandData data;
- - memset(&data, 0, sizeof(CommandData));
- + memzero(&data, sizeof(CommandData));
- string cmd, param;
- string::size_type si = line.find(' ');
- @@ -221,38 +221,22 @@
- cmd = line.substr(1);
- }
- - ClientData object;
- - memset(&object, 0, sizeof(ClientData));
- -
- - object.data = line.c_str();
- - object.url = client->getHubUrl().c_str();
- - object.ip = client->getIp().c_str();
- - object.object = client;
- - Util::toString(object.port) = client->getPort();
- - object.protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
- - object.isOp = client->isOp() ? True : False;
- - object.isSecure = client->isSecure() ? True : False;
- -
- - data.object = &object;
- data.command = cmd.c_str();
- data.params = param.c_str();
- data.isPrivate = False;
- - return callHook(i->second, UI_PROCESS_CHAT_CMD, &data);
- + return runHook(HOOK_UI_PROCESS_CHAT_CMD, client->getPluginObject(), &data);
- }
- bool PluginManager::onChatCommandPM(const HintedUser& user, const string& line, bool isPriv) {
- - hookList::iterator i = hooks.find(HOOK_UI);
- - if(i == hooks.end()) return false;
- -
- // Hopefully this is safe...
- bool res = false;
- - auto lock = ClientManager::getInstance()->lock();
- + ClientManager::getInstance()->lock();
- OnlineUser* ou = ClientManager::getInstance()->findOnlineUser(user.user->getCID(), user.hint, isPriv);
- if(ou) {
- CommandData data;
- - memset(&data, 0, sizeof(CommandData));
- + memzero(&data, sizeof(CommandData));
- string cmd, param;
- string::size_type si = line.find(' ');
- @@ -263,411 +247,189 @@
- cmd = line.substr(1);
- }
- - UserData object;
- - memset(&object, 0, sizeof(UserData));
- -
- - object.data = line.c_str();
- - object.hubHint = ou->getClient().getHubUrl().c_str();
- - object.cid = ou->getUser()->getCID().data();
- - object.object = (dcptr_t)ou;
- - object.isOp = ou->getIdentity().isOp() ? True : False;
- - if(ou->getUser()->isNMDC()) {
- - object.protocol = PROTOCOL_NMDC;
- - strncpy(object.uid.nick, ou->getIdentity().getNick().c_str(), 35);
- - } else {
- - object.protocol = PROTOCOL_ADC;
- - object.uid.sid = ou->getIdentity().getSID();
- - }
- -
- - data.object = &object;
- data.command = cmd.c_str();
- data.params = param.c_str();
- data.isPrivate = True;
- - res = callHook(i->second, UI_PROCESS_CHAT_CMD, &data);
- + res = runHook(HOOK_UI_PROCESS_CHAT_CMD, ou->getPluginObject(), &data);
- }
- return res;
- }
- -bool PluginManager::onOutgoingChat(Client* client, const string& message) {
- - hookList::iterator i = hooks.find(HOOK_CHAT);
- - if(i == hooks.end()) return false;
- -
- - ClientData data;
- - memset(&data, 0, sizeof(ClientData));
- -
- - data.data = message.c_str();
- - data.url = client->getHubUrl().c_str();
- - data.ip = client->getIp().c_str();
- - data.object = client;
- - Util::toString(data.port) = client->getPort();
- - data.protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
- - data.isOp = client->isOp() ? True : False;
- - data.isSecure = client->isSecure() ? True : False;
- -
- - return callHook(i->second, CHAT_OUT, &data);
- -}
- -
- -bool PluginManager::onOutgoingPM(const OnlineUser& user, const string& message) {
- - hookList::iterator i = hooks.find(HOOK_CHAT);
- - if(i == hooks.end()) return false;
- -
- - UserData data;
- - memset(&data, 0, sizeof(UserData));
- -
- - data.data = message.c_str();
- - data.hubHint = user.getClient().getHubUrl().c_str();
- - data.cid = user.getUser()->getCID().data();
- - data.object = (dcptr_t)&user;
- - data.isOp = user.getIdentity().isOp() ? True : False;
- - if(user.getUser()->isNMDC()) {
- - data.protocol = PROTOCOL_NMDC;
- - strncpy(data.uid.nick, user.getIdentity().getNick().c_str(), 35);
- - } else {
- - data.protocol = PROTOCOL_ADC;
- - data.uid.sid = user.getIdentity().getSID();
- - }
- -
- - return callHook(i->second, CHAT_PM_OUT, &data);
- -}
- -
- -bool PluginManager::onIncomingChat(Client* client, const string& message) {
- - hookList::iterator i = hooks.find(HOOK_CHAT);
- - if(i == hooks.end()) return false;
- -
- - ClientData data;
- - memset(&data, 0, sizeof(ClientData));
- -
- - data.data = message.c_str();
- - data.url = client->getHubUrl().c_str();
- - data.ip = client->getIp().c_str();
- - data.object = client;
- - Util::toString(data.port) = client->getPort();
- - data.protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
- - data.isOp = client->isOp() ? True : False;
- - data.isSecure = client->isSecure() ? True : False;
- -
- - return callHook(i->second, CHAT_IN, &data);
- -}
- -
- -bool PluginManager::onIncomingPM(const OnlineUser* user, const string& message) {
- - hookList::iterator i = hooks.find(HOOK_CHAT);
- - if(i == hooks.end()) return false;
- -
- - UserData data;
- - memset(&data, 0, sizeof(UserData));
- -
- - data.data = message.c_str();
- - data.hubHint = user->getClient().getHubUrl().c_str();
- - data.cid = user->getUser()->getCID().data();
- - data.object = (dcptr_t)user;
- - data.isOp = user->getIdentity().isOp() ? True : False;
- - if(user->getUser()->isNMDC()) {
- - data.protocol = PROTOCOL_NMDC;
- - strncpy(data.uid.nick, user->getIdentity().getNick().c_str(), 35);
- - } else {
- - data.protocol = PROTOCOL_ADC;
- - data.uid.sid = user->getIdentity().getSID();
- +// Plugin interface registry
- +intfHandle PluginManager::registerInterface(const string& guid, dcptr_t funcs) {
- + if(interfaces.find(guid) == interfaces.end())
- + interfaces.insert(make_pair(guid, funcs));
- + // Following ensures that only the original provider may remove this
- + return reinterpret_cast<intfHandle>((uintptr_t)funcs ^ secNum);
- +}
- +
- +dcptr_t PluginManager::queryInterface(const string& guid) {
- + auto i = interfaces.find(guid);
- + if(i != interfaces.end()) {
- + return i->second;
- + } else return NULL;
- +}
- +
- +bool PluginManager::releaseInterface(intfHandle hInterface) {
- + // Following ensures that only the original provider may remove this
- + dcptr_t funcs = reinterpret_cast<dcptr_t>((uintptr_t)hInterface ^ secNum);
- + for(auto i = interfaces.begin(); i != interfaces.end(); ++i) {
- + if(i->second == funcs) {
- + interfaces.erase(i);
- + return true;
- + }
- }
- -
- - return callHook(i->second, CHAT_PM_IN, &data);
- -}
- -
- -bool PluginManager::onIncomingHubData(Client* client, const string& message) {
- - hookList::iterator i = hooks.find(HOOK_PROTOCOL);
- - if(i == hooks.end()) return false;
- -
- - ClientData data;
- - memset(&data, 0, sizeof(ClientData));
- -
- - data.data = message.c_str();
- - data.url = client->getHubUrl().c_str();
- - data.ip = client->getIp().c_str();
- - data.object = client;
- - Util::toString(data.port) = client->getPort();
- - data.protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
- - data.isOp = client->isOp() ? True : False;
- - data.isSecure = client->isSecure() ? True : False;
- -
- - return callHook(i->second, HUB_IN, &data);
- -}
- -
- -bool PluginManager::onOutgoingHubData(Client* client, const string& message) {
- - hookList::iterator i = hooks.find(HOOK_PROTOCOL);
- - if(i == hooks.end()) return false;
- -
- - ClientData data;
- - memset(&data, 0, sizeof(ClientData));
- -
- - data.data = message.c_str();
- - data.url = client->getHubUrl().c_str();
- - data.ip = client->getIp().c_str();
- - data.object = client;
- - Util::toString(data.port) = client->getPort();
- - data.protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
- - data.isOp = client->isOp() ? True : False;
- - data.isSecure = client->isSecure() ? True : False;
- -
- - return callHook(i->second, HUB_OUT, &data);
- -}
- -
- -bool PluginManager::onIncomingConnectionData(UserConnection* uc, const string& message) {
- - hookList::iterator i = hooks.find(HOOK_PROTOCOL);
- - if(i == hooks.end()) return false;
- -
- - ConnectionData data;
- - memset(&data, 0, sizeof(ConnectionData));
- -
- - data.data = message.c_str();
- - data.ip = uc->getRemoteIp().c_str();
- - data.object = uc;
- - Util::toString(data.port) = uc->getPort();
- - data.protocol = (message[0] == '$') ? PROTOCOL_NMDC : PROTOCOL_ADC;
- - data.isOp = uc->isSet(UserConnection::FLAG_OP) ? True : False;
- - data.isSecure = uc->isSecure() ? True : False;
- -
- - return callHook(i->second, CONN_IN, &data);
- -}
- -
- -bool PluginManager::onOutgoingConnectionData(UserConnection* uc, const string& message) {
- - hookList::iterator i = hooks.find(HOOK_PROTOCOL);
- - if(i == hooks.end()) return false;
- -
- - ConnectionData data;
- - memset(&data, 0, sizeof(ConnectionData));
- -
- - data.data = message.c_str();
- - data.ip = uc->getRemoteIp().c_str();
- - data.object = uc;
- - Util::toString(data.port) = uc->getPort();
- - data.protocol = (message[0] == '$') ? PROTOCOL_NMDC : PROTOCOL_ADC;
- - data.isOp = uc->isSet(UserConnection::FLAG_OP) ? True : False;
- - data.isSecure = uc->isSecure() ? True : False;
- -
- - return callHook(i->second, CONN_OUT, &data);
- + return false;
- }
- -// Hook functions
- -hookHandle PluginManager::createHook(HookID hookId, HookType hookType, DCHOOK defProc) {
- - Lock l((hookType == HOOK_EVENT) ? csHook : csCb);
- +// Plugin Hook system
- +PluginHook* PluginManager::createHook(const string& guid, DCHOOK defProc) {
- + Lock l(csHook);
- - hookList::iterator i = hooks.find(hookId);
- + auto i = hooks.find(guid);
- if(i != hooks.end()) return NULL;
- PluginHook* hook = new PluginHook();
- - hook->id = hookId;
- - hook->type = hookType;
- + hook->guid = guid;
- hook->defProc = defProc;
- - hooks[hookId] = hook;
- + hooks[guid] = hook;
- return hook;
- }
- -void PluginManager::destroyHook(hookHandle hHook) {
- - PluginHook* hook = (PluginHook*)hHook;
- - hookList::iterator i;
- -
- - Lock l((hook->type == HOOK_EVENT) ? csHook : csCb);
- +bool PluginManager::destroyHook(PluginHook* hook) {
- + Lock l(csHook);
- - if((i = hooks.find(hook->id)) != hooks.end()) {
- + auto i = hooks.find(hook->guid);
- + if(i != hooks.end()) {
- for_each(hook->subscribers.begin(), hook->subscribers.end(), DeleteFunction());
- hook->subscribers.clear();
- hooks.erase(i);
- delete hook;
- - }
- + return true;
- + } else return false;
- }
- -subsHandle PluginManager::setHook(HookID hookId, DCHOOK hookProc, void* pCommon) {
- +HookSubscriber* PluginManager::bindHook(const string& guid, DCHOOK hookProc, void* pCommon) {
- + Lock l(csHook);
- +
- PluginHook* hook;
- - hookList::iterator i = hooks.find(hookId);
- + auto i = hooks.find(guid);
- - // Handle "common" hooks
- if(i == hooks.end()) {
- - if(hookId < HOOK_USER) {
- - hook = (PluginHook*)createHook(hookId, HOOK_EVENT, NULL);
- - switch(hookId) {
- - case HOOK_TIMER: TimerManager::getInstance()->addListener(this); break;
- - case HOOK_HUBS: ClientManager::getInstance()->addListener(this); break;
- - case HOOK_QUEUE: QueueManager::getInstance()->addListener(this); break;
- - default: /* do nothing - except silence mingw */ break;
- - }
- - } else return NULL;
- + return NULL;
- } else hook = i->second;
- - Lock l((hook->type == HOOK_EVENT) ? csHook : csCb);
- -
- HookSubscriber* subscribtion = new HookSubscriber();
- subscribtion->hookProc = hookProc;
- subscribtion->common = pCommon;
- - subscribtion->owner = hookId;
- + subscribtion->owner = hook->guid;
- hook->subscribers.push_back(subscribtion);
- return subscribtion;
- }
- -bool PluginManager::callHook(PluginHook* hook, uint32_t eventId, dcptr_t pData) {
- - Lock l((hook->type == HOOK_EVENT) ? csHook : csCb);
- +bool PluginManager::runHook(const string& guid, dcptr_t pObject, dcptr_t pData) {
- + Lock l(csHook);
- +
- + PluginHook* hook;
- + auto i = hooks.find(guid);
- +
- + if(i == hooks.end()) {
- + return false;
- + } else hook = i->second;
- Bool bBreak = False;
- Bool bRes = False;
- - for(PluginHook::subsList::const_iterator i = hook->subscribers.begin(); i != hook->subscribers.end(); ++i) {
- + for(auto i = hook->subscribers.cbegin(); i != hook->subscribers.cend(); ++i) {
- HookSubscriber* sub = *i;
- - switch(hook->type) {
- - case HOOK_CALLBACK:
- - bRes = (sub->common ? sub->hookProcCommonEx(eventId, pData, sub->common, &bBreak) : sub->hookProcEx(eventId, pData, &bBreak));
- - if(bBreak)
- - return (bRes != False);
- - break;
- - case HOOK_EVENT:
- - if(sub->common ? sub->hookProcCommon(eventId, pData, sub->common) : sub->hookProc(eventId, pData))
- - bRes = True;
- - break;
- - default:
- - dcassert(0);
- - }
- + if(sub->common ? sub->hookProcCommon(pObject, pData, sub->common, &bBreak) : sub->hookProc(pObject, pData, &bBreak))
- + bRes = True;
- + if(bBreak) return (bRes != False);
- }
- - // Call default hook procedure for all unused hooks and overloadables
- - if(hook->defProc && (hook->subscribers.empty() || hook->type == HOOK_CALLBACK)) {
- - if(hook->defProc(eventId, pData))
- + // Call default hook procedure for all unused hooks
- + if(hook->defProc && hook->subscribers.empty()) {
- + if(hook->defProc(pObject, pData, &bBreak))
- bRes = True;
- }
- return (bRes != False);
- }
- -size_t PluginManager::unHook(subsHandle hHook) {
- - if(hHook == NULL)
- +size_t PluginManager::releaseHook(HookSubscriber* subscription) {
- + Lock l(csHook);
- +
- + if(subscription == NULL)
- return 0;
- - hookList::iterator i;
- PluginHook* hook = NULL;
- - HookSubscriber* subscription = reinterpret_cast<HookSubscriber*>(hHook);
- - if((i = hooks.find(subscription->owner)) != hooks.end())
- + auto i = hooks.find(subscription->owner);
- + if(i != hooks.end())
- hook = i->second;
- if(hook == NULL)
- return 0;
- - Lock l((hook->type == HOOK_EVENT) ? csHook : csCb);
- -
- hook->subscribers.erase(std::remove(hook->subscribers.begin(), hook->subscribers.end(), subscription), hook->subscribers.end());
- delete subscription;
- - // Handle "common" hooks
- - if(hook->subscribers.empty() && hook->id < HOOK_USER) {
- - switch(hook->id) {
- - case HOOK_TIMER: TimerManager::getInstance()->removeListener(this); break;
- - case HOOK_HUBS: ClientManager::getInstance()->removeListener(this); break;
- - case HOOK_QUEUE: QueueManager::getInstance()->removeListener(this); break;
- - default: /* do nothing - except silence mingw */ break;
- - }
- - hooks.erase(i);
- - delete hook; return 0;
- - }
- -
- return hook->subscribers.size();
- }
- -// Listeners
- -void PluginManager::on(TimerManagerListener::Second, uint64_t ticks) throw() {
- - callHook(hooks.find(HOOK_TIMER)->second, TIMER_SECOND, &ticks);
- -}
- -
- -void PluginManager::on(TimerManagerListener::Minute, uint64_t ticks) throw() {
- - callHook(hooks.find(HOOK_TIMER)->second, TIMER_MINUTE, &ticks);
- +// Plugin configuration
- +void PluginManager::setPluginSetting(const string& pluginName, const string& setting, const string& value) {
- + settings[pluginName][setting] = value;
- +}
- +
- +const string& PluginManager::getPluginSetting(const string& pluginName, const string& setting) {
- + auto i = settings.find(pluginName);
- + if(i != settings.end()) {
- + auto j = i->second.find(setting);
- + if(j != i->second.end())
- + return j->second;
- + }
- + return Util::emptyString;
- +}
- +
- +void PluginManager::removePluginSetting(const string& pluginName, const string& setting) {
- + auto i = settings.find(pluginName);
- + if(i != settings.end()) {
- + auto j = i->second.find(setting);
- + if(j != i->second.end())
- + i->second.erase(j);
- + }
- }
- -void PluginManager::on(ClientManagerListener::ClientDisconnected, Client* aClient) throw() {
- - ClientData data;
- - memset(&data, 0, sizeof(ClientData));
- -
- - data.url = aClient->getHubUrl().c_str();
- - data.object = aClient;
- - data.protocol = dynamic_cast<AdcHub*>(aClient) ? PROTOCOL_ADC : PROTOCOL_NMDC;
- -
- - callHook(hooks.find(HOOK_HUBS)->second, HUB_OFFLINE, &data);
- +// Listeners
- +void PluginManager::on(ClientManagerListener::ClientConnected, Client* aClient) noexcept {
- + runHook(HOOK_HUB_ONLINE, aClient);
- }
- -void PluginManager::on(ClientManagerListener::ClientConnected, Client* aClient) throw() {
- - ClientData data;
- - memset(&data, 0, sizeof(ClientData));
- -
- - data.url = aClient->getHubUrl().c_str();
- - data.ip = aClient->getIp().c_str();
- - data.object = aClient;
- - Util::toString(data.port) = aClient->getPort();
- - data.protocol = dynamic_cast<AdcHub*>(aClient) ? PROTOCOL_ADC : PROTOCOL_NMDC;
- - data.isOp = aClient->isOp() ? True : False;
- - data.isSecure = aClient->isSecure() ? True : False;
- -
- - callHook(hooks.find(HOOK_HUBS)->second, HUB_ONLINE, &data);
- +void PluginManager::on(ClientManagerListener::ClientDisconnected, Client* aClient) noexcept {
- + runHook(HOOK_HUB_OFFLINE, aClient);
- }
- -void PluginManager::on(QueueManagerListener::Added, QueueItem* qi) throw() {
- - QueueData data;
- - memset(&data, 0, sizeof(QueueData));
- -
- - data.file = qi->getTargetFileName().c_str();
- - data.target = qi->getTarget().c_str();
- - data.location = qi->isFinished() ? data.target : qi->getTempTarget().c_str();
- - data.hash = qi->getTTH().data;
- - data.object = qi;
- - data.size = qi->getSize();
- - data.isFileList = qi->isSet(QueueItem::FLAG_USER_LIST) ? True : False;
- -
- - callHook(hooks.find(HOOK_QUEUE)->second, QUEUE_ADD, &data);
- +void PluginManager::on(QueueManagerListener::Added, QueueItem* qi) noexcept {
- + runHook(HOOK_QUEUE_ADD, qi);
- }
- -void PluginManager::on(QueueManagerListener::Moved, QueueItem* qi, const string&) throw() {
- - QueueData data;
- - memset(&data, 0, sizeof(QueueData));
- -
- - data.file = qi->getTargetFileName().c_str();
- - data.target = qi->getTarget().c_str();
- - data.location = qi->isFinished() ? data.target : qi->getTempTarget().c_str();
- - data.hash = qi->getTTH().data;
- - data.object = qi;
- - data.size = qi->getSize();
- - data.isFileList = qi->isSet(QueueItem::FLAG_USER_LIST) ? True : False;
- -
- - callHook(hooks.find(HOOK_QUEUE)->second, QUEUE_MOVE, &data);
- +void PluginManager::on(QueueManagerListener::Moved, QueueItem* qi, const string& /*aSource*/) noexcept {
- + runHook(HOOK_QUEUE_MOVE, qi);
- }
- -void PluginManager::on(QueueManagerListener::Removed, QueueItem* qi) throw() {
- - QueueData data;
- - memset(&data, 0, sizeof(QueueData));
- -
- - data.file = qi->getTargetFileName().c_str();
- - data.target = qi->getTarget().c_str();
- - data.location = qi->isFinished() ? data.target : qi->getTempTarget().c_str();
- - data.hash = qi->getTTH().data;
- - data.object = qi;
- - data.size = qi->getSize();
- - data.isFileList = qi->isSet(QueueItem::FLAG_USER_LIST) ? True : False;
- -
- - callHook(hooks.find(HOOK_QUEUE)->second, QUEUE_REMOVE, &data);
- +void PluginManager::on(QueueManagerListener::Removed, QueueItem* qi) noexcept {
- + runHook(HOOK_QUEUE_REMOVE, qi);
- }
- -// Finished items are no longer quaranteed to be removed right away
- -void PluginManager::on(QueueManagerListener::Finished, QueueItem* qi, const string&, int64_t) throw() {
- - QueueData data;
- - memset(&data, 0, sizeof(QueueData));
- -
- - data.file = qi->getTargetFileName().c_str();
- - data.target = qi->getTarget().c_str();
- - data.location = qi->isFinished() ? data.target : qi->getTempTarget().c_str();
- - data.hash = qi->getTTH().data;
- - data.object = qi;
- - data.size = qi->getSize();
- - data.isFileList = qi->isSet(QueueItem::FLAG_USER_LIST) ? True : False;
- -
- - callHook(hooks.find(HOOK_QUEUE)->second, QUEUE_FINISHED, &data);
- +void PluginManager::on(QueueManagerListener::Finished, QueueItem* qi, const string& /*dir*/, int64_t /*speed*/) noexcept {
- + runHook(HOOK_QUEUE_FINISHED, qi);
- }
- // Load / Save settings
- -void PluginManager::on(SettingsManagerListener::Load, SimpleXML& /*xml*/) throw() {
- +void PluginManager::on(SettingsManagerListener::Load, SimpleXML& /*xml*/) noexcept {
- Lock l(cs);
- try {
- @@ -680,9 +442,9 @@
- while(xml.findChild("Plugin")) {
- const string& pluginGuid = xml.getChildAttrib("Guid");
- xml.stepIn();
- - StringMap settings = xml.getCurrentChildren();
- - for(StringMapIter j = settings.begin(); j != settings.end(); ++j) {
- - setSetting(pluginGuid, j->first, j->second);
- + auto settings = xml.getCurrentChildren();
- + for(auto j = settings.cbegin(); j != settings.cend(); ++j) {
- + setPluginSetting(pluginGuid, j->first, j->second);
- }
- xml.stepOut();
- }
- @@ -693,17 +455,17 @@
- }
- }
- -void PluginManager::on(SettingsManagerListener::Save, SimpleXML& /*xml*/) throw() {
- +void PluginManager::on(SettingsManagerListener::Save, SimpleXML& /*xml*/) noexcept {
- Lock l(cs);
- try {
- SimpleXML xml;
- xml.addTag("Plugins");
- xml.stepIn();
- - for(settingsMap::const_iterator i = settings.begin(); i != settings.end(); ++i){
- + for(auto i = settings.cbegin(); i != settings.cend(); ++i){
- xml.addTag("Plugin");
- xml.stepIn();
- - for(StringMap::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
- + for(auto j = i->second.cbegin(); j != i->second.cend(); ++j) {
- xml.addTag(j->first, j->second);
- }
- xml.stepOut();
- @@ -727,5 +489,5 @@
- /**
- * @file
- - * $Id: PluginManager.cpp 712 2010-09-07 14:46:45Z crise $
- + * $Id: PluginManager.cpp 1217 2012-01-08 16:15:57Z crise $
- */
- --- PluginManager.h Tue Jan 20 00:26:36 1970
- +++ PluginManager.h Tue Jan 20 00:26:36 1970
- @@ -1,5 +1,5 @@
- /*
- - * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
- + * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -19,19 +19,15 @@
- #ifndef DCPLUSPLUS_DCPP_PLUGIN_MANAGER_H
- #define DCPLUSPLUS_DCPP_PLUGIN_MANAGER_H
- -#include <vector>
- -#include <algorithm>
- -
- -// for tstring
- -#include "DCPlusPlus.h"
- +#include "typedefs.h"
- #include "Singleton.h"
- #include "SettingsManager.h"
- #include "TimerManager.h"
- -#include "ClientManager.h"
- -#include "QueueManager.h"
- #include "LogManager.h"
- -#include "UserConnection.h"
- +
- +#include "QueueManagerListener.h"
- +#include "ClientManagerListener.h"
- #include "PluginDefs.h"
- #include "PluginApiImpl.h"
- @@ -44,28 +40,35 @@
- namespace dcpp {
- -using std::vector;
- -using std::swap;
- +// Internal types to plugin types
- +// - Grants plugin data types same scope as their equivalent internal types
- +template<typename PluginType>
- +class PluginEntity
- +{
- +public:
- + PluginEntity() { pod.object = NULL; }
- + virtual ~PluginEntity() { }
- +
- + virtual PluginType* getPluginObject() noexcept = 0;
- +
- +protected:
- + PluginType pod;
- +};
- // Represents a plugin in hook context
- struct HookSubscriber {
- union {
- DCHOOK hookProc;
- - DCHOOKEX hookProcEx;
- DCHOOKCOMMON hookProcCommon;
- - DCHOOKCOMMONEX hookProcCommonEx;
- };
- void* common;
- - HookID owner;
- + string owner;
- };
- -// Hookable event (or event group)
- +// Hookable event
- struct PluginHook {
- - typedef vector<HookSubscriber*> subsList;
- -
- - HookID id;
- - HookType type;
- - subsList subscribers;
- + string guid;
- + vector<HookSubscriber*> subscribers;
- DCHOOK defProc;
- };
- @@ -73,14 +76,14 @@
- class PluginInfo : private boost::noncopyable
- {
- public:
- - typedef DCHOOK (DCAPI *PLUGIN_INIT)(MetaDataPtr info);
- + typedef DCMAIN (DCAPI *PLUGIN_INIT)(MetaDataPtr info);
- - PluginInfo(const string& aFile, pluginHandle hInst, MetaData aInfo, DCHOOK aHook)
- - : mainHook(aHook), info(aInfo), file(aFile), handle(hInst) { };
- + PluginInfo(const string& aFile, pluginHandle hInst, MetaData aInfo, DCMAIN aMain)
- + : dcMain(aMain), info(aInfo), file(aFile), handle(hInst) { };
- ~PluginInfo();
- - DCHOOK mainHook;
- + DCMAIN dcMain;
- const MetaData& getInfo() const { return info; }
- const string& getFile() const { return file; }
- @@ -96,12 +99,12 @@
- public:
- typedef vector<PluginInfo*> pluginList;
- - PluginManager() : shutdown(false) {
- - memset(&dcCore, 0, sizeof(DCCore));
- + PluginManager() : shutdown(false), secNum(Util::rand()) {
- + memzero(&dcCore, sizeof(DCCore));
- SettingsManager::getInstance()->addListener(this);
- }
- - ~PluginManager() throw() {
- + ~PluginManager() {
- SettingsManager::getInstance()->removeListener(this);
- }
- @@ -118,33 +121,42 @@
- const pluginList& getPluginList() { Lock l(cs); return plugins; };
- const PluginInfo* getPlugin(uint32_t index) { Lock l(cs); return plugins[index]; }
- + DCCorePtr getCore() { return &dcCore; }
- +
- // Functions that call the plugin
- bool onChatDisplay(Client* client, tstring& line);
- bool onChatCommand(Client* client, const string& line);
- bool onChatCommandPM(const HintedUser& user, const string& line, bool isPriv);
- - bool onOutgoingChat(Client* client, const string& message);
- - bool onOutgoingPM(const OnlineUser& user, const string& message);
- - bool onIncomingChat(Client* client, const string& message);
- - bool onIncomingPM(const OnlineUser* user, const string& message);
- - bool onIncomingHubData(Client* client, const string& message);
- - bool onOutgoingHubData(Client* client, const string& message);
- - bool onIncomingConnectionData(UserConnection* uc, const string& message);
- - bool onOutgoingConnectionData(UserConnection* uc, const string& message);
- -
- - bool callHook(HookID hookId, uint32_t eventId, dcptr_t pData) {
- - hookList::iterator i = hooks.find(hookId);
- - if(i == hooks.end()) return false;
- - return callHook(i->second, eventId, pData);
- +
- + template<class T>
- + bool runHook(const string& guid, PluginEntity<T>* object) {
- + return runHook(guid, object->getPluginObject(), NULL);
- }
- -private:
- - friend class PluginApiImpl;
- + template<class T>
- + bool runHook(const string& guid, PluginEntity<T>* object, const string& data) {
- + return runHook(guid, object->getPluginObject(), (dcptr_t)data.c_str());
- + }
- +
- + // Plugin interface registry
- + intfHandle registerInterface(const string& guid, dcptr_t funcs);
- + dcptr_t queryInterface(const string& guid);
- + bool releaseInterface(intfHandle hInterface);
- +
- + // Plugin Hook system
- + PluginHook* createHook(const string& guid, DCHOOK defProc);
- + bool destroyHook(PluginHook* hook);
- +
- + HookSubscriber* bindHook(const string& guid, DCHOOK hookProc, void* pCommon);
- + bool runHook(const string& guid, dcptr_t pObject, dcptr_t pData);
- + size_t releaseHook(HookSubscriber* subscription);
- - typedef vector<pluginHandle> inactiveList;
- - typedef map<HookID, PluginHook*> hookList;
- - typedef map<string, StringMap> settingsMap;
- - typedef map<string, uint32_t> messageMap;
- + // Plugin configuration
- + void setPluginSetting(const string& pluginName, const string& setting, const string& value);
- + const string& getPluginSetting(const string& pluginName, const string& setting);
- + void removePluginSetting(const string& pluginName, const string& setting);
- +private:
- // Plugin finder
- struct PluginCompare {
- PluginCompare(const char* guid) : tmpGuid(guid) { }
- @@ -157,89 +169,34 @@
- // Check if plugin can be loaded
- bool checkPlugin(const MetaData& info);
- - // Hook functions
- - hookHandle createHook(HookID hookId, HookType hookType, DCHOOK defProc);
- - void destroyHook(hookHandle hHook);
- -
- - subsHandle setHook(HookID hookId, DCHOOK hookProc, void* pCommon);
- - bool callHook(PluginHook* hook, uint32_t eventId, dcptr_t pData);
- - size_t unHook(subsHandle hHook);
- -
- - // Settings management
- - void setSetting(const string& pluginName, const string& setting, const string& value) {
- - settings[pluginName][setting] = value;
- - }
- -
- - const string& getSetting(const string& pluginName, const string& setting) {
- - settingsMap::const_iterator i;
- - if((i = settings.find(pluginName)) != settings.end()) {
- - StringMap::const_iterator j;
- - if((j = i->second.find(setting)) != i->second.end())
- - return j->second;
- - }
- - return Util::emptyString;
- - }
- -
- - void removeSetting(const string& pluginName, const string& setting) {
- - settingsMap::iterator i;
- - if((i = settings.find(pluginName)) != settings.end()) {
- - StringMap::iterator j;
- - if((j = i->second.find(setting)) != i->second.end())
- - i->second.erase(j);
- - }
- - }
- -
- - // Message register (to avoid collisions with plugin defined messages)
- - uint32_t registerMessage(HookType type, const string& messageName) {
- - messageMap::const_iterator i;
- - if((i = messages.find(messageName)) == messages.end()) {
- - messages[messageName] = ++(msgMaps[type]);
- - return msgMaps[type];
- - } else return i->second;
- - }
- + // Listeners
- + void on(TimerManagerListener::Second, uint64_t ticks) noexcept { runHook(HOOK_TIMER_SECOND, NULL, &ticks); }
- + void on(TimerManagerListener::Minute, uint64_t ticks) noexcept { runHook(HOOK_TIMER_MINUTE, NULL, &ticks); }
- - uint32_t registerRange(HookType type, const string& messageName, uint32_t count) {
- - messageMap::const_iterator i;
- - if((i = messages.find(messageName)) == messages.end()) {
- - messages[messageName] = msgMaps[type] + 1;
- - msgMaps[type] += count;
- - return (msgMaps[type] - count) + 1;
- - } else return i->second;
- - }
- + void on(ClientManagerListener::ClientConnected, Client* aClient) noexcept;
- + void on(ClientManagerListener::ClientDisconnected, Client* aClient) noexcept;
- - uint32_t seekMessage(const string& messageName) {
- - messageMap::const_iterator i;
- - if((i = messages.find(messageName)) != messages.end())
- - return i->second;
- - return 0; // always reserved
- - }
- + void on(QueueManagerListener::Added, QueueItem* qi) noexcept;
- + void on(QueueManagerListener::Moved, QueueItem* qi, const string& /*aSource*/) noexcept;
- + void on(QueueManagerListener::Removed, QueueItem* qi) noexcept;
- + void on(QueueManagerListener::Finished, QueueItem* qi, const string& /*dir*/, int64_t /*speed*/) noexcept;
- - // Listeners
- - void on(TimerManagerListener::Second, uint64_t ticks) throw();
- - void on(TimerManagerListener::Minute, uint64_t ticks) throw();
- - void on(ClientManagerListener::ClientConnected, Client* aClient) throw();
- - void on(ClientManagerListener::ClientDisconnected, Client* aClient) throw();
- - void on(QueueManagerListener::Added, QueueItem* qi) throw();
- - void on(QueueManagerListener::Moved, QueueItem* qi, const string&) throw();
- - void on(QueueManagerListener::Removed, QueueItem* qi) throw();
- - void on(QueueManagerListener::Finished, QueueItem* qi, const string&, int64_t) throw();
- + void on(SettingsManagerListener::Load, SimpleXML& /*xml*/) noexcept;
- + void on(SettingsManagerListener::Save, SimpleXML& /*xml*/) noexcept;
- - void on(SettingsManagerListener::Load, SimpleXML& /*xml*/) throw();
- - void on(SettingsManagerListener::Save, SimpleXML& /*xml*/) throw();
- + pluginList plugins;
- + vector<pluginHandle> inactive;
- - // Tracks plugin reserved messages
- - static uint32_t msgMaps[3];
- + map<string, PluginHook*> hooks;
- + map<string, dcptr_t> interfaces;
- - pluginList plugins;
- - inactiveList inactive;
- - hookList hooks;
- - settingsMap settings;
- - messageMap messages;
- + map<string, StringMap> settings;
- DCCore dcCore;
- - CriticalSection cs, csHook, csCb;
- - hookHandle coreHook;
- + CriticalSection cs, csHook;
- bool shutdown;
- +
- + uintptr_t secNum;
- };
- } // namespace dcpp
- @@ -248,5 +205,5 @@
- /**
- * @file
- - * $Id: PluginManager.h 707 2010-09-03 15:40:16Z crise $
- + * $Id: PluginManager.h 1217 2012-01-08 16:15:57Z crise $
- */
- --- QueueItem.h Tue Jan 20 00:26:36 1970
- +++ QueueItem.h Tue Jan 20 00:26:36 1970
- @@ -38,7 +38,7 @@
- class QueueManager;
- -class QueueItem : public Flags, public FastAlloc<QueueItem> {
- +class QueueItem : public Flags, public FastAlloc<QueueItem>, public PluginEntity<QueueData> {
- public:
- typedef unordered_map<string*, QueueItemPtr, noCaseStringHash, noCaseStringEq> StringMap;
- @@ -179,6 +179,22 @@
- const string& getTempTarget();
- void setTempTarget(const string& aTempTarget) { tempTarget = aTempTarget; }
- +
- + QueueData* getPluginObject() noexcept {
- + pod.file = getTarget().c_str(); // yes, this member implemented like this is useless
- + pod.target = getTarget().c_str();
- + pod.location = isFinished() ? pod.target : getTempTarget().c_str();
- +
- + if(pod.object)
- + return &pod;
- +
- + pod.hash = tthRoot.data;
- + pod.object = this;
- + pod.size = size;
- + pod.isFileList = isSet(QueueItem::FLAG_USER_LIST) ? True : False;
- +
- + return &pod;
- + }
- GETSET(SegmentSet, done, Done);
- GETSET(DownloadList, downloads, Downloads);
- --- User.cpp Tue Jan 20 00:26:36 1970
- +++ User.cpp Tue Jan 20 00:26:36 1970
- @@ -33,6 +33,26 @@
- }
- +UserData* OnlineUser::getPluginObject() noexcept {
- + pod.isOp = getIdentity().isOp() ? True : False;
- + pod.hubHint = getClient().getHubUrl().c_str();
- +
- + if(pod.object)
- + return &pod;
- +
- + pod.cid = getUser()->getCID().data();
- + pod.object = this;
- + if(getUser()->isNMDC()) {
- + pod.protocol = PROTOCOL_NMDC;
- + strncpy(pod.uid.nick, getIdentity().getNick().c_str(), 35);
- + } else {
- + pod.protocol = PROTOCOL_ADC;
- + pod.uid.sid = getIdentity().getSID();
- + }
- +
- + return &pod;
- +}
- +
- bool Identity::isTcpActive() const {
- return isTcp4Active() || isTcp6Active();
- }
- --- UserConnection.cpp Tue Jan 20 00:26:36 1970
- +++ UserConnection.cpp Tue Jan 20 00:26:36 1970
- @@ -56,7 +56,10 @@
- return;
- }
- - if(PluginManager::getInstance()->onIncomingConnectionData(this, aLine))
- + if(aLine[0] == '$')
- + setFlag(FLAG_NMDC);
- +
- + if(PluginManager::getInstance()->runHook(HOOK_NETWORK_CONN_IN, this, aLine))
- return;
- if(aLine[0] == 'C' && !isSet(FLAG_NMDC)) {
- @@ -66,9 +69,7 @@
- }
- dispatch(aLine);
- return;
- - } else if(aLine[0] == '$') {
- - setFlag(FLAG_NMDC);
- - } else {
- + } else if(!isSet(FLAG_NMDC)) {
- fire(UserConnectionListener::ProtocolError(), this, _("Invalid data"));
- return;
- }
- @@ -267,11 +268,12 @@
- }
- void UserConnection::send(const string& aString) {
- - if(PluginManager::getInstance()->onOutgoingConnectionData(this, aString))
- - return;
- + if(PluginManager::getInstance()->runHook(HOOK_NETWORK_CONN_OUT, this, aString))
- + return;
- +
- + lastActivity = GET_TICK();
- + COMMAND_DEBUG(aString, DebugManager::CLIENT_OUT, getRemoteIp());
- + socket->write(aString);
- +}
- - lastActivity = GET_TICK();
- - COMMAND_DEBUG(aString, DebugManager::CLIENT_OUT, getRemoteIp());
- - socket->write(aString);
- - }
- } // namespace dcpp
- --- UserConnection.h Tue Jan 20 00:26:36 1970
- +++ UserConnection.h Tue Jan 20 00:26:36 1970
- @@ -33,7 +33,7 @@
- namespace dcpp {
- -class UserConnection : public Speaker<UserConnectionListener>,
- +class UserConnection : public PluginEntity<ConnectionData>, public Speaker<UserConnectionListener>,
- private BufferedSocketListener, public Flags, private CommandHandler<UserConnection>,
- private boost::noncopyable
- {
- @@ -193,6 +193,21 @@
- GETSET(States, state, State);
- GETSET(uint64_t, lastActivity, LastActivity);
- GETSET(double, speed, Speed);
- +
- + ConnectionData* getPluginObject() noexcept {
- + if(pod.object)
- + return &pod;
- +
- + pod.ip = getRemoteIp().c_str();
- + pod.object = this;
- + pod.port = Util::toInt(getPort());
- + pod.protocol = isSet(UserConnection::FLAG_NMDC) ? PROTOCOL_NMDC : PROTOCOL_ADC;
- + pod.isOp = isSet(UserConnection::FLAG_OP) ? True : False;
- + pod.isSecure = isSecure() ? True : False;
- +
- + return &pod;
- + }
- +
- private:
- int64_t chunkSize;
- BufferedSocket* socket;
Advertisement
Add Comment
Please, Sign In to add comment