iceman50

Untitled

Jan 11th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 106.85 KB | None | 0 0
  1. --- AdcHub.cpp  Tue Jan 20 00:26:36 1970
  2. +++ AdcHub.cpp  Tue Jan 20 00:26:36 1970
  3. @@ -276,9 +276,12 @@
  4.             return;
  5.  
  6.         message.replyTo = findUser(AdcCommand::toSID(temp));
  7. -       if(!message.replyTo || PluginManager::getInstance()->onIncomingPM(message.replyTo, message.text))
  8. +       if(!message.replyTo)
  9.             return;
  10. -   } else if(PluginManager::getInstance()->onIncomingChat(this, message.text))
  11. +
  12. +       if(PluginManager::getInstance()->runHook(HOOK_CHAT_PM_IN, message.replyTo, message.text))
  13. +           return;
  14. +   } else if(PluginManager::getInstance()->runHook(HOOK_CHAT_IN, this, message.text))
  15.         return;
  16.  
  17.     message.thirdPerson = c.hasFlag("ME", 1);
  18. @@ -707,8 +710,12 @@
  19.  }
  20.  
  21.  void AdcHub::hubMessage(const string& aMessage, bool thirdPerson) {
  22. -   if(state != STATE_NORMAL || PluginManager::getInstance()->onOutgoingChat(this, aMessage))
  23. +   if(state != STATE_NORMAL)
  24. +       return;
  25. +
  26. +   if(PluginManager::getInstance()->runHook(HOOK_CHAT_OUT, this, aMessage))
  27.         return;
  28. +
  29.     AdcCommand c(AdcCommand::CMD_MSG, AdcCommand::TYPE_BROADCAST);
  30.     c.addParam(aMessage);
  31.     if(thirdPerson)
  32. @@ -717,8 +724,9 @@
  33.  }
  34.  
  35.  void AdcHub::privateMessage(const OnlineUser& user, const string& aMessage, bool thirdPerson) {
  36. -   if(state != STATE_NORMAL || PluginManager::getInstance()->onOutgoingPM(user, aMessage))
  37. +   if(state != STATE_NORMAL)
  38.         return;
  39. +
  40.     AdcCommand c(AdcCommand::CMD_MSG, user.getIdentity().getSID(), AdcCommand::TYPE_ECHO);
  41.     c.addParam(aMessage);
  42.     if(thirdPerson)
  43. @@ -1120,7 +1128,7 @@
  44.         return;
  45.     }
  46.  
  47. -   if(PluginManager::getInstance()->onIncomingHubData(this, aLine))
  48. +   if(PluginManager::getInstance()->runHook(HOOK_NETWORK_HUB_IN, this, aLine))
  49.         return;
  50.  
  51.     dispatch(aLine);
  52. --- ChatMessage.h   Tue Jan 20 00:26:36 1970
  53. +++ ChatMessage.h   Tue Jan 20 00:26:36 1970
  54. @@ -32,7 +32,7 @@
  55.  
  56.     const OnlineUser* from;
  57.     const OnlineUser* to;
  58. -   const OnlineUser* replyTo;
  59. +   OnlineUser* replyTo;
  60.  
  61.     bool thirdPerson;
  62.     time_t timestamp;
  63. --- Client.cpp  Tue Jan 20 00:26:36 1970
  64. +++ Client.cpp  Tue Jan 20 00:26:36 1970
  65. @@ -19,12 +19,13 @@
  66.  #include "stdinc.h"
  67.  #include "Client.h"
  68.  
  69. +#include "AdcHub.h"
  70. +
  71.  #include "BufferedSocket.h"
  72.  #include "ClientManager.h"
  73.  #include "ConnectivityManager.h"
  74.  #include "DebugManager.h"
  75.  #include "FavoriteManager.h"
  76. -#include "PluginManager.h"
  77.  #include "TimerManager.h"
  78.  #include "UserMatchManager.h"
  79.  
  80. @@ -125,12 +126,32 @@
  81.  }
  82.  
  83.  void Client::send(const char* aMessage, size_t aLen) {
  84. -   if(!isConnected() || PluginManager::getInstance()->onOutgoingHubData(this, aMessage))
  85. +   if(!isConnected())
  86. +       return;
  87. +
  88. +   if(PluginManager::getInstance()->runHook(HOOK_NETWORK_HUB_OUT, this, aMessage))
  89.         return;
  90.  
  91.     updateActivity();
  92.     sock->write(aMessage, aLen);
  93.     COMMAND_DEBUG(aMessage, DebugManager::HUB_OUT, getIpPort());
  94. +}
  95. +
  96. +HubData* Client::getPluginObject() noexcept {
  97. +   pod.ip = ip.c_str();
  98. +   pod.isOp = isOp() ? True : False;
  99. +   // in case this is called before connection ís established
  100. +   pod.isSecure = isSecure() ? True : False;
  101. +
  102. +   if(pod.object)
  103. +       return &pod;
  104. +
  105. +   pod.url = hubUrl.c_str();
  106. +   pod.object = this;
  107. +   pod.port = Util::toInt(port);
  108. +   pod.protocol = dynamic_cast<AdcHub*>(this) ? PROTOCOL_ADC : PROTOCOL_NMDC;
  109. +
  110. +   return &pod;
  111.  }
  112.  
  113.  void Client::on(Connected) noexcept {
  114. --- Client.h    Tue Jan 20 00:26:36 1970
  115. +++ Client.h    Tue Jan 20 00:26:36 1970
  116. @@ -31,13 +31,14 @@
  117.  #include "ClientListener.h"
  118.  #include "OnlineUser.h"
  119.  #include "atomic.h"
  120. +#include "PluginManager.h"
  121.  
  122.  namespace dcpp {
  123.  
  124.  using std::list;
  125.  
  126.  /** Yes, this should probably be called a Hub */
  127. -class Client : public Speaker<ClientListener>, public BufferedSocketListener, protected TimerManagerListener {
  128. +class Client : public PluginEntity<HubData>, public Speaker<ClientListener>, public BufferedSocketListener, protected TimerManagerListener {
  129.  public:
  130.     virtual void connect();
  131.     virtual void disconnect(bool graceless);
  132. @@ -85,6 +86,8 @@
  133.  
  134.     void send(const string& aMessage) { send(aMessage.c_str(), aMessage.length()); }
  135.     void send(const char* aMessage, size_t aLen);
  136. +
  137. +   HubData* getPluginObject() noexcept;
  138.  
  139.     string getMyNick() const { return getMyIdentity().getNick(); }
  140.     string getHubName() const { return getHubIdentity().getNick().empty() ? getHubUrl() : getHubIdentity().getNick(); }
  141. --- ClientManager.cpp   Tue Jan 20 00:26:36 1970
  142. +++ ClientManager.cpp   Tue Jan 20 00:26:36 1970
  143. @@ -29,6 +29,7 @@
  144.  #include "SearchManager.h"
  145.  #include "SearchResult.h"
  146.  #include "ShareManager.h"
  147. +#include "PluginManager.h"
  148.  #include "SimpleXML.h"
  149.  #include "UserCommand.h"
  150.  
  151. @@ -434,7 +435,7 @@
  152.     Lock l(cs);
  153.     OnlineUser* u = findOnlineUser(user, priv);
  154.  
  155. -   if(u) {
  156. +   if(u && !PluginManager::getInstance()->runHook(HOOK_CHAT_PM_OUT, u, msg)) {
  157.         u->getClient().privateMessage(*u, msg, thirdPerson);
  158.     }
  159.  }
  160. --- NmdcHub.cpp Tue Jan 20 00:26:36 1970
  161. +++ NmdcHub.cpp Tue Jan 20 00:26:36 1970
  162. @@ -230,7 +230,7 @@
  163.             chatMessage.from = &o;
  164.         }
  165.  
  166. -       if(PluginManager::getInstance()->onIncomingChat(this, chatMessage.text))
  167. +       if(PluginManager::getInstance()->runHook(HOOK_CHAT_IN, this, chatMessage.text))
  168.             return;
  169.  
  170.         fire(ClientListener::Message(), this, chatMessage);
  171. @@ -756,7 +756,7 @@
  172.             message.from = findUser(fromNick);
  173.         }
  174.  
  175. -       if(PluginManager::getInstance()->onIncomingPM(message.replyTo, message.text))
  176. +       if(PluginManager::getInstance()->runHook(HOOK_CHAT_PM_IN, message.replyTo, message.text))
  177.             return;
  178.  
  179.         fire(ClientListener::Message(), this, message);
  180. @@ -808,7 +808,7 @@
  181.  
  182.  void NmdcHub::hubMessage(const string& aMessage, bool thirdPerson) {
  183.     checkstate();
  184. -   if(!PluginManager::getInstance()->onOutgoingChat(this, aMessage))
  185. +   if(!PluginManager::getInstance()->runHook(HOOK_CHAT_OUT, this, aMessage))
  186.         send(fromUtf8( "<" + getMyNick() + "> " + escape(thirdPerson ? "/me " + aMessage : aMessage) + "|" ) );
  187.  }
  188.  
  189. @@ -949,9 +949,6 @@
  190.  void NmdcHub::privateMessage(const OnlineUser& aUser, const string& aMessage, bool /*thirdPerson*/) {
  191.     checkstate();
  192.  
  193. -   if(PluginManager::getInstance()->onOutgoingPM(aUser, aMessage))
  194. -       return;
  195. -
  196.     privateMessage(aUser.getIdentity().getNick(), aMessage);
  197.     // Emulate a returning message...
  198.     Lock l(cs);
  199. @@ -1011,8 +1008,10 @@
  200.  
  201.  void NmdcHub::on(Line, const string& aLine) noexcept {
  202.     Client::on(Line(), aLine);
  203. -   if(PluginManager::getInstance()->onIncomingHubData(this, validateMessage(aLine, true)))
  204. +
  205. +   if(PluginManager::getInstance()->runHook(HOOK_NETWORK_HUB_IN, this, validateMessage(aLine, true)))
  206.         return;
  207. +
  208.     onLine(aLine);
  209.  }
  210.  
  211. --- OnlineUser.h    Tue Jan 20 00:26:36 1970
  212. +++ OnlineUser.h    Tue Jan 20 00:26:36 1970
  213. @@ -30,6 +30,7 @@
  214.  #include "Util.h"
  215.  #include "User.h"
  216.  #include "UserMatch.h"
  217. +#include "PluginManager.h"
  218.  
  219.  namespace dcpp {
  220.  
  221. @@ -141,7 +142,7 @@
  222.     static FastCriticalSection cs;
  223.  };
  224.  
  225. -class OnlineUser : public FastAlloc<OnlineUser>, private boost::noncopyable {
  226. +class OnlineUser : public FastAlloc<OnlineUser>, private boost::noncopyable, public PluginEntity<UserData> {
  227.  public:
  228.     typedef vector<OnlineUser*> List;
  229.     typedef List::iterator Iter;
  230. @@ -156,6 +157,8 @@
  231.     Identity& getIdentity() { return identity; }
  232.     Client& getClient() { return client; }
  233.     const Client& getClient() const { return client; }
  234. +
  235. +   UserData* getPluginObject() noexcept;
  236.  
  237.     GETSET(Identity, identity, Identity);
  238.  private:
  239. --- PluginApiImpl.cpp   Tue Jan 20 00:26:36 1970
  240. +++ PluginApiImpl.cpp   Tue Jan 20 00:26:36 1970
  241. @@ -1,5 +1,5 @@
  242.  /*
  243. - * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
  244. + * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
  245.   *
  246.   * This program is free software; you can redistribute it and/or modify
  247.   * it under the terms of the GNU General Public License as published by
  248. @@ -19,103 +19,197 @@
  249.  /**
  250.   * The PluginApiImpl class contains implementations of certain callback functions,
  251.   * they are simply separated here.
  252. + *
  253. + * Notes:
  254. + * - Current implementation does not correctly run HOOK_CHAT_PM_OUT for PM's sent as a result of Client::sendUserCmd
  255. + * - dcpp may run HOOK_HUB_OFFLINE for hubs that never ran HOOK_HUB_ONLINE before (if socket creation fails in Client::connect)
  256.   */
  257.  
  258.  #include "stdinc.h"
  259. -#include "DCPlusPlus.h"
  260. +#include "PluginApiImpl.h"
  261. +
  262. +#include "File.h"
  263.  
  264.  #include "PluginManager.h"
  265.  #include "ConnectionManager.h"
  266.  #include "FavoriteManager.h"
  267. +#include "QueueManager.h"
  268. +#include "ClientManager.h"
  269.  
  270. -#include "AdcHub.h"
  271.  #include "UserConnection.h"
  272.  
  273.  namespace dcpp {
  274.  
  275. -Socket PluginApiImpl::apiSocket(Socket::TYPE_UDP);
  276. -
  277. -hookHandle PluginApiImpl::initAPI(DCCore& dcCore) {
  278. -   dcCore.apiVersion = DCAPI_VER;
  279. -
  280. -   // Hook creation
  281. -   dcCore.create_hook = &PluginApiImpl::createHook;
  282. -   dcCore.destroy_hook = &PluginApiImpl::destroyHook;
  283. +#define IMPL_HOOKS_COUNT 19
  284.  
  285. -   // Hook interaction
  286. -   dcCore.set_hook = &PluginApiImpl::setHook;
  287. -   dcCore.call_hook = &PluginApiImpl::callHook;
  288. -   dcCore.un_hook = &PluginApiImpl::unHook;
  289. +static const char* hookGuids[IMPL_HOOKS_COUNT] = {
  290. +   HOOK_CHAT_IN,
  291. +   HOOK_CHAT_OUT,
  292. +   HOOK_CHAT_PM_IN,
  293. +   HOOK_CHAT_PM_OUT,
  294. +
  295. +   HOOK_TIMER_SECOND,
  296. +   HOOK_TIMER_MINUTE,
  297. +
  298. +   HOOK_HUB_ONLINE,
  299. +   HOOK_HUB_OFFLINE,
  300. +
  301. +   HOOK_NETWORK_HUB_IN,
  302. +   HOOK_NETWORK_HUB_OUT,
  303. +   HOOK_NETWORK_CONN_IN,
  304. +   HOOK_NETWORK_CONN_OUT,
  305. +
  306. +   HOOK_QUEUE_ADD,
  307. +   HOOK_QUEUE_MOVE,
  308. +   HOOK_QUEUE_REMOVE,
  309. +   HOOK_QUEUE_FINISHED,
  310. +
  311. +   HOOK_UI_CREATED,
  312. +   HOOK_UI_CHAT_DISPLAY,
  313. +   HOOK_UI_PROCESS_CHAT_CMD       
  314. +};
  315.  
  316. -   // Message regitster
  317. -   dcCore.register_message = &PluginApiImpl::registerMessage;
  318. -   dcCore.register_range = &PluginApiImpl::registerRange;
  319. -   dcCore.seek_message = &PluginApiImpl::seekMessage;
  320. +Socket PluginApiImpl::apiSocket(Socket::TYPE_UDP);
  321.  
  322. -   // Setting management
  323. -   dcCore.set_cfg = &PluginApiImpl::setConfig;
  324. -   dcCore.get_cfg = &PluginApiImpl::getConfig;
  325. +// lambdas are not used because certain compiler is being a pain about it (for now)
  326. +DCHooks PluginApiImpl::dcHooks = {
  327. +   &PluginApiImpl::createHook,
  328. +   &PluginApiImpl::destroyHook,
  329. +
  330. +   &PluginApiImpl::bindHook,
  331. +   &PluginApiImpl::runHook,
  332. +   &PluginApiImpl::releaseHook
  333. +};
  334. +
  335. +DCConfig PluginApiImpl::dcConfig = {
  336. +   &PluginApiImpl::getPath,
  337. +   &PluginApiImpl::setConfig,
  338. +   &PluginApiImpl::getConfig
  339. +};
  340. +
  341. +DCLog PluginApiImpl::dcLog = {
  342. +   &PluginApiImpl::log
  343. +};
  344. +
  345. +DCConnection PluginApiImpl::dcConnection = {
  346. +   &PluginApiImpl::sendUdpData,
  347. +   &PluginApiImpl::sendProtocolCmd,
  348. +   &PluginApiImpl::terminateConnection
  349. +};
  350. +
  351. +DCHub PluginApiImpl::dcHub = {
  352. +   &PluginApiImpl::newClient,
  353. +   &PluginApiImpl::findOnlineHub,
  354. +   &PluginApiImpl::deleteClient,
  355. +
  356. +   &PluginApiImpl::emulateProtocolCmd,
  357. +   &PluginApiImpl::sendProtocolCmd,
  358. +
  359. +   &PluginApiImpl::sendHubMessage,
  360. +   &PluginApiImpl::sendLocalMessage,
  361. +   &PluginApiImpl::sendPrivateMessage
  362. +};
  363. +
  364. +DCQueue PluginApiImpl::dcQueue = {
  365. +   &PluginApiImpl::addDownload,
  366. +   &PluginApiImpl::removeDownload,
  367. +   &PluginApiImpl::setPriority
  368. +};
  369. +
  370. +DCUtils PluginApiImpl::dcUtils = {
  371. +   &PluginApiImpl::toUtf8,
  372. +   &PluginApiImpl::fromUtf8,
  373. +
  374. +   &PluginApiImpl::Utf8toWide,
  375. +   &PluginApiImpl::WidetoUtf8,
  376. +
  377. +   &PluginApiImpl::toBase32,
  378. +   &PluginApiImpl::fromBase32
  379. +};
  380.  
  381. -   dcCore.memalloc = &PluginApiImpl::memalloc;
  382. -   dcCore.strconv = &PluginApiImpl::strconv;
  383. +void PluginApiImpl::initAPI(DCCore& dcCore) {
  384. +   dcCore.apiVersion = DCAPI_VER;
  385.  
  386. -   return PluginManager::getInstance()->createHook(CALLBACK_BASE, HOOK_CALLBACK, &PluginApiImpl::coreCallback);
  387. +   // Interface registry
  388. +   dcCore.register_interface = &PluginApiImpl::registerInterface;
  389. +   dcCore.query_interface = &PluginApiImpl::queryInterface;
  390. +   dcCore.release_interface = &PluginApiImpl::releaseInterface;
  391. +
  392. +   // Interfaces (since these outlast any plugin they don't need to be explictly released)
  393. +   dcCore.register_interface(INTERFACE_HOOKS, &dcHooks);
  394. +   dcCore.register_interface(INTERFACE_CONFIG, &dcConfig);
  395. +   dcCore.register_interface(INTERFACE_LOGGING, &dcLog);
  396. +
  397. +   dcCore.register_interface(INTERFACE_DCPP_CONNECTIONS, &dcConnection);
  398. +   dcCore.register_interface(INTERFACE_DCPP_HUBS, &dcHub);
  399. +   dcCore.register_interface(INTERFACE_DCPP_QUEUE, &dcQueue);
  400. +   dcCore.register_interface(INTERFACE_DCPP_UTILS, &dcUtils);
  401. +
  402. +   // Create provided hooks (since these outlast any plugin they don't need to be explictly released)
  403. +   for(int i = 0; i < IMPL_HOOKS_COUNT; ++i)
  404. +       dcHooks.create_hook(hookGuids[i], NULL);
  405.  }
  406.  
  407. -void PluginApiImpl::releaseAPI(hookHandle hHook) {
  408. -   PluginManager::getInstance()->destroyHook(hHook);
  409. +void PluginApiImpl::releaseAPI() {
  410.     apiSocket.disconnect();
  411.  }
  412.  
  413.  // Functions for DCCore
  414. -hookHandle PluginApiImpl::createHook(HookID hookId, HookType hookType, DCHOOK defProc) {
  415. -   return PluginManager::getInstance()->createHook(hookId, hookType, defProc);
  416. +intfHandle PluginApiImpl::registerInterface(const char* guid, dcptr_t funcs) {
  417. +   return PluginManager::getInstance()->registerInterface(guid, funcs);
  418.  }
  419.  
  420. -void PluginApiImpl::destroyHook(hookHandle hHook) {
  421. -   PluginManager::getInstance()->destroyHook(hHook);
  422. -   hHook = NULL;
  423. +dcptr_t PluginApiImpl::queryInterface(const char* guid) {
  424. +   return PluginManager::getInstance()->queryInterface(guid);
  425. +}
  426. +
  427. +Bool PluginApiImpl::releaseInterface(intfHandle hInterface) {
  428. +   return PluginManager::getInstance()->releaseInterface(hInterface) ? True : False;
  429.  }
  430.  
  431. -subsHandle PluginApiImpl::setHook(HookID hookId, DCHOOK hookProc, void* pCommon) {
  432. -   return PluginManager::getInstance()->setHook(hookId, hookProc, pCommon);
  433. +// Functions for DCHook
  434. +hookHandle PluginApiImpl::createHook(const char* guid, DCHOOK defProc) {
  435. +   return PluginManager::getInstance()->createHook(guid, defProc);
  436.  }
  437.  
  438. -Bool PluginApiImpl::callHook(HookID hookId, uint32_t eventId, dcptr_t pData) {
  439. -   return PluginManager::getInstance()->callHook(hookId, eventId, pData) ? True : False;
  440. +Bool PluginApiImpl::destroyHook(hookHandle hHook) {
  441. +   Bool bRes = PluginManager::getInstance()->destroyHook(reinterpret_cast<PluginHook*>(hHook)) ? True : False;
  442. +   hHook = NULL;
  443. +   return bRes;
  444.  }
  445.  
  446. -size_t PluginApiImpl::unHook(subsHandle hHook) {
  447. -   return PluginManager::getInstance()->unHook(hHook);
  448. +subsHandle PluginApiImpl::bindHook(const char* guid, DCHOOK hookProc, void* pCommon) {
  449. +   return PluginManager::getInstance()->bindHook(guid, hookProc, pCommon);
  450.  }
  451.  
  452. -uint32_t PluginApiImpl::registerMessage(HookType type, const char* name) {
  453. -   return PluginManager::getInstance()->registerMessage(type, name);
  454. +Bool PluginApiImpl::runHook(const char* guid, dcptr_t pObject, dcptr_t pData) {
  455. +   return PluginManager::getInstance()->runHook(guid, pObject, pData) ? True : False;
  456.  }
  457.  
  458. -uint32_t PluginApiImpl::registerRange(HookType type, const char* name, uint32_t count) {
  459. -   return PluginManager::getInstance()->registerRange(type, name, count);
  460. +size_t PluginApiImpl::releaseHook(subsHandle hHook) {
  461. +   return PluginManager::getInstance()->releaseHook(reinterpret_cast<HookSubscriber*>(hHook));
  462.  }
  463.  
  464. -uint32_t PluginApiImpl::seekMessage(const char* name) {
  465. -   return PluginManager::getInstance()->seekMessage(name);
  466. +// Functions for DCConfig
  467. +const char* DCAPI PluginApiImpl::getPath(PathType type) {
  468. +   return Util::getPath(static_cast<Util::Paths>(type)).c_str();
  469.  }
  470.  
  471.  void PluginApiImpl::setConfig(const char* guid, const char* setting, ConfigValuePtr val) {
  472.     PluginManager* pm = PluginManager::getInstance();
  473.     switch(val->type) {
  474.         case CFG_TYPE_REMOVE:
  475. -           pm->removeSetting(guid, setting);
  476. +           pm->removePluginSetting(guid, setting);
  477.             break;
  478.         case CFG_TYPE_STRING:
  479.             if(val->value.str)
  480. -               pm->setSetting(guid, setting, val->value.str);
  481. +               pm->setPluginSetting(guid, setting, val->value.str);
  482.             break;
  483.         case CFG_TYPE_INT:
  484. -           pm->setSetting(guid, setting, Util::toString(val->value.int32));
  485. +           pm->setPluginSetting(guid, setting, Util::toString(val->value.int32));
  486.             break;
  487.         case CFG_TYPE_INT64:
  488. -           pm->setSetting(guid, setting, Util::toString(val->value.int64));
  489. +           pm->setPluginSetting(guid, setting, Util::toString(val->value.int64));
  490.             break;
  491.         default:
  492.             dcassert(0);
  493. @@ -149,13 +243,13 @@
  494.     PluginManager* pm = PluginManager::getInstance();
  495.     switch(val->type) {
  496.         case CFG_TYPE_STRING:
  497. -           val->value.str = pm->getSetting(guid, setting).c_str();
  498. +           val->value.str = pm->getPluginSetting(guid, setting).c_str();
  499.             break;
  500.         case CFG_TYPE_INT:
  501. -           val->value.int32 = Util::toInt(pm->getSetting(guid, setting));
  502. +           val->value.int32 = Util::toInt(pm->getPluginSetting(guid, setting));
  503.             break;
  504.         case CFG_TYPE_INT64:
  505. -           val->value.int64 = Util::toInt64(pm->getSetting(guid, setting));
  506. +           val->value.int64 = Util::toInt64(pm->getPluginSetting(guid, setting));
  507.             break;
  508.         default:
  509.             dcassert(0);
  510. @@ -163,242 +257,172 @@
  511.     return True;
  512.  }
  513.  
  514. -void* PluginApiImpl::memalloc(void* ptr, size_t bytes) {
  515. -   if(ptr != NULL && bytes > 0) {
  516. -       return realloc(ptr, bytes);
  517. -   } else if(ptr != NULL) {
  518. -       free(ptr);
  519. -   } else if(bytes > 0) {
  520. -       return malloc(bytes);
  521. -   }
  522. -   return NULL;
  523. +// Functions for DCLog
  524. +void PluginApiImpl::log(const char* msg) {
  525. +   LogManager::getInstance()->message(msg);
  526.  }
  527.  
  528. -size_t PluginApiImpl::strconv(ConversionType type, void* dst, void* src, size_t len) {
  529. -   switch(type) {
  530. -       case CONV_TO_UTF8: {
  531. -           string sSrc(Text::toUtf8(reinterpret_cast<char*>(src)));
  532. -           char* cDst = static_cast<char*>(dst);
  533. -           len = (sSrc.size() < len) ? sSrc.size() : len;
  534. -           strncpy(cDst, sSrc.c_str(), len);
  535. -           return len;
  536. -       }
  537. -       case CONV_FROM_UTF8: {
  538. -           string sSrc(Text::fromUtf8(reinterpret_cast<char*>(src)));
  539. -           char* cDst = static_cast<char*>(dst);
  540. -           len = (sSrc.size() < len) ? sSrc.size() : len;
  541. -           strncpy(cDst, sSrc.c_str(), len);
  542. -           return len;
  543. -       }
  544. -       case CONV_UTF8_TO_WIDE: {
  545. -           wstring sSrc(Text::utf8ToWide(reinterpret_cast<char*>(src)));
  546. -           wchar_t* cDst = static_cast<wchar_t*>(dst);
  547. -           len = (sSrc.size() < len) ? sSrc.size() : len;
  548. -           wcsncpy(cDst, sSrc.c_str(), len);
  549. -           return len;
  550. -       }
  551. -       case CONV_WIDE_TO_UTF8: {
  552. -           string sSrc(Text::wideToUtf8(reinterpret_cast<wchar_t*>(src)));
  553. -           char* cDst = static_cast<char*>(dst);
  554. -           len = (sSrc.size() < len) ? sSrc.size() : len;
  555. -           strncpy(cDst, sSrc.c_str(), len);
  556. -           return len;
  557. -       }
  558. -       case CONV_TO_BASE32: {
  559. -           string sSrc(Encoder::toBase32(reinterpret_cast<uint8_t*>(src), len));
  560. -           char* cDst = static_cast<char*>(dst);
  561. -           len = (sSrc.size() < len) ? sSrc.size() : len;
  562. -           strncpy(cDst, sSrc.c_str(), len);
  563. -           return len;
  564. -       }
  565. -       case CONV_FROM_BASE32:
  566. -           Encoder::fromBase32(reinterpret_cast<char*>(src), reinterpret_cast<uint8_t*>(dst), len);
  567. -           return 0;
  568. -       default:
  569. -           // No value is better than the other
  570. -           return string::npos;
  571. -   }
  572. +// Functions for DCConnection
  573. +void PluginApiImpl::sendProtocolCmd(ConnectionDataPtr conn, const char* cmd) {
  574. +   reinterpret_cast<UserConnection*>(conn->object)->sendRaw(cmd);
  575.  }
  576.  
  577. -// Default callback for hook CALLBACK_BASE
  578. -Bool PluginApiImpl::coreCallback(uint32_t eventId, dcptr_t pData) {
  579. -   switch(eventId) {
  580. -       case DBG_MESSAGE:
  581. -       case LOG_MESSAGE:
  582. -           LogManager::getInstance()->message(reinterpret_cast<const char*>(pData));
  583. -           break;
  584. -       case GET_PATHS: {
  585. -           TextDataCondPtr args = reinterpret_cast<TextDataCondPtr>(pData);
  586. -           args->res = const_cast<char*>(Util::getPath(static_cast<Util::Paths>(args->cond)).c_str());
  587. -           break;
  588. -       }
  589. -       case PROTOCOL_SEND_UDP: {
  590. -           TextDataCondPtr args = reinterpret_cast<TextDataCondPtr>(pData);
  591. -           try { apiSocket.writeTo(args->data, Util::toString(args->cond), args->res); }
  592. -           catch(const Exception& e) { dcdebug("CoreCallback, PROTOCOL_SEND_UDP: %s\n", e.getError().c_str()); }
  593. -           break;
  594. -       }
  595. -       case PROTOCOL_HUB_EMULATE_CMD: {
  596. -           TextArgsResPtr args = reinterpret_cast<TextArgsResPtr>(pData);
  597. -           if(args->object) reinterpret_cast<Client*>(args->object)->emulateCommand(args->data);
  598. -           break;
  599. -       }
  600. -       case PROTOCOL_HUB_SEND_CMD: {
  601. -           TextArgsResPtr args = reinterpret_cast<TextArgsResPtr>(pData);
  602. -           if(args->object) reinterpret_cast<Client*>(args->object)->send(args->data);
  603. -           break;
  604. -       }
  605. -       case PROTOCOL_CONN_SEND_CMD: {
  606. -           TextArgsResPtr args = reinterpret_cast<TextArgsResPtr>(pData);
  607. -           if(args->object) reinterpret_cast<UserConnection*>(args->object)->sendRaw(args->data);
  608. -           break;
  609. -       }
  610. -       case PROTOCOL_CONN_TERMINATE: {
  611. -           TextArgsCondPtr args = reinterpret_cast<TextArgsCondPtr>(pData);
  612. -           if(args->object) reinterpret_cast<UserConnection*>(args->object)->disconnect(args->cond != False);
  613. -           break;
  614. -       }
  615. -       case HUBS_CREATE_HUB: {
  616. -           TextArgsResPtr args = reinterpret_cast<TextArgsResPtr>(pData);
  617. -           return newClient(args->data, reinterpret_cast<ClientDataPtr>(args->res));
  618. -       }
  619. -       case HUBS_DESTROY_HUB:
  620. -           if(pData) ClientManager::getInstance()->putClient(reinterpret_cast<Client*>(pData));
  621. -           break;
  622. -       case HUBS_FIND_HUB: {
  623. -           TextArgsResPtr args = reinterpret_cast<TextArgsResPtr>(pData);
  624. -           return findOnlineHub(args->data, reinterpret_cast<ClientDataPtr>(args->res));
  625. -       }
  626. -       case HUBS_SEND_CHAT: {
  627. -           TextArgsCondPtr args = reinterpret_cast<TextArgsCondPtr>(pData);
  628. -           sendHubMessage(reinterpret_cast<Client*>(args->object), args->data, args->cond != False);
  629. -           break;
  630. -       }
  631. -       case HUBS_SEND_PM: {
  632. -           TextArgsCondPtr args = reinterpret_cast<TextArgsCondPtr>(pData);
  633. -           sendPrivateMessage(reinterpret_cast<OnlineUser*>(args->object), args->data, args->cond != False);
  634. -           break;
  635. -       }
  636. -       case HUBS_SEND_LOCAL: {
  637. -           TextArgsCondPtr args = reinterpret_cast<TextArgsCondPtr>(pData);
  638. -           Client* client = reinterpret_cast<Client*>(args->object);
  639. -           if(client) client->fire(ClientListener::ClientLine(), client, args->data, args->cond);
  640. -           break;
  641. -       }
  642. -       case QUEUE_ADD_DL: {
  643. -           QueueArgsPtr args = reinterpret_cast<QueueArgsPtr>(pData);
  644. -           return addDownload(args->target, args->size, args->hash, args->res);
  645. -       }
  646. -       case QUEUE_REMOVE_DL:
  647. -           QueueManager::getInstance()->remove(reinterpret_cast<const char*>(pData));
  648. -           break;
  649. -       case QUEUE_SET_PRIORITY: {
  650. -           TextArgsCondPtr args = reinterpret_cast<TextArgsCondPtr>(pData);
  651. -           if(args->object) reinterpret_cast<QueueItem*>(args->object)->setPriority(static_cast<QueueItem::Priority>(args->cond));
  652. -           break;
  653. -       }
  654. -       default:
  655. -           return False;
  656. -   }
  657. -   return True;
  658. +void PluginApiImpl::terminateConnection(ConnectionDataPtr conn, Bool graceless) {
  659. +   reinterpret_cast<UserConnection*>(conn->object)->disconnect(graceless != False);
  660. +}
  661. +
  662. +void PluginApiImpl::sendUdpData(const char* ip, uint32_t port, dcptr_t data, size_t n) {
  663. +   apiSocket.writeTo(ip, Util::toString(port), data, n);
  664. +}
  665. +
  666. +// Functions for DCUtils
  667. +size_t PluginApiImpl::toUtf8(char* dst, const char* src, size_t n) {
  668. +   string sSrc(Text::toUtf8(src));
  669. +   n = (sSrc.size() < n) ? sSrc.size() : n;
  670. +   strncpy(dst, sSrc.c_str(), n);
  671. +   return n;
  672. +}
  673. +
  674. +size_t PluginApiImpl::fromUtf8(char* dst, const char* src, size_t n) {
  675. +   string sSrc(Text::fromUtf8(src));
  676. +   n = (sSrc.size() < n) ? sSrc.size() : n;
  677. +   strncpy(dst, sSrc.c_str(), n);
  678. +   return n;
  679. +}
  680. +
  681. +size_t PluginApiImpl::Utf8toWide(wchar_t* dst, const char* src, size_t n) {
  682. +   wstring sSrc(Text::utf8ToWide(src));
  683. +   n = (sSrc.size() < n) ? sSrc.size() : n;
  684. +   wcsncpy(dst, sSrc.c_str(), n);
  685. +   return n;
  686. +}
  687. +
  688. +size_t PluginApiImpl::WidetoUtf8(char* dst, const wchar_t* src, size_t n) {
  689. +   string sSrc(Text::wideToUtf8(src));
  690. +   n = (sSrc.size() < n) ? sSrc.size() : n;
  691. +   strncpy(dst, sSrc.c_str(), n);
  692. +   return n;
  693. +}
  694. +
  695. +size_t PluginApiImpl::toBase32(char* dst, const uint8_t* src, size_t n) {
  696. +   string sSrc(Encoder::toBase32(src, n));
  697. +   n = (sSrc.size() < n) ? sSrc.size() : n;
  698. +   strncpy(dst, sSrc.c_str(), n);
  699. +   return n;
  700. +}
  701. +
  702. +size_t PluginApiImpl::fromBase32(uint8_t* dst, const char* src, size_t n) {
  703. +   Encoder::fromBase32(src, dst, n);
  704. +   return n;
  705.  }
  706.  
  707. -// Queue functions
  708. -Bool PluginApiImpl::addDownload(const string& fname, int64_t fsize, const string& fhash, QueueDataPtr data) {
  709. -   Bool bRes = False;
  710. +// Functions for DCQueue
  711. +QueueDataPtr PluginApiImpl::addDownload(const char* hash, uint64_t size, const char* target) {
  712.  
  713. +   QueueData* data = NULL;
  714.     try {
  715. -       string target = File::isAbsolute(fname) ? fname : SETTING(DOWNLOAD_DIRECTORY) + fname;
  716. -       QueueManager::getInstance()->add(target, fsize, TTHValue(fhash), HintedUser(UserPtr(), Util::emptyString));
  717. +       string sTarget = File::isAbsolute(target) ? target : SETTING(DOWNLOAD_DIRECTORY) + target;
  718. +       QueueManager::getInstance()->add(sTarget, size, TTHValue(hash), HintedUser(UserPtr(), Util::emptyString));
  719.  
  720. -       QueueManager::getInstance()->lockedOperation([data, &target, &bRes](const QueueItem::StringMap& lst) {
  721. -           QueueItem::StringMap::const_iterator i;
  722. -           if ((i = lst.find(&target)) != lst.end()) {
  723. -               QueueItem* qi = i->second;
  724. -               data->file = qi->getTargetFileName().c_str();
  725. -               data->target = qi->getTarget().c_str();
  726. -               data->location = qi->getTempTarget().c_str();
  727. -               data->hash = qi->getTTH().data;
  728. -               data->object = qi;
  729. -               data->size = qi->getSize();
  730. -               data->isFileList = qi->isSet(QueueItem::FLAG_USER_LIST) ? True : False;
  731. -               bRes = True;
  732. +       QueueManager::getInstance()->lockedOperation([&data, &sTarget](const QueueItem::StringMap& lst) {
  733. +           auto i = lst.find(&sTarget);
  734. +           if (i != lst.end()) {
  735. +               data = i->second->getPluginObject();
  736.             }
  737.         });
  738.     } catch(const Exception& e) {
  739.         LogManager::getInstance()->message(e.getError());
  740.     }
  741.  
  742. -   return bRes;
  743. +   return data;
  744.  }
  745.  
  746. -// Hub functions
  747. -Bool PluginApiImpl::findOnlineHub(string hubUrl, ClientDataPtr data) {
  748. -   auto& clients = ClientManager::getInstance()->getClients();
  749. -
  750. -   for(auto i = clients.begin(); i != clients.end(); ++i) {
  751. -       if(((*i)->getHubUrl() == hubUrl) && (*i)->isConnected()) {
  752. -           Client* client = *i;
  753. -           data->url = client->getHubUrl().c_str();
  754. -           data->ip = client->getIp().c_str();
  755. -           data->object = client;
  756. -           Util::toString(data->port) = client->getPort();
  757. -           data->protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
  758. -           data->isOp = client->isOp() ? True : False;
  759. -           data->isSecure = client->isSecure() ? True : False;
  760. -           return True;
  761. -       }
  762. +void PluginApiImpl::removeDownload(const char* target) {
  763. +   QueueManager::getInstance()->remove(target);
  764. +}
  765. +
  766. +void PluginApiImpl::setPriority(QueueDataPtr qi, QueuePrio priority) {
  767. +   reinterpret_cast<QueueItem*>(qi->object)->setPriority(static_cast<QueueItem::Priority>(priority));
  768. +}
  769. +
  770. +// Functions for DCHub
  771. +HubDataPtr PluginApiImpl::findOnlineHub(const char* url) {
  772. +   ClientManager::getInstance()->lock();
  773. +   const auto& list = ClientManager::getInstance()->getClients();
  774. +
  775. +   for(auto i = list.begin(); i != list.end(); ++i) {
  776. +       if(((*i)->getHubUrl() == url) && (*i)->isConnected())
  777. +            return (*i)->getPluginObject();
  778.     }
  779.  
  780. -   return False;
  781. +   return NULL;
  782.  }
  783.  
  784. -Bool PluginApiImpl::newClient(const string& hubUrl, ClientDataPtr data) {
  785. -   if(!SETTING(NICK).empty()) {
  786. -       // Note, it is no use specifying any other info here...
  787. -       Client* client = ClientManager::getInstance()->getClient(hubUrl);
  788. -       client->setPassword(Util::emptyString);
  789. +HubDataPtr PluginApiImpl::newClient(const char* url, const char* nick, const char* password) {
  790. +   HubData* data = findOnlineHub(url);
  791. +
  792. +   if(data == NULL && !SETTING(NICK).empty()) {
  793. +       Client* client = ClientManager::getInstance()->getClient(url);
  794.         client->connect();
  795. +       client->setPassword(password);
  796. +       client->setCurrentNick(nick);
  797.  
  798. -       data->url = client->getHubUrl().c_str();
  799. -       data->ip = client->getIp().c_str();
  800. -       data->object = client;
  801. -       Util::toString(data->port) = client->getPort();
  802. -       data->protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
  803. -       data->isOp = False;
  804. -       data->isSecure = client->isSecure() ? True : False;
  805. -       return True;
  806. +       // check that socket is waitting for connection...
  807. +       if(client->isConnected()) {
  808. +           return client->getPluginObject();
  809. +       }
  810.     }
  811.  
  812. -   return False;
  813. +   return data;
  814.  }
  815.  
  816. -void PluginApiImpl::sendHubMessage(Client* client, const string& message, bool thirdPerson) {
  817. -   if(client) {
  818. +void PluginApiImpl::sendHubMessage(HubDataPtr hub, const char* message, Bool thirdPerson) {
  819. +   if(hub && hub->object) {
  820. +       Client* client = reinterpret_cast<Client*>(hub->object);
  821. +
  822.         // Lets make plugins life easier...
  823.         ParamMap params;
  824.         client->getMyIdentity().getParams(params, "my", true);
  825.         client->getHubIdentity().getParams(params, "hub", false);
  826.  
  827. -       client->hubMessage(Util::formatParams(message, params, false), thirdPerson);
  828. +       client->hubMessage(Util::formatParams(message, params), thirdPerson != False);
  829.     }
  830.  }
  831.  
  832. -void PluginApiImpl::sendPrivateMessage(OnlineUserPtr ou, const string& message, bool thirdPerson) {
  833. -   if(ou) {
  834. +void PluginApiImpl::sendPrivateMessage(UserDataPtr user, const char* message, Bool thirdPerson) {
  835. +   if(user && user->object) {
  836. +       OnlineUserPtr ou = reinterpret_cast<OnlineUser*>(user->object);
  837. +
  838.         // Lets make plugins life easier...
  839.         ParamMap params;
  840.         ou->getIdentity().getParams(params, "user", true);
  841.         ou->getClient().getMyIdentity().getParams(params, "my", true);
  842.         ou->getClient().getHubIdentity().getParams(params, "hub", false);
  843.  
  844. -       ou->getClient().privateMessage(*ou, Util::formatParams(message, params, false), thirdPerson);
  845. +       ClientManager::getInstance()->privateMessage(HintedUser(ou->getUser(), user->hubHint), Util::formatParams(message, params), thirdPerson != False);
  846.     }
  847.  }
  848.  
  849. +void PluginApiImpl::deleteClient(HubDataPtr hub) {
  850. +   ClientManager::getInstance()->putClient(reinterpret_cast<Client*>(hub->object));
  851. +}
  852. +
  853. +void PluginApiImpl::emulateProtocolCmd(HubDataPtr hub, const char* cmd) {
  854. +   reinterpret_cast<Client*>(hub->object)->emulateCommand(cmd);
  855. +}
  856. +
  857. +void PluginApiImpl::sendProtocolCmd(HubDataPtr hub, const char* cmd) {
  858. +   reinterpret_cast<Client*>(hub->object)->send(cmd);
  859. +}
  860. +
  861. +void PluginApiImpl::sendLocalMessage(HubDataPtr hub, const char* msg, MsgType type) {
  862. +   Client* client = reinterpret_cast<Client*>(hub->object);
  863. +   client->fire(ClientListener::ClientLine(), client, msg, type);
  864. +}
  865. +
  866.  } // namespace dcpp
  867.  
  868.  /**
  869.   * @file
  870. - * $Id: PluginApiImpl.cpp 722 2010-10-09 11:51:36Z crise $
  871. + * $Id: PluginApiImpl.cpp 1217 2012-01-08 16:15:57Z crise $
  872.   */
  873. --- PluginApiImpl.h Tue Jan 20 00:26:36 1970
  874. +++ PluginApiImpl.h Tue Jan 20 00:26:36 1970
  875. @@ -1,5 +1,5 @@
  876.  /*
  877. - * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
  878. + * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
  879.   *
  880.   * This program is free software; you can redistribute it and/or modify
  881.   * it under the terms of the GNU General Public License as published by
  882. @@ -24,44 +24,80 @@
  883.  #ifndef DCPLUSPLUS_DCPP_PLUGIN_API_IMPL_H
  884.  #define DCPLUSPLUS_DCPP_PLUGIN_API_IMPL_H
  885.  
  886. +#include <cstdint>
  887. +
  888. +#include "typedefs.h"
  889. +#include "PluginDefs.h"
  890. +
  891.  namespace dcpp {
  892.  
  893.  class PluginApiImpl
  894.  {
  895.  public:
  896. -   static hookHandle initAPI(DCCore& dcCore);
  897. -   static void releaseAPI(hookHandle hHook);
  898. +   static void initAPI(DCCore& dcCore);
  899. +   static void releaseAPI();
  900.  
  901.  private:
  902.     // Functions for DCCore
  903. -   static hookHandle DCAPI createHook(HookID hookId, HookType hookType, DCHOOK defProc);
  904. -   static void DCAPI destroyHook(hookHandle hHook);
  905. -
  906. -   static subsHandle DCAPI setHook(HookID hookId, DCHOOK hookProc, void* pCommon);
  907. -   static Bool DCAPI callHook(HookID hookId, uint32_t eventId, dcptr_t pData);
  908. -   static size_t DCAPI unHook(subsHandle hHook);
  909. -
  910. -   static uint32_t DCAPI registerMessage(HookType type, const char* name);
  911. -   static uint32_t DCAPI registerRange(HookType type, const char* name, uint32_t count);
  912. -   static uint32_t DCAPI seekMessage(const char* name);
  913. +   static intfHandle DCAPI registerInterface(const char* guid, dcptr_t funcs);
  914. +   static dcptr_t DCAPI queryInterface(const char* guid);
  915. +   static Bool DCAPI releaseInterface(intfHandle hInterface);
  916. +
  917. +   // Functions for DCHooks
  918. +   static hookHandle DCAPI createHook(const char* guid, DCHOOK defProc);
  919. +   static Bool DCAPI destroyHook(hookHandle hHook);
  920. +
  921. +   static subsHandle DCAPI bindHook(const char* guid, DCHOOK hookProc, void* pCommon);
  922. +   static Bool DCAPI runHook(const char* guid, dcptr_t pObject, dcptr_t pData);
  923. +   static size_t DCAPI releaseHook(subsHandle hHook);
  924.  
  925. +   // Functions For DCConfig
  926. +   static const char* DCAPI getPath(PathType type);
  927.     static void DCAPI setConfig(const char* guid, const char* setting, ConfigValuePtr val);
  928.     static Bool DCAPI getConfig(const char* guid, const char* setting, ConfigValuePtr val);
  929.  
  930. -   static void* DCAPI memalloc(void* ptr, size_t bytes);
  931. -   static size_t DCAPI strconv(ConversionType type, void* dst, void* src, size_t len);
  932. -
  933. -   // Default callback for hook CALLBACK_BASE
  934. -   static Bool DCAPI coreCallback(uint32_t eventId, dcptr_t pData);
  935. -
  936. -   // Queue functions
  937. -   static Bool addDownload(const string& fname, int64_t fsize, const string& fhash, QueueDataPtr data);
  938. +   // Functions for DCLog
  939. +   static void DCAPI log(const char* msg);
  940.  
  941. -   // Hub functions
  942. -   static Bool findOnlineHub(string hubUrl, ClientDataPtr data);
  943. -   static Bool newClient(const string& hubUrl, ClientDataPtr data);
  944. -   static void sendHubMessage(Client* client, const string& message, bool thirdPerson);
  945. -   static void sendPrivateMessage(OnlineUserPtr ou, const string& message, bool thirdPerson);
  946. +   // Functions for DCConnection
  947. +   static void DCAPI sendProtocolCmd(ConnectionDataPtr conn, const char* cmd);
  948. +   static void DCAPI terminateConnection(ConnectionDataPtr conn, Bool graceless);
  949. +   static void DCAPI sendUdpData(const char* ip, uint32_t port, dcptr_t data, size_t n);
  950. +
  951. +   // Functions for DCUtils
  952. +   static size_t DCAPI toUtf8(char* dst, const char* src, size_t n);
  953. +   static size_t DCAPI fromUtf8(char* dst, const char* src, size_t n);
  954. +
  955. +   static size_t DCAPI Utf8toWide(wchar_t* dst, const char* src, size_t n);
  956. +   static size_t DCAPI WidetoUtf8(char* dst, const wchar_t* src, size_t n);
  957. +
  958. +   static size_t DCAPI toBase32(char* dst, const uint8_t* src, size_t n);
  959. +   static size_t DCAPI fromBase32(uint8_t* dst, const char* src, size_t n);
  960. +
  961. +   // Functions for DCQueue
  962. +   static QueueDataPtr DCAPI addDownload(const char* hash, uint64_t size, const char* target);
  963. +   static void DCAPI removeDownload(const char* target);
  964. +   static void DCAPI setPriority(QueueDataPtr qi, QueuePrio priority);
  965. +
  966. +   // Functions for DCHub
  967. +   static HubDataPtr DCAPI findOnlineHub(const char* url);
  968. +   static HubDataPtr DCAPI newClient(const char* url, const char* nick, const char* password);
  969. +   static void DCAPI sendHubMessage(HubDataPtr hub, const char* message, Bool thirdPerson);
  970. +   static void DCAPI sendPrivateMessage(UserDataPtr user, const char* message, Bool thirdPerson);
  971. +
  972. +   static void DCAPI deleteClient(HubDataPtr hub);
  973. +   static void DCAPI emulateProtocolCmd(HubDataPtr hub, const char* cmd);
  974. +   static void DCAPI sendProtocolCmd(HubDataPtr hub, const char* cmd);
  975. +   static void DCAPI sendLocalMessage(HubDataPtr hub, const char* msg, MsgType type);
  976. +
  977. +   static DCHooks dcHooks;
  978. +   static DCConfig dcConfig;
  979. +   static DCLog dcLog;
  980. +
  981. +   static DCConnection dcConnection;
  982. +   static DCHub dcHub;
  983. +   static DCQueue dcQueue;
  984. +   static DCUtils dcUtils;
  985.  
  986.     static Socket apiSocket;
  987.  };
  988. @@ -72,5 +108,5 @@
  989.  
  990.  /**
  991.   * @file
  992. - * $Id: PluginApiImpl.h 707 2010-09-03 15:40:16Z crise $
  993. + * $Id: PluginApiImpl.h 1217 2012-01-08 16:15:57Z crise $
  994.   */
  995. --- PluginDefs.h    Tue Jan 20 00:26:36 1970
  996. +++ PluginDefs.h    Tue Jan 20 00:26:36 1970
  997. @@ -1,5 +1,5 @@
  998.  /*
  999. - * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
  1000. + * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
  1001.   *
  1002.   * This program is free software; you can redistribute it and/or modify
  1003.   * it under the terms of the GNU General Public License as published by
  1004. @@ -16,71 +16,6 @@
  1005.   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  1006.   */
  1007.  
  1008. -/**
  1009. - *                     API Stuff (just to put some things down)
  1010. - *
  1011. - * API Terms:
  1012. - * 1. Node: User of the plugin API (both plugins and the host itself).
  1013. - * 2. Hook: Generic term for message based channel between two nodes. Hook can be either inbound
  1014. - *          (called) our outboud (listened). Inbound hooks are referred as callbacks but their
  1015. - *          mechanics are mostly identical.
  1016. - *             - Main hook: a special hook which notifies plugins about changes in the API and
  1017. - *               its state (separate of the hooks system).
  1018. - *             - Default hook procedure: called after subscribers have been processed, if available.
  1019. - *
  1020. - * Host node implementation:
  1021. - * 1§ Host is expected to implement all functions pointed directly by DCCore struct, with the
  1022. - *    notable exception of "strconv" which should be implemented to be platform, useage and
  1023. - *    environment relevant.
  1024. - *
  1025. - * 2§ set_hook and un_hook implementations must automatically create (if missing) and free hooks from
  1026. - *    HookID range [1, HOOK_USER] respectively. The type of any automatically created hooks should be
  1027. - *    HOOK_EVENT.
  1028. - *
  1029. - * 3§ Host node must create the callback CALLBACK_BASE, which is the only guaranteed callback between
  1030. - *    host node and (all of) the plugin nodes (this callback should be a hook of type HOOK_CALLBACK).
  1031. - *
  1032. - * 4§ Host is expected to implement at least one of the "common" outbound hooks, rest are optional.
  1033. - *
  1034. - * 5§ Hooks the host node chooses implement are expected to be complete or complemented, to a satisfactory
  1035. - *    degree, by plugin for the host.
  1036. - *
  1037. - * 6§ Host is required to implement only the callback events relevant to the implemented outbound hooks.
  1038. - *    Alternatively a plugin may complement (complete) the hosts supply of these by the means of
  1039. - *    callback overloading.
  1040. - *
  1041. - * 7§ Any completely platform specific callbacks or hooks are considered completely optional and
  1042. - *    plugins can be expected to handle this accordingly.
  1043. - *
  1044. - * Plugin node implementation:
  1045. - * 1§ Plugin is required to export function pluginInit which must return pointer to a hook procedure
  1046. - *    that can handle main hook events (basic DCHOOK). Unless plugin explictly sets the common data
  1047. - *    when subscribing to a hook or a callback all hook procedures are of the simple variant.
  1048. - *
  1049. - * 2§ Most hooks are simple blocking type, however, even an event blocked by one node will get sent
  1050. - *    to any remaining nodes (sending process is linear, based on subscription order) though they can't
  1051. - *    unblock the event.
  1052. - *
  1053. - * 3§ Callback hooks are overloadable and differ slightly from above. They suppport both terminating the
  1054. - *    sending of the current event to remaining nodes as well as changing the blocking state on the fly.
  1055. - *    This allows callbacks to be overloaded by plugins. Example: host node uses default hook procedure
  1056. - *    to provide callbacks. Plugin subscribes to the hook and catches the event it needs then terminates
  1057. - *    so the default hook procedure won't get processed (callbacks can be implemented by all nodes, see below).
  1058. - *
  1059. - * 4§ Plugins can also intercommunicate and depend on each other because everyone can create and call hooks freely
  1060. - *    this also allows plugins to complement the hosts implementations of the API (as noted under Host node
  1061. - *    implementation). However, plugin intercom is something largely independant of the host and the API itself.
  1062. - *    To put it simply plugins have to "know each other", the API only allows for basic checking of dependencies
  1063. - *    based on plugin GUIDs.
  1064. - *
  1065. - * Misc implementation
  1066. - * §1 Implementations that add additional messages or types to any of the groups of constants must always aim to
  1067. - *    preserve the existing constants and their values so that backwards compatibility is maintained.
  1068. - *
  1069. - * §2 Any constants should not exceed the absolute minium size requirements for an integer (ie. 16bit, [-32767, 32767])
  1070. - *    even though on most architectures today integer can be larger.
  1071. - */
  1072. -
  1073.  #ifndef DCPLUSPLUS_DCPP_PLUGIN_DEFS_H
  1074.  #define DCPLUSPLUS_DCPP_PLUGIN_DEFS_H
  1075.  
  1076. @@ -89,10 +24,10 @@
  1077.  #endif
  1078.  
  1079.  /* Version of the plugin api (must change every time the API has changed) */
  1080. -#define DCAPI_VER              0.50
  1081. +#define DCAPI_VER              0.56
  1082.  
  1083.  /* The earliest version of the API that this version is backwards compatible with */
  1084. -#define DCAPI_COMPATIBLE_VER   0.50
  1085. +#define DCAPI_COMPATIBLE_VER   0.56
  1086.  
  1087.  #ifdef _WIN32
  1088.  # define DCAPI __stdcall
  1089. @@ -103,14 +38,17 @@
  1090.  #  define DCIMP __declspec(dllimport)
  1091.  # endif
  1092.  #else
  1093. -# define DCAPI STDCALL
  1094. +# ifdef STDCALL
  1095. +#  define DCAPI STDCALL
  1096. +# else
  1097. +#  define DCAPI
  1098. +# endif
  1099.  # define DCEXP __attribute__ ((visibility("default")))
  1100.  # define DCIMP __attribute__ ((visibility("default")))
  1101.  #endif
  1102.  
  1103.  #ifndef DCAPI_HOST
  1104. -/* current STLPort GIT implements this */
  1105. -# if _MSC_VER <= 1500 && (!defined(_STLPORT_VERSION) || (_STLPORT_VERSION < 0x600))
  1106. +# if defined(_MSC_VER) && _MSC_VER <= 1500 && (!defined(_STLPORT_VERSION) || (_STLPORT_VERSION < 0x600))
  1107.  typedef signed __int8 int8_t;
  1108.  typedef signed __int16 int16_t;
  1109.  typedef signed __int32 int32_t;
  1110. @@ -125,141 +63,79 @@
  1111.  # endif
  1112.  #endif
  1113.  
  1114. -/* Hook types */
  1115. -typedef enum tagHookType {
  1116. -   HOOK_ID = 0,                                    /* Used by the message register functions, to register new hooks */
  1117. -   HOOK_CALLBACK,                                  /* Callback (inbound) hook */
  1118. -   HOOK_EVENT                                      /* Regular (outbound) hook */
  1119. -} HookType;
  1120. -
  1121. -/* Hook IDs */
  1122. -typedef enum tagHookID {
  1123. -   /* Mandatory callback hook */
  1124. -   CALLBACK_BASE = 0,
  1125. -
  1126. -   /* Common hooks (none manadatory, however, one required) */
  1127. -   HOOK_PROTOCOL = 500,
  1128. -   HOOK_CHAT,
  1129. -   HOOK_HUBS,
  1130. -   HOOK_TIMER,
  1131. -   HOOK_QUEUE,
  1132. -   HOOK_UI,
  1133. -
  1134. -   /* Plugin created hooks and callbacks (HOOK_USER + n) */
  1135. -   HOOK_USER = 1000
  1136. -} HookID;
  1137. -
  1138. -typedef enum tagCallbackEvent {
  1139. -   /* Generic callback events */
  1140. -   DBG_MESSAGE = 0,
  1141. -   LOG_MESSAGE,
  1142. -   GET_PATHS,
  1143. -
  1144. -   /* Protocol callback events */
  1145. -   PROTOCOL_SEND_UDP = 500,
  1146. -   PROTOCOL_HUB_EMULATE_CMD,
  1147. -   PROTOCOL_HUB_SEND_CMD,
  1148. -   PROTOCOL_CONN_SEND_CMD,
  1149. -   PROTOCOL_CONN_TERMINATE,
  1150. -
  1151. -   /* Hub callback events */
  1152. -   HUBS_CREATE_HUB = 1000,
  1153. -   HUBS_DESTROY_HUB,
  1154. -   HUBS_FIND_HUB,
  1155. -   HUBS_SEND_CHAT,
  1156. -   HUBS_SEND_PM,
  1157. -   HUBS_SEND_LOCAL,
  1158. -
  1159. -   /* Queue callback events */
  1160. -   QUEUE_ADD_DL = 1500,
  1161. -   QUEUE_REMOVE_DL,
  1162. -   QUEUE_SET_PRIORITY,
  1163. -
  1164. -   /* [2000, 2499] Reserved for UI callback events */
  1165. -
  1166. -   /* Plugin created callback events (CALLBACK_USER + n) */
  1167. -   CALLBACK_USER = 2500
  1168. -} CallbackEvent;
  1169. -
  1170. -typedef enum tagHookEvent {
  1171. -   /* Main hook events (returned by pluginInit) */
  1172. -   ON_INSTALL = 0,                                 /* Replaces ON_LOAD for the very first loading of the plugin */
  1173. -   ON_UNINSTALL,                                   /* Replaces ON_UNLOAD when plugin is being uninstalled */
  1174. -   ON_LOAD,                                        /* Sent after successful call to pluginInit */
  1175. -   ON_UNLOAD,                                      /* Sent right before plugin is unloaded (no params) */
  1176. -   ON_CONFIGURE,                                   /* Sent when user wants to configure the plugin (obj: obj: impl. dependant or NULL) */
  1177. -
  1178. -   /* Chat hook events (HOOK_CHAT) */
  1179. -   CHAT_IN = 500,                                  /* Incoming chat from hub (obj: ClientData) */
  1180. -   CHAT_OUT,                                       /* Outgoing chat (obj: ClientData) */
  1181. -   CHAT_PM_IN,                                     /* Incoming private message (obj: UserData) */
  1182. -   CHAT_PM_OUT,                                    /* Outgoing private message (obj: UserData) */
  1183. -
  1184. -   /* Timer hook events (HOOK_TIMER) */
  1185. -   TIMER_SECOND = 1000,                            /* Timer event fired once per second (tick value) */
  1186. -   TIMER_MINUTE,                                   /* Timer event fired once per minute (tick value) */
  1187. -
  1188. -   /* Hubs hook events (HOOK_HUBS) */
  1189. -   HUB_OFFLINE = 1500,                             /* Hub has just gone offline (obj: ClientData) */
  1190. -   HUB_ONLINE,                                     /* (New) hub has just gone online (obj: ClientData) */
  1191. -
  1192. -   /* Connections hook events (HOOK_PROTOCOL) */
  1193. -   HUB_IN = 2000,                                  /* Incoming protocol messages from hub (obj: ClientData) */
  1194. -   HUB_OUT,                                        /* Outgoing protocol message to hub (obj: ClientData) */
  1195. -   CONN_IN,                                        /* Incoming client<->client protocol message (obj: ConnectionData) */
  1196. -   CONN_OUT,                                       /* Outgoing client<->client protocol message (obj: ConnectionData) */
  1197. -
  1198. -   /* Queue hook events (HOOK_QUEUE) */
  1199. -   QUEUE_ADD = 2500,                               /* (New) item has been added to download queue (obj: QueueData) */
  1200. -   QUEUE_MOVE,                                     /* Download queue item has been moved to new location (obj: QueueData) */
  1201. -   QUEUE_REMOVE,                                   /* Item has just been removed from download queue (obj: QueueData) */
  1202. -   QUEUE_FINISHED,                                 /* Item has just finished downloading (obj: QueueData) */
  1203. -
  1204. -   /* UI hook events (HOOK_UI) */
  1205. -   UI_CREATED = 3000,                              /* Host node UI has been created (if any, obj: impl. dependant) */
  1206. -   UI_CHAT_DISPLAY,                                /* Chat messages before displayed in chat (obj: StringData) */
  1207. -   UI_PROCESS_CHAT_CMD,                            /* Client side commands in chat (obj: CommandData) */
  1208. -
  1209. -   /* Plugin created hook events (EVENT_USER + n) */
  1210. -   EVENT_USER = 3500
  1211. -} HookEvent;
  1212. -
  1213. -/* Conversion functions */
  1214. -typedef enum tagConversionType {
  1215. -   CONV_TO_UTF8 = 0,                               /* Convert string to UTF-8 */
  1216. -   CONV_FROM_UTF8,                                 /* Reverse of CONV_TO_UTF8 */
  1217. -   CONV_UTF8_TO_WIDE,                              /* Convert UTF-8 string to wide character string */
  1218. -   CONV_WIDE_TO_UTF8,                              /* Reverse of CONV_UTF8_TO_WIDE */
  1219. -   CONV_TO_BASE32,                                 /* Convert unsigned short data (uint8_t*, array) to string */
  1220. -   CONV_FROM_BASE32                                /* Reverse of CONV_TO_BASE32 */
  1221. -} ConversionType;
  1222. +/* Interface GUID's */
  1223. +#define INTERFACE_HOOKS                "generic.plugins.DCHooks"   /* This is *required* for plugins to actually be able to do anything */
  1224. +
  1225. +#define INTERFACE_CONFIG           "generic.plugins.DCConfig"  /* Config managemen */
  1226. +#define INTERFACE_LOGGING          "generic.plugins.DCLog"     /* Logging functions */
  1227. +
  1228. +#define INTERFACE_DCPP_CONNECTIONS "dcpp.network.DCConnection" /* Client<->client connections */
  1229. +#define INTERFACE_DCPP_HUBS            "dcpp.network.DCHub"        /* Hubs */
  1230. +#define INTERFACE_DCPP_QUEUE       "dcpp.queue.DCQueue"        /* Download Queue (TODO: expand) */
  1231. +#define INTERFACE_DCPP_UTILS       "dcpp.utils.DCUtils"        /* Utility and convenience functions */
  1232. +
  1233. +/* Hook GUID's for event system */
  1234. +#define HOOK_CHAT_IN               "dcpp.chat.onIncomingChat"  /* Incoming chat from hub (obj: HubData) */
  1235. +#define HOOK_CHAT_OUT              "dcpp.chat.onOutgoingChat"  /* Outgoing chat (obj: HubData) */
  1236. +#define HOOK_CHAT_PM_IN                "dcpp.chat.onIncomingPM"    /* Incoming private message (obj: UserData) */
  1237. +#define HOOK_CHAT_PM_OUT           "dcpp.chat.onOutgoingPM"    /* Outgoing private message (obj: UserData) */
  1238. +
  1239. +#define HOOK_TIMER_SECOND          "dcpp.timer.onSecond"       /* Timer event fired once per second (tick value) */
  1240. +#define HOOK_TIMER_MINUTE          "dcpp.timer.onMinute"       /* Timer event fired once per minute (tick value) */
  1241. +
  1242. +#define HOOK_HUB_ONLINE                "dcpp.hubs.onOnline"        /* (New) hub has just gone online (obj: HubData) */
  1243. +#define HOOK_HUB_OFFLINE           "dcpp.hubs.onOffline"       /* Hub has just gone offline (obj: HubData) */
  1244. +
  1245. +#define HOOK_NETWORK_HUB_IN            "dcpp.network.onHubDataIn"      /* Incoming protocol messages from hub (obj: HubData) */
  1246. +#define HOOK_NETWORK_HUB_OUT       "dcpp.network.onHubDataOut"     /* Outgoing protocol message to hub (obj: HubData) */
  1247. +#define HOOK_NETWORK_CONN_IN       "dcpp.network.onClientDataIn"   /* Incoming client<->client protocol message (obj: ConnectionData) */
  1248. +#define HOOK_NETWORK_CONN_OUT      "dcpp.network.onClientDataOut"  /* Outgoing client<->client protocol message (obj: ConnectionData) */
  1249. +
  1250. +#define HOOK_QUEUE_ADD             "dcpp.queue.onAdd"          /* (New) item has been added to download queue (obj: QueueData) */
  1251. +#define HOOK_QUEUE_MOVE                "dcpp.queue.onMove"         /* Download queue item has been moved to new location (obj: QueueData) */
  1252. +#define HOOK_QUEUE_REMOVE          "dcpp.queue.onRemove"       /* Item has just been removed from download queue (obj: QueueData) */
  1253. +#define HOOK_QUEUE_FINISHED            "dcpp.queue.onFinished"     /* Item has just finished downloading (obj: QueueData) */
  1254. +
  1255. +#define HOOK_UI_CREATED                "dcpp.ui.onCreated"         /* Host application UI has been created (if any, obj: impl. dependant) */
  1256. +#define HOOK_UI_CHAT_DISPLAY       "dcpp.ui.onChatDisplay"     /* Chat messages before displayed in chat (obj: StringData) */
  1257. +#define HOOK_UI_PROCESS_CHAT_CMD   "dcpp.ui.onProcessCmd"      /* Client side commands in chat (obj: CommandData) */
  1258. +
  1259. +/* Main hook events (returned by pluginInit) */
  1260. +typedef enum tagPluginState {
  1261. +   ON_INSTALL = 0,                                             /* Replaces ON_LOAD for the very first loading of the plugin */
  1262. +   ON_UNINSTALL,                                               /* Replaces ON_UNLOAD when plugin is being uninstalled */
  1263. +   ON_LOAD,                                                    /* Sent after successful call to pluginInit (obj: DCCore) */
  1264. +   ON_UNLOAD,                                                  /* Sent right before plugin is unloaded (no params) */
  1265. +   ON_CONFIGURE                                                /* Sent when user wants to configure the plugin (obj: DCCore, data: impl. dependant) */
  1266. +} PluginState;
  1267.  
  1268. +/* Argument types */
  1269.  typedef enum tagConfigType {
  1270. -   CFG_TYPE_REMOVE = -1,                           /* Config value will be removed */
  1271. -   CFG_TYPE_STRING,                                /* Config value is string */
  1272. -   CFG_TYPE_INT,                                   /* Config value is 32bit integer */
  1273. -   CFG_TYPE_INT64                                  /* Config value is 64bit integer */
  1274. +   CFG_TYPE_REMOVE = -1,                                       /* Config value will be removed */
  1275. +   CFG_TYPE_STRING,                                            /* Config value is string */
  1276. +   CFG_TYPE_INT,                                               /* Config value is 32bit integer */
  1277. +   CFG_TYPE_INT64                                              /* Config value is 64bit integer */
  1278.  } ConfigType;
  1279.  
  1280.  typedef enum tagProtocolType {
  1281. -   PROTOCOL_ADC = 0,                               /* Protocol used ís ADC */
  1282. -   PROTOCOL_NMDC,                                  /* Protocol used is NMDC */
  1283. -   PROTOCOL_DHT                                    /* DHT node (not used, reserved) */
  1284. +   PROTOCOL_ADC = 0,                                           /* Protocol used ís ADC */
  1285. +   PROTOCOL_NMDC,                                              /* Protocol used is NMDC */
  1286. +   PROTOCOL_DHT                                                /* DHT node (not used, reserved) */
  1287.  } ProtocolType;
  1288.  
  1289.  typedef enum tagPathType {
  1290. -   PATH_GLOBAL_CONFIG = 0,                         /* Global configuration */
  1291. -   PATH_USER_CONFIG,                               /* Per-user configuration (queue, favorites, ...) */
  1292. -   PATH_USER_LOCAL,                                /* Per-user local data (cache, temp files, ...) */                 
  1293. -   PATH_RESOURCES,                                 /* Various resources (help files etc) */
  1294. -   PATH_LOCALE                                     /* Translations */
  1295. +   PATH_GLOBAL_CONFIG = 0,                                     /* Global configuration */
  1296. +   PATH_USER_CONFIG,                                           /* Per-user configuration (queue, favorites, ...) */
  1297. +   PATH_USER_LOCAL,                                            /* Per-user local data (cache, temp files, ...) */                 
  1298. +   PATH_RESOURCES,                                             /* Various resources (help files etc) */
  1299. +   PATH_LOCALE                                                 /* Translations */
  1300.  } PathType;
  1301.  
  1302.  typedef enum tagMsgType {
  1303. -   MSG_CLIENT = 0,                                 /* General text style */
  1304. -   MSG_STATUS,                                     /* Message in status bar */
  1305. -   MSG_SYSTEM,                                     /* Message with system message format */
  1306. -   MSG_CHEAT                                       /* Message with cheat message format */
  1307. +   MSG_CLIENT = 0,                                             /* General text style */
  1308. +   MSG_STATUS,                                                 /* Message in status bar */
  1309. +   MSG_SYSTEM,                                                 /* Message with system message format */
  1310. +   MSG_CHEAT                                                   /* Message with cheat message format */
  1311.  } MsgType;
  1312.  
  1313.  typedef enum tagQueuePrio {
  1314. @@ -272,8 +148,8 @@
  1315.     PRIO_HIGHEST
  1316.  } QueuePrio;
  1317.  
  1318. -/* Types */
  1319. -typedef void *hookHandle, *dcptr_t, *subsHandle;
  1320. +/* Data types */
  1321. +typedef void *hookHandle, *subsHandle, *intfHandle, *dcptr_t;
  1322.  typedef enum tagDCBool { dcFalse = 0, dcTrue } dcBool;
  1323.  
  1324.  /* Workaround for other bool defs */
  1325. @@ -281,15 +157,9 @@
  1326.  #define True dcTrue
  1327.  #define False dcFalse
  1328.  
  1329. -/* Hook function prototypes */
  1330. -typedef Bool (DCAPI *DCHOOK)       (uint32_t eventId, dcptr_t pData);
  1331. -typedef Bool (DCAPI* DCHOOKEX)     (uint32_t eventId, dcptr_t pData, Bool* bBreak);
  1332. -typedef Bool (DCAPI* DCHOOKCOMMON) (uint32_t eventId, dcptr_t pData, void* pCommon);
  1333. -typedef Bool (DCAPI* DCHOOKCOMMONEX)(uint32_t eventId, dcptr_t pData, void* pCommon, Bool* bBreak);
  1334. -
  1335. -/* Config Value (for get_cfg/set_cfg) */
  1336. +/* Config Value */
  1337.  typedef struct tagConfigValue {
  1338. -   ConfigType type;                                /* Indicates which type value holds */
  1339. +   ConfigType type;                                            /* Indicates which type value holds */
  1340.     union {
  1341.         const char* str;
  1342.         int32_t int32;
  1343. @@ -299,265 +169,161 @@
  1344.  
  1345.  /* String Data (for substitutions) */
  1346.  typedef struct tagStringData {
  1347. -   dcptr_t object;                                 /* Any related object (internal, may be omitted) */
  1348. -   const char* in;                                 /* Incoming string */
  1349. -   char* out;                                      /* Resulting new string (allocated with DCCore::memalloc) */
  1350. +   const char* in;                                             /* Incoming string */
  1351. +   char* out;                                                  /* Resulting new string */
  1352.  } StringData, *StringDataPtr;
  1353.  
  1354.  /* Client side chat commands */
  1355.  typedef struct tagCommandData {
  1356. -   dcptr_t object;                                 /* UserData or ClientData based on isPrivate */
  1357. -   const char* command;                            /* Command name */
  1358. -   const char* params;                             /* Command parameters passed */
  1359. -   Bool isPrivate;                                 /* Used in a private context (private messages) */
  1360. +   const char* command;                                        /* Command name */
  1361. +   const char* params;                                         /* Command parameters passed */
  1362. +   Bool isPrivate;                                             /* Used in a private context (private messages) */
  1363.  } CommandData, *CommandDataPtr;
  1364.  
  1365.  /* Users */
  1366.  typedef struct tagUserData {
  1367. -   const char* data;                               /* Data sent/received */
  1368. -   const char* hubHint;                            /* Contains hub url to find the user from */
  1369. -   const uint8_t* cid;                             /* User CID (raw data, size: 192 / 8) */
  1370. -   dcptr_t object;                                 /* The source/destination for the data */
  1371. -   ProtocolType protocol;                          /* The protocol used */
  1372. -   Bool isOp;                                      /* Whether user has a key or not */
  1373. +   const char* hubHint;                                        /* Contains hub url to find the user from */
  1374. +   const uint8_t* cid;                                         /* User CID (raw data, size: 192 / 8) */
  1375. +   dcptr_t object;                                             /* The source/destination for the data */
  1376. +   ProtocolType protocol;                                      /* The protocol used */
  1377. +   Bool isOp;                                                  /* Whether user has a key or not */
  1378.     union {
  1379. -       char nick[36];                              /* Users nick (only valid in NMDC) */
  1380. -       uint32_t sid;                               /* Users SID (only valid in ADC) */
  1381. +       char nick[36];                                          /* Users nick (only valid in NMDC) */
  1382. +       uint32_t sid;                                           /* Users SID (only valid in ADC) */
  1383.     } uid;
  1384.  } UserData, *UserDataPtr;
  1385.  
  1386. -/* Hubs (clients) */
  1387. -typedef struct tagClientData {
  1388. -   const char* data;                               /* Data sent/received */
  1389. -   const char* url;                                /* Hub url address */
  1390. -   const char* ip;                                 /* Hub ip address */
  1391. -   dcptr_t object;                                 /* The source/destination for the data */
  1392. -   uint16_t port;                                  /* Hub port */
  1393. -   ProtocolType protocol;                          /* The protocol used */
  1394. -   Bool isOp;                                      /* Whether we have a key on this hub or not */
  1395. -   Bool isSecure;                                  /* True for TLS encrypted connections */
  1396. -} ClientData, *ClientDataPtr;
  1397. +/* Hubs */
  1398. +typedef struct tagHubData {
  1399. +   const char* url;                                            /* Hub url address */
  1400. +   const char* ip;                                             /* Hub ip address */
  1401. +   dcptr_t object;                                             /* The source/destination for the data */
  1402. +   uint16_t port;                                              /* Hub port */
  1403. +   ProtocolType protocol;                                      /* The protocol used */
  1404. +   Bool isOp;                                                  /* Whether we have a key on this hub or not */
  1405. +   Bool isSecure;                                              /* True for TLS encrypted connections */
  1406. +} HubData, *HubDataPtr;
  1407.  
  1408.  /* Client<->client connections */
  1409.  typedef struct tagConnectionData {
  1410. -   const char* data;                               /* The data sent/received */
  1411. -   const char* ip;                                 /* The ip address (remote) for this connection */
  1412. -   dcptr_t object;                                 /* The source/destination for the data */
  1413. -   uint16_t port;                                  /* The port for this connection */
  1414. -   ProtocolType protocol;                          /* The protocol used */
  1415. -   Bool isOp;                                      /* Whether user has a key or not */
  1416. -   Bool isSecure;                                  /* True for TLS encrypted connections */
  1417. +   const char* ip;                                             /* The ip address (remote) for this connection */
  1418. +   dcptr_t object;                                             /* The source/destination for the data */
  1419. +   uint16_t port;                                              /* The port for this connection */
  1420. +   ProtocolType protocol;                                      /* The protocol used */
  1421. +   Bool isOp;                                                  /* Whether user has a key or not */
  1422. +   Bool isSecure;                                              /* True for TLS encrypted connections */
  1423.  } ConnectionData, *ConnectionDataPtr;
  1424.  
  1425.  /* Queue items and files */
  1426.  typedef struct tagQueueData {
  1427. -   const char* file;                               /* File name */
  1428. -   const char* target;                             /* The *final* location for the file */
  1429. -   const char* location;                           /* The *current* location for the file (may be same as target) */
  1430. -   const uint8_t* hash;                            /* TTH hash of the file (raw data, size: 192 / 8) */
  1431. -   dcptr_t object;                                 /* The source/destination for the data */
  1432. -   uint64_t size;                                  /* File size (bytes) */
  1433. -   Bool isFileList;                                /* FileList download */
  1434. +   const char* file;                                           /* File name */
  1435. +   const char* target;                                         /* The *final* location for the file */
  1436. +   const char* location;                                       /* The *current* location for the file (may be same as target) */
  1437. +   const uint8_t* hash;                                        /* TTH hash of the file (raw data, size: 192 / 8) */
  1438. +   dcptr_t object;                                             /* The source/destination for the data */
  1439. +   uint64_t size;                                              /* File size (bytes) */
  1440. +   Bool isFileList;                                            /* FileList download */
  1441.  } QueueData, *QueueDataPtr;
  1442.  
  1443.  /* Plugin meta data */
  1444.  typedef struct tagMetaData {
  1445. -   const char* name;                               /* Name of the plugin */
  1446. -   const char* author;                             /* Name/Nick of the plugin author */
  1447. -   const char* description;                        /* *Short* description of plugin functionality (may be multiple lines) */
  1448. -   const char* web;                                /* Authors website if any */
  1449. -   const char* guid;                               /* Plugins unique GUID */
  1450. -   const char** dependencies;                      /* Array of plugin dependencies */
  1451. -   uint32_t numDependencies;                       /* Number of plugin GUIDs in dependencies array */
  1452. -   double version;                                 /* Plugin version */
  1453. -   double apiVersion;                              /* API version the plugin was compiled against */
  1454. -   double compatibleVersion;                       /* Earliest API version the plugin can be used with */
  1455. +   const char* name;                                           /* Name of the plugin */
  1456. +   const char* author;                                         /* Name/Nick of the plugin author */
  1457. +   const char* description;                                    /* *Short* description of plugin functionality (may be multiple lines) */
  1458. +   const char* web;                                            /* Authors website if any */
  1459. +   const char* guid;                                           /* Plugins unique GUID */
  1460. +   const char** dependencies;                                  /* Array of plugin dependencies */
  1461. +   uint32_t numDependencies;                                   /* Number of plugin GUIDs in dependencies array */
  1462. +   double version;                                             /* Plugin version */
  1463. +   double apiVersion;                                          /* API version the plugin was compiled against */
  1464. +   double compatibleVersion;                                   /* Earliest API version the plugin can be used with */
  1465.  } MetaData, *MetaDataPtr;
  1466.  
  1467. -/* Interaction layer */
  1468. +/* Plugin management */
  1469.  typedef struct tagDCCore {
  1470.     /* Core API version */
  1471.     double apiVersion;
  1472.  
  1473. -   /* Hook creation */
  1474. -   hookHandle  (DCAPI *create_hook)        (HookID hookId, HookType hookType, DCHOOK defProc);
  1475. -   void        (DCAPI *destroy_hook)       (hookHandle hHook);
  1476. -
  1477. -   /* Hook interaction */
  1478. -   subsHandle  (DCAPI *set_hook)           (HookID hookId, DCHOOK hookProc, void* pCommon);
  1479. -   Bool        (DCAPI *call_hook)          (HookID hookId, uint32_t eventId, dcptr_t pData);
  1480. -   size_t      (DCAPI *un_hook)            (subsHandle hHook);
  1481. -
  1482. -   /* Message regitster */
  1483. -   uint32_t    (DCAPI *register_message)   (HookType type, const char* name);
  1484. -   uint32_t    (DCAPI *register_range)     (HookType type, const char* name, uint32_t count);
  1485. -   uint32_t    (DCAPI *seek_message)       (const char* name);
  1486. -
  1487. -   /* Settings management */
  1488. -   void        (DCAPI *set_cfg)            (const char* guid, const char* setting, ConfigValuePtr val);
  1489. -   Bool        (DCAPI *get_cfg)            (const char* guid, const char* setting, ConfigValuePtr val);
  1490. -
  1491. -   /* General */
  1492. -   void*       (DCAPI *memalloc)           (void* ptr, size_t bytes);
  1493. -   size_t      (DCAPI *strconv)            (ConversionType type, void* dst, void* src, size_t len);
  1494. +   /* Interface registry */
  1495. +   intfHandle          (DCAPI *register_interface) (const char* guid, dcptr_t cbFuncs);
  1496. +   dcptr_t             (DCAPI *query_interface)    (const char* guid);
  1497. +   Bool                (DCAPI *release_interface)  (intfHandle hCallbacks);
  1498.  } DCCore, *DCCorePtr;
  1499.  
  1500. -/* For callback function arguments (after long thinking and with much regret) */
  1501. -typedef struct tagTextDataCond {
  1502. -   const char* data;
  1503. -   uint32_t cond;
  1504. -   char* res;
  1505. -} TextDataCond, *TextDataCondPtr;
  1506. -
  1507. -typedef struct tagTextArgsRes {
  1508. -   dcptr_t object;
  1509. -   const char* data;
  1510. -   dcptr_t res;
  1511. -} TextArgsRes, *TextArgsResPtr;
  1512. -
  1513. -typedef struct tagTextArgsCond {
  1514. -   dcptr_t object;
  1515. -   const char* data;
  1516. -   uint32_t cond;
  1517. -} TextArgsCond, *TextArgsCondPtr;
  1518. -
  1519. -typedef struct tagQueueArgs {
  1520. -   const char* target;
  1521. -   int64_t size;
  1522. -   const char* hash;
  1523. -   QueueDataPtr res;
  1524. -} QueueArgs, *QueueArgsPtr;
  1525. +/* Plugin main function */
  1526. +typedef Bool (DCAPI* DCMAIN)       (PluginState pluginState, DCCorePtr core, dcptr_t pData);
  1527.  
  1528. -#ifndef DCAPI_HOST
  1529. -/* And then some macros so no-one has to figure out what goes where above */
  1530. -#define BASE_DBG_MESSAGE(core, aMsg)       { core->call_hook(CALLBACK_BASE, DBG_MESSAGE, (dcptr_t)aMsg); }
  1531. -#define BASE_LOG_MESSAGE(core, aMsg)       { core->call_hook(CALLBACK_BASE, LOG_MESSAGE, (dcptr_t)aMsg); }
  1532. -#define BASE_DESTROY_HUB(core, client)     { core->call_hook(CALLBACK_BASE, HUBS_DESTROY_HUB, client); }
  1533. -#define BASE_QUEUE_REMOVE_DL(core, aTarget)    { core->call_hook(CALLBACK_BASE, QUEUE_REMOVE_DL, (dcptr_t)aTarget); }
  1534. -
  1535. -#define BASE_GET_PATHS(core, type, aData) \
  1536. -{ \
  1537. -   TextDataCond args; \
  1538. -   memset(&args, 0, sizeof(TextDataCond)); \
  1539. -   args.cond = type; \
  1540. -   core->call_hook(CALLBACK_BASE, GET_PATHS, &args); \
  1541. -   aData = args.res; \
  1542. -}
  1543. -
  1544. -#define BASE_SEND_UDP(core, aIP, aPort, aData) \
  1545. -{ \
  1546. -   TextDataCond args; \
  1547. -   memset(&args, 0, sizeof(TextDataCond)); \
  1548. -   args.data = aIP; \
  1549. -   args.cond = aPort; \
  1550. -   args.res = (char*)aData; \
  1551. -   core->call_hook(CALLBACK_BASE, PROTOCOL_SEND_UDP, &args); \
  1552. -}
  1553. -
  1554. -#define BASE_HUB_EMULATE_CMD(core, client, cmd) \
  1555. -{ \
  1556. -   TextArgsRes args; \
  1557. -   memset(&args, 0, sizeof(TextArgsRes)); \
  1558. -   args.object = client; \
  1559. -   args.data = cmd; \
  1560. -   core->call_hook(CALLBACK_BASE, PROTOCOL_HUB_EMULATE_CMD, &args); \
  1561. -}
  1562. -
  1563. -#define BASE_HUB_SEND_CMD(core, client, cmd) \
  1564. -{ \
  1565. -   TextArgsRes args; \
  1566. -   memset(&args, 0, sizeof(TextArgsRes)); \
  1567. -   args.object = client; \
  1568. -   args.data = cmd; \
  1569. -   core->call_hook(CALLBACK_BASE, PROTOCOL_HUB_SEND_CMD, &args); \
  1570. -}
  1571. -
  1572. -#define BASE_CONN_SEND_CMD(core, uc, cmd) \
  1573. -{ \
  1574. -   TextArgsRes args; \
  1575. -   memset(&args, 0, sizeof(TextArgsRes)); \
  1576. -   args.object = uc; \
  1577. -   args.data = cmd; \
  1578. -   core->call_hook(CALLBACK_BASE, PROTOCOL_CONN_SEND_CMD, &args); \
  1579. -}
  1580. -
  1581. -#define BASE_CONN_TERMINATE(core, uc, graceless) \
  1582. -{ \
  1583. -   TextArgsCond args; \
  1584. -   memset(&args, 0, sizeof(TextArgsCond)); \
  1585. -   args.object = uc; \
  1586. -   args.cond = graceless; \
  1587. -   core->call_hook(CALLBACK_BASE, PROTOCOL_CONN_TERMINATE, &args); \
  1588. -}
  1589. -
  1590. -#define BASE_CREATE_HUB(core, aUrl, aData) \
  1591. -{ \
  1592. -   TextArgsRes args; \
  1593. -   memset(&args, 0, sizeof(TextArgsRes)); \
  1594. -   args.data = aUrl; \
  1595. -   args.res = aData; \
  1596. -   core->call_hook(CALLBACK_BASE, HUBS_CREATE_HUB, &args); \
  1597. -}
  1598. +/* Event system (required!) */
  1599.  
  1600. -#define BASE_FIND_HUB(core, aUrl, aData) \
  1601. -{ \
  1602. -   TextArgsRes args; \
  1603. -   memset(&args, 0, sizeof(TextArgsRes)); \
  1604. -   args.data = aUrl; \
  1605. -   args.res = aData; \
  1606. -   core->call_hook(CALLBACK_BASE, HUBS_FIND_HUB, &args); \
  1607. -}
  1608. -
  1609. -#define BASE_HUB_SEND_CHAT(core, client, aMsg, third_person) \
  1610. -{ \
  1611. -   TextArgsCond args; \
  1612. -   memset(&args, 0, sizeof(TextArgsCond)); \
  1613. -   args.object = client; \
  1614. -   args.data = aMsg; \
  1615. -   args.cond = third_person; \
  1616. -   core->call_hook(CALLBACK_BASE, HUBS_SEND_CHAT, &args); \
  1617. -}
  1618. -
  1619. -#define BASE_HUB_SEND_PM(core, ou, aMsg, third_person) \
  1620. -{ \
  1621. -   TextArgsCond args; \
  1622. -   memset(&args, 0, sizeof(TextArgsCond)); \
  1623. -   args.object = ou; \
  1624. -   args.data = aMsg; \
  1625. -   args.cond = third_person; \
  1626. -   core->call_hook(CALLBACK_BASE, HUBS_SEND_PM, &args); \
  1627. -}
  1628. +/* Hook function prototypes */
  1629. +typedef Bool (DCAPI* DCHOOK)       (dcptr_t pObject, dcptr_t pData, Bool* bBreak);
  1630. +typedef Bool (DCAPI* DCHOOKCOMMON) (dcptr_t pObject, dcptr_t pData, void* pCommon, Bool* bBreak);
  1631.  
  1632. -#define BASE_HUB_SEND_LOCAL(core, type, client, aMsg) \
  1633. -{ \
  1634. -   TextArgsCond args; \
  1635. -   memset(&args, 0, sizeof(TextArgsCond)); \
  1636. -   args.object = client; \
  1637. -   args.data = aMsg; \
  1638. -   args.cond = type; \
  1639. -   core->call_hook(CALLBACK_BASE, HUBS_SEND_LOCAL, &args); \
  1640. -}
  1641. +/* Hook management */
  1642. +typedef struct tagDCHooks {
  1643. +   /* Hook creation */
  1644. +   hookHandle          (DCAPI *create_hook)        (const char* guid, DCHOOK defProc);
  1645. +   Bool                (DCAPI *destroy_hook)       (hookHandle hHook);
  1646.  
  1647. -#define BASE_QUEUE_ADD_DL(core, aTarget, aSize, aHash, aFlags, aData) \
  1648. -{ \
  1649. -   QueueArgs args; \
  1650. -   memset(&args, 0, sizeof(QueueArgs)); \
  1651. -   args.target = aTarget; \
  1652. -   args.size = aSize; \
  1653. -   args.hash = aHash; \
  1654. -   args.res = aData; \
  1655. -   core->call_hook(CALLBACK_BASE, QUEUE_ADD_DL, &args); \
  1656. -}
  1657. +   /* Hook interaction */
  1658. +   subsHandle          (DCAPI *bind_hook)          (const char* guid, DCHOOK hookProc, void* pCommon);
  1659. +   Bool                (DCAPI *run_hook)           (const char* guid, dcptr_t pObject, dcptr_t pData);
  1660. +   size_t              (DCAPI *release_hook)       (subsHandle hHook);
  1661. +} DCHooks, *DCHooksPtr;
  1662. +
  1663. +/* Optional interfaces */
  1664. +
  1665. +/* Config management */
  1666. +typedef struct tagDCConfig {
  1667. +   const char*         (DCAPI *get_path)           (PathType type);
  1668. +   void                (DCAPI *set_cfg)            (const char* guid, const char* setting, ConfigValuePtr val);
  1669. +   Bool                (DCAPI *get_cfg)            (const char* guid, const char* setting, ConfigValuePtr val);
  1670. +} DCConfig, *DCConfigPtr;
  1671. +
  1672. +/* Logging functions */
  1673. +typedef struct tagDCLog {
  1674. +   void        (DCAPI *log)                        (const char* msg);
  1675. +} DCLog, *DCLogPtr;
  1676.  
  1677. -#define BASE_QUEUE_SET_PRIO(core, qi, aPrio) \
  1678. -{ \
  1679. -   TextArgsCond args; \
  1680. -   memset(&args, 0, sizeof(TextArgsCond)); \
  1681. -   args.object = qi; \
  1682. -   args.cond = aPrio; \
  1683. -   core->call_hook(CALLBACK_BASE, QUEUE_SET_PRIO, &args); \
  1684. -}
  1685. -#endif
  1686. +/* Client<->client connections */
  1687. +typedef struct tagDCConnection {
  1688. +   void            (DCAPI *send_udp_data)          (const char* ip, uint32_t port, dcptr_t data, size_t n);
  1689. +   void            (DCAPI *send_protocol_cmd)      (ConnectionDataPtr hConn, const char* cmd);
  1690. +   void            (DCAPI *terminate_conn)         (ConnectionDataPtr hConn, Bool graceless);
  1691. +} DCConnection, *DCConnectionPtr;
  1692. +
  1693. +/* Hubs */
  1694. +typedef struct tagDCHub {
  1695. +   HubDataPtr      (DCAPI *add_hub)                (const char* url, const char* nick, const char* password);
  1696. +   HubDataPtr      (DCAPI *find_hub)               (const char* url);
  1697. +   void            (DCAPI *remove_hub)             (HubDataPtr hHub);
  1698. +
  1699. +   void            (DCAPI *emulate_protocol_cmd)   (HubDataPtr hHub, const char* cmd);
  1700. +   void            (DCAPI *send_protocol_cmd)      (HubDataPtr hHub, const char* cmd);
  1701. +
  1702. +   void            (DCAPI *send_message)           (HubDataPtr hHub, const char* msg, Bool thirdPerson);
  1703. +   void            (DCAPI *local_message)          (HubDataPtr hHub, const char* msg, MsgType type);
  1704. +   void            (DCAPI *send_private_message)   (UserDataPtr hUser, const char* msg, Bool thirdPerson);
  1705. +} DCHub, *DCHubPtr;
  1706. +
  1707. +/* Download Queue (TODO: expand) */
  1708. +typedef struct tagDCQueue {
  1709. +   QueueDataPtr    (DCAPI *add_download)           (const char* hash, uint64_t size, const char* target);
  1710. +   void            (DCAPI *remove_download)        (const char* target);
  1711. +   void            (DCAPI *set_priority)           (QueueDataPtr hItem, QueuePrio priority);
  1712. +} DCQueue, *DCQueuePtr;
  1713. +
  1714. +/* Utility and convenience functions */
  1715. +typedef struct tagDCUtils {
  1716. +   size_t      (DCAPI *to_utf8)                    (char* dst, const char* src, size_t n);
  1717. +   size_t      (DCAPI *from_utf8)                  (char* dst, const char* src, size_t n);
  1718. +
  1719. +   size_t      (DCAPI *utf8_to_wcs)                (wchar_t* dst, const char* src, size_t n);
  1720. +   size_t      (DCAPI *wcs_to_utf8)                (char* dst, const wchar_t* src, size_t n);
  1721. +
  1722. +   size_t      (DCAPI *to_base32)                  (char* dst, const uint8_t* src, size_t n);
  1723. +   size_t      (DCAPI *from_base32)                (uint8_t* dst, const char* src, size_t n);
  1724. +} DCUtils, *DCUtilsPtr;
  1725.  
  1726.  #ifdef __cplusplus
  1727.  }
  1728. @@ -567,5 +333,5 @@
  1729.  
  1730.  /**
  1731.   * @file
  1732. - * $Id: PluginDefs.h 715 2010-09-09 12:13:53Z crise $
  1733. + * $Id: PluginDefs.h 1217 2012-01-08 16:15:57Z crise $
  1734.   */
  1735. --- PluginManager.cpp   Tue Jan 20 00:26:36 1970
  1736. +++ PluginManager.cpp   Tue Jan 20 00:26:36 1970
  1737. @@ -1,5 +1,5 @@
  1738.  /*
  1739. - * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
  1740. + * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
  1741.   *
  1742.   * This program is free software; you can redistribute it and/or modify
  1743.   * it under the terms of the GNU General Public License as published by
  1744. @@ -17,13 +17,17 @@
  1745.   */
  1746.  
  1747.  #include "stdinc.h"
  1748. -#include "DCPlusPlus.h"
  1749. -
  1750.  #include "PluginManager.h"
  1751. +
  1752. +#include <utility>
  1753. +
  1754.  #include "ConnectionManager.h"
  1755. +#include "QueueManager.h"
  1756. +#include "ClientManager.h"
  1757.  #include "StringTokenizer.h"
  1758.  #include "SimpleXML.h"
  1759.  #include "AdcHub.h"
  1760. +#include "UserConnection.h"
  1761.  
  1762.  #ifdef _WIN32
  1763.  # define PLUGIN_EXT "*.dll"
  1764. @@ -44,11 +48,11 @@
  1765.  
  1766.  namespace dcpp {
  1767.  
  1768. -uint32_t PluginManager::msgMaps[3] = { HOOK_USER, CALLBACK_USER, EVENT_USER };
  1769. +using std::swap;
  1770.  
  1771.  PluginInfo::~PluginInfo() {
  1772.     bool isSafe = true;
  1773. -   if(mainHook((PluginManager::getInstance()->getShutdown() ? ON_UNLOAD : ON_UNINSTALL), NULL) == False) {
  1774. +   if(dcMain((PluginManager::getInstance()->getShutdown() ? ON_UNLOAD : ON_UNINSTALL), NULL, NULL) == False) {
  1775.         // Plugin performs operation critical tasks (runtime unload not possible)
  1776.         isSafe = !PluginManager::getInstance()->addInactivePlugin(handle);
  1777.     } if(isSafe && handle != NULL) {
  1778. @@ -58,9 +62,13 @@
  1779.  }
  1780.  
  1781.  void PluginManager::loadPlugins(void (*f)(void*, const string&), void* p) {
  1782. -   coreHook = PluginApiImpl::initAPI(dcCore);
  1783. +   PluginApiImpl::initAPI(dcCore);
  1784.  
  1785. -   StringTokenizer<string> st(getSetting("CoreSetup", "Plugins"), ";");
  1786. +   TimerManager::getInstance()->addListener(this);
  1787. +   ClientManager::getInstance()->addListener(this);
  1788. +   QueueManager::getInstance()->addListener(this);
  1789. +
  1790. +   StringTokenizer<string> st(getPluginSetting("CoreSetup", "Plugins"), ";");
  1791.     for(StringIter i = st.getTokens().begin(); i != st.getTokens().end(); ++i) {
  1792.         if(!loadPlugin(*i) || !f) continue;
  1793.         (*f)(p, Util::getFileName(*i));
  1794. @@ -69,9 +77,12 @@
  1795.  
  1796.  bool PluginManager::loadPlugin(const string& fileName, bool isInstall /*= false*/) {
  1797.     Lock l(cs);
  1798. +
  1799. +   dcassert(dcCore.apiVersion != 0);
  1800. +
  1801.     pluginHandle hr = LOAD_LIBRARY(fileName);
  1802.     if(!hr) {
  1803. -       LogManager::getInstance()->message("Error loading " + Util::getFileName(fileName) + ": " + GET_ERROR());
  1804. +       LogManager::getInstance()->message(str(F_("Error loading %1%: %2%") % Util::getFileName(fileName) % GET_ERROR()));
  1805.         return false;
  1806.     }
  1807.  
  1808. @@ -79,13 +90,13 @@
  1809.  
  1810.     if(pluginInfo != NULL) {
  1811.         MetaData info;
  1812. -       memset(&info, 0, sizeof(MetaData));
  1813. +       memzero(&info, sizeof(MetaData));
  1814.  
  1815. -       DCHOOK mainHook;
  1816. -       if((mainHook = pluginInfo(&info)) != NULL) {
  1817. +       DCMAIN dcMain;
  1818. +       if((dcMain = pluginInfo(&info)) != NULL) {
  1819.             if(checkPlugin(info)) {
  1820. -               if(mainHook((isInstall ? ON_INSTALL : ON_LOAD), &dcCore) != False) {
  1821. -                   plugins.push_back(new PluginInfo(fileName, hr, info, mainHook));
  1822. +               if(dcMain((isInstall ? ON_INSTALL : ON_LOAD), &dcCore, NULL) != False) {
  1823. +                   plugins.push_back(new PluginInfo(fileName, hr, info, dcMain));
  1824.                     return true;
  1825.                 }
  1826.             }
  1827. @@ -133,30 +144,28 @@
  1828.     }
  1829.  
  1830.     // Update plugin order
  1831. -   setSetting("CoreSetup", "Plugins", installed);
  1832. +   setPluginSetting("CoreSetup", "Plugins", installed);
  1833.  
  1834.     // Really unload plugins that have been flagged inactive (ON_UNLOAD returns False)
  1835. -   for(inactiveList::iterator i = inactive.begin(); i != inactive.end(); ++i)
  1836. +   for(auto i = inactive.begin(); i != inactive.end(); ++i)
  1837.         FREE_LIBRARY(*i);
  1838.  
  1839. -   if(hooks.size() > 1) {
  1840. +   if(!hooks.empty()) {
  1841.         // Destroy all hooks not freed correctly
  1842. -       for(hookList::iterator i = hooks.begin(); hooks.size() > 1;) {
  1843. -           if(i->second != coreHook) {
  1844. -               PluginHook* hook = i->second;
  1845. -               for_each(hook->subscribers.begin(), hook->subscribers.end(), DeleteFunction());
  1846. -               hook->subscribers.clear();
  1847. -               hooks.erase(i++);
  1848. -               delete hook;
  1849. -           } else ++i;
  1850. +       for(auto i = hooks.begin(); !hooks.empty();) {
  1851. +           PluginHook* hook = i->second;
  1852. +           for_each(hook->subscribers.begin(), hook->subscribers.end(), DeleteFunction());
  1853. +           hook->subscribers.clear();
  1854. +           hooks.erase(i++);
  1855. +           delete hook;
  1856.         }
  1857. -
  1858. -       TimerManager::getInstance()->removeListener(this);
  1859. -       ClientManager::getInstance()->removeListener(this);
  1860. -       QueueManager::getInstance()->removeListener(this);
  1861.     }
  1862.  
  1863. -   PluginApiImpl::releaseAPI(coreHook);
  1864. +   TimerManager::getInstance()->removeListener(this);
  1865. +   ClientManager::getInstance()->removeListener(this);
  1866. +   QueueManager::getInstance()->removeListener(this);
  1867. +
  1868. +   PluginApiImpl::releaseAPI();
  1869.  }
  1870.  
  1871.  void PluginManager::unloadPlugin(int index) {
  1872. @@ -183,22 +192,16 @@
  1873.  
  1874.  // Functions that call the plugin
  1875.  bool PluginManager::onChatDisplay(Client* client, tstring& line) {
  1876. -   hookList::iterator i = hooks.find(HOOK_UI);
  1877. -   if(i == hooks.end()) return false;
  1878. -
  1879.     StringData data;
  1880. -   memset(&data, 0, sizeof(StringData));
  1881. +   memzero(&data, sizeof(StringData));
  1882.  
  1883.     string tmpLine;
  1884. -   data.object = (client && client->isConnected()) ? client : NULL;
  1885.     data.in = Text::fromT(line, tmpLine).c_str();
  1886. +   HubData* object = client->getPluginObject();
  1887.  
  1888. -   if(callHook(i->second, UI_CHAT_DISPLAY, &data) && data.out != NULL) {
  1889. +   if(runHook(HOOK_UI_CHAT_DISPLAY, object, &data) && data.out != NULL) {
  1890.         line.clear();
  1891.         Text::toT(data.out, line);
  1892. -
  1893. -       // NOTE: Here we rely on plugins using DCCore::memalloc
  1894. -       free(data.out);
  1895.         return true;
  1896.     }
  1897.  
  1898. @@ -206,11 +209,8 @@
  1899.  }
  1900.  
  1901.  bool PluginManager::onChatCommand(Client* client, const string& line) {
  1902. -   hookList::iterator i = hooks.find(HOOK_UI);
  1903. -   if(i == hooks.end()) return false;
  1904. -
  1905.     CommandData data;
  1906. -   memset(&data, 0, sizeof(CommandData));
  1907. +   memzero(&data, sizeof(CommandData));
  1908.  
  1909.     string cmd, param;
  1910.     string::size_type si = line.find(' ');
  1911. @@ -221,38 +221,22 @@
  1912.         cmd = line.substr(1);
  1913.     }
  1914.  
  1915. -   ClientData object;
  1916. -   memset(&object, 0, sizeof(ClientData));
  1917. -
  1918. -   object.data = line.c_str();
  1919. -   object.url = client->getHubUrl().c_str();
  1920. -   object.ip = client->getIp().c_str();
  1921. -   object.object = client;
  1922. -   Util::toString(object.port) = client->getPort();
  1923. -   object.protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
  1924. -   object.isOp = client->isOp() ? True : False;
  1925. -   object.isSecure = client->isSecure() ? True : False;
  1926. -
  1927. -   data.object = &object;
  1928.     data.command = cmd.c_str();
  1929.     data.params = param.c_str();
  1930.     data.isPrivate = False;
  1931.  
  1932. -   return callHook(i->second, UI_PROCESS_CHAT_CMD, &data);
  1933. +   return runHook(HOOK_UI_PROCESS_CHAT_CMD, client->getPluginObject(), &data);
  1934.  }
  1935.  
  1936.  bool PluginManager::onChatCommandPM(const HintedUser& user, const string& line, bool isPriv) {
  1937. -   hookList::iterator i = hooks.find(HOOK_UI);
  1938. -   if(i == hooks.end()) return false;
  1939. -
  1940.     // Hopefully this is safe...
  1941.     bool res = false;
  1942. -   auto lock = ClientManager::getInstance()->lock();
  1943. +   ClientManager::getInstance()->lock();
  1944.     OnlineUser* ou = ClientManager::getInstance()->findOnlineUser(user.user->getCID(), user.hint, isPriv);
  1945.  
  1946.     if(ou) {
  1947.         CommandData data;
  1948. -       memset(&data, 0, sizeof(CommandData));
  1949. +       memzero(&data, sizeof(CommandData));
  1950.  
  1951.         string cmd, param;
  1952.         string::size_type si = line.find(' ');
  1953. @@ -263,411 +247,189 @@
  1954.             cmd = line.substr(1);
  1955.         }
  1956.  
  1957. -       UserData object;
  1958. -       memset(&object, 0, sizeof(UserData));
  1959. -
  1960. -       object.data = line.c_str();
  1961. -       object.hubHint = ou->getClient().getHubUrl().c_str();
  1962. -       object.cid = ou->getUser()->getCID().data();
  1963. -       object.object = (dcptr_t)ou;
  1964. -       object.isOp = ou->getIdentity().isOp() ? True : False;
  1965. -       if(ou->getUser()->isNMDC()) {
  1966. -           object.protocol = PROTOCOL_NMDC;
  1967. -           strncpy(object.uid.nick, ou->getIdentity().getNick().c_str(), 35);
  1968. -       } else {
  1969. -           object.protocol = PROTOCOL_ADC;
  1970. -           object.uid.sid = ou->getIdentity().getSID();
  1971. -       }
  1972. -
  1973. -       data.object = &object;
  1974.         data.command = cmd.c_str();
  1975.         data.params = param.c_str();
  1976.         data.isPrivate = True;
  1977.  
  1978. -       res = callHook(i->second, UI_PROCESS_CHAT_CMD, &data);
  1979. +       res = runHook(HOOK_UI_PROCESS_CHAT_CMD, ou->getPluginObject(), &data);
  1980.     }
  1981.  
  1982.     return res;
  1983.  }
  1984.  
  1985. -bool PluginManager::onOutgoingChat(Client* client, const string& message) {
  1986. -   hookList::iterator i = hooks.find(HOOK_CHAT);
  1987. -   if(i == hooks.end()) return false;
  1988. -
  1989. -   ClientData data;
  1990. -   memset(&data, 0, sizeof(ClientData));
  1991. -
  1992. -   data.data = message.c_str();
  1993. -   data.url = client->getHubUrl().c_str();
  1994. -   data.ip = client->getIp().c_str();
  1995. -   data.object = client;
  1996. -   Util::toString(data.port) = client->getPort();
  1997. -   data.protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
  1998. -   data.isOp = client->isOp() ? True : False;
  1999. -   data.isSecure = client->isSecure() ? True : False;
  2000. -
  2001. -   return callHook(i->second, CHAT_OUT, &data);
  2002. -}
  2003. -
  2004. -bool PluginManager::onOutgoingPM(const OnlineUser& user, const string& message) {
  2005. -   hookList::iterator i = hooks.find(HOOK_CHAT);
  2006. -   if(i == hooks.end()) return false;
  2007. -
  2008. -   UserData data;
  2009. -   memset(&data, 0, sizeof(UserData));
  2010. -
  2011. -   data.data = message.c_str();
  2012. -   data.hubHint = user.getClient().getHubUrl().c_str();
  2013. -   data.cid = user.getUser()->getCID().data();
  2014. -   data.object = (dcptr_t)&user;
  2015. -   data.isOp = user.getIdentity().isOp() ? True : False;
  2016. -   if(user.getUser()->isNMDC()) {
  2017. -       data.protocol = PROTOCOL_NMDC;
  2018. -       strncpy(data.uid.nick, user.getIdentity().getNick().c_str(), 35);
  2019. -   } else {
  2020. -       data.protocol = PROTOCOL_ADC;
  2021. -       data.uid.sid = user.getIdentity().getSID();
  2022. -   }
  2023. -
  2024. -   return callHook(i->second, CHAT_PM_OUT, &data);
  2025. -}
  2026. -
  2027. -bool PluginManager::onIncomingChat(Client* client, const string& message) {
  2028. -   hookList::iterator i = hooks.find(HOOK_CHAT);
  2029. -   if(i == hooks.end()) return false;
  2030. -
  2031. -   ClientData data;
  2032. -   memset(&data, 0, sizeof(ClientData));
  2033. -
  2034. -   data.data = message.c_str();
  2035. -   data.url = client->getHubUrl().c_str();
  2036. -   data.ip = client->getIp().c_str();
  2037. -   data.object = client;
  2038. -   Util::toString(data.port) = client->getPort();
  2039. -   data.protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
  2040. -   data.isOp = client->isOp() ? True : False;
  2041. -   data.isSecure = client->isSecure() ? True : False;
  2042. -
  2043. -   return callHook(i->second, CHAT_IN, &data);
  2044. -}
  2045. -
  2046. -bool PluginManager::onIncomingPM(const OnlineUser* user, const string& message) {
  2047. -   hookList::iterator i = hooks.find(HOOK_CHAT);
  2048. -   if(i == hooks.end()) return false;
  2049. -
  2050. -   UserData data;
  2051. -   memset(&data, 0, sizeof(UserData));
  2052. -
  2053. -   data.data = message.c_str();
  2054. -   data.hubHint = user->getClient().getHubUrl().c_str();
  2055. -   data.cid = user->getUser()->getCID().data();
  2056. -   data.object = (dcptr_t)user;
  2057. -   data.isOp = user->getIdentity().isOp() ? True : False;
  2058. -   if(user->getUser()->isNMDC()) {
  2059. -       data.protocol = PROTOCOL_NMDC;
  2060. -       strncpy(data.uid.nick, user->getIdentity().getNick().c_str(), 35);
  2061. -   } else {
  2062. -       data.protocol = PROTOCOL_ADC;
  2063. -       data.uid.sid = user->getIdentity().getSID();
  2064. +// Plugin interface registry
  2065. +intfHandle PluginManager::registerInterface(const string& guid, dcptr_t funcs) {
  2066. +   if(interfaces.find(guid) == interfaces.end())
  2067. +       interfaces.insert(make_pair(guid, funcs));
  2068. +   // Following ensures that only the original provider may remove this
  2069. +   return reinterpret_cast<intfHandle>((uintptr_t)funcs ^ secNum);
  2070. +}
  2071. +
  2072. +dcptr_t PluginManager::queryInterface(const string& guid) {
  2073. +   auto i = interfaces.find(guid);
  2074. +   if(i != interfaces.end()) {
  2075. +       return i->second;
  2076. +   } else return NULL;
  2077. +}
  2078. +
  2079. +bool PluginManager::releaseInterface(intfHandle hInterface) {
  2080. +   // Following ensures that only the original provider may remove this
  2081. +   dcptr_t funcs = reinterpret_cast<dcptr_t>((uintptr_t)hInterface ^ secNum);
  2082. +   for(auto i = interfaces.begin(); i != interfaces.end(); ++i) {
  2083. +       if(i->second == funcs) {
  2084. +           interfaces.erase(i);
  2085. +           return true;
  2086. +       }
  2087.     }
  2088. -
  2089. -   return callHook(i->second, CHAT_PM_IN, &data);
  2090. -}
  2091. -
  2092. -bool PluginManager::onIncomingHubData(Client* client, const string& message) {
  2093. -   hookList::iterator i = hooks.find(HOOK_PROTOCOL);
  2094. -   if(i == hooks.end()) return false;
  2095. -
  2096. -   ClientData data;
  2097. -   memset(&data, 0, sizeof(ClientData));
  2098. -
  2099. -   data.data = message.c_str();
  2100. -   data.url = client->getHubUrl().c_str();
  2101. -   data.ip = client->getIp().c_str();
  2102. -   data.object = client;
  2103. -   Util::toString(data.port) = client->getPort();
  2104. -   data.protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
  2105. -   data.isOp = client->isOp() ? True : False;
  2106. -   data.isSecure = client->isSecure() ? True : False;
  2107. -
  2108. -   return callHook(i->second, HUB_IN, &data);
  2109. -}
  2110. -
  2111. -bool PluginManager::onOutgoingHubData(Client* client, const string& message) {
  2112. -   hookList::iterator i =  hooks.find(HOOK_PROTOCOL);
  2113. -   if(i == hooks.end()) return false;
  2114. -
  2115. -   ClientData data;
  2116. -   memset(&data, 0, sizeof(ClientData));
  2117. -
  2118. -   data.data = message.c_str();
  2119. -   data.url = client->getHubUrl().c_str();
  2120. -   data.ip = client->getIp().c_str();
  2121. -   data.object = client;
  2122. -   Util::toString(data.port) = client->getPort();
  2123. -   data.protocol = dynamic_cast<AdcHub*>(client) ? PROTOCOL_ADC : PROTOCOL_NMDC;
  2124. -   data.isOp = client->isOp() ? True : False;
  2125. -   data.isSecure = client->isSecure() ? True : False;
  2126. -
  2127. -   return callHook(i->second, HUB_OUT, &data);
  2128. -}
  2129. -
  2130. -bool PluginManager::onIncomingConnectionData(UserConnection* uc, const string& message) {
  2131. -   hookList::iterator i =  hooks.find(HOOK_PROTOCOL);
  2132. -   if(i == hooks.end()) return false;
  2133. -
  2134. -   ConnectionData data;
  2135. -   memset(&data, 0, sizeof(ConnectionData));
  2136. -
  2137. -   data.data = message.c_str();
  2138. -   data.ip = uc->getRemoteIp().c_str();
  2139. -   data.object = uc;
  2140. -   Util::toString(data.port) = uc->getPort();
  2141. -   data.protocol = (message[0] == '$') ? PROTOCOL_NMDC : PROTOCOL_ADC;
  2142. -   data.isOp = uc->isSet(UserConnection::FLAG_OP) ? True : False;
  2143. -   data.isSecure = uc->isSecure() ? True : False;
  2144. -
  2145. -   return callHook(i->second, CONN_IN, &data);
  2146. -}
  2147. -
  2148. -bool PluginManager::onOutgoingConnectionData(UserConnection* uc, const string& message) {
  2149. -   hookList::iterator i = hooks.find(HOOK_PROTOCOL);
  2150. -   if(i == hooks.end()) return false;
  2151. -
  2152. -   ConnectionData data;
  2153. -   memset(&data, 0, sizeof(ConnectionData));
  2154. -
  2155. -   data.data = message.c_str();
  2156. -   data.ip = uc->getRemoteIp().c_str();
  2157. -   data.object = uc;
  2158. -   Util::toString(data.port) = uc->getPort();
  2159. -   data.protocol = (message[0] == '$') ? PROTOCOL_NMDC : PROTOCOL_ADC;
  2160. -   data.isOp = uc->isSet(UserConnection::FLAG_OP) ? True : False;
  2161. -   data.isSecure = uc->isSecure() ? True : False;
  2162. -
  2163. -   return callHook(i->second, CONN_OUT, &data);
  2164. +   return false;
  2165.  }
  2166.  
  2167. -// Hook functions
  2168. -hookHandle PluginManager::createHook(HookID hookId, HookType hookType, DCHOOK defProc) {
  2169. -   Lock l((hookType == HOOK_EVENT) ? csHook : csCb);
  2170. +// Plugin Hook system
  2171. +PluginHook* PluginManager::createHook(const string& guid, DCHOOK defProc) {
  2172. +   Lock l(csHook);
  2173.  
  2174. -   hookList::iterator i = hooks.find(hookId);
  2175. +   auto i = hooks.find(guid);
  2176.     if(i != hooks.end()) return NULL;
  2177.  
  2178.     PluginHook* hook = new PluginHook();
  2179. -   hook->id = hookId;
  2180. -   hook->type = hookType;
  2181. +   hook->guid = guid;
  2182.     hook->defProc = defProc;
  2183. -   hooks[hookId] = hook;
  2184. +   hooks[guid] = hook;
  2185.     return hook;
  2186.  }
  2187.  
  2188. -void PluginManager::destroyHook(hookHandle hHook) {
  2189. -   PluginHook* hook = (PluginHook*)hHook;
  2190. -   hookList::iterator i;
  2191. -
  2192. -   Lock l((hook->type == HOOK_EVENT) ? csHook : csCb);
  2193. +bool PluginManager::destroyHook(PluginHook* hook) {
  2194. +   Lock l(csHook);
  2195.  
  2196. -   if((i = hooks.find(hook->id)) != hooks.end()) {
  2197. +   auto i = hooks.find(hook->guid);
  2198. +   if(i != hooks.end()) {
  2199.         for_each(hook->subscribers.begin(), hook->subscribers.end(), DeleteFunction());
  2200.         hook->subscribers.clear();
  2201.         hooks.erase(i);
  2202.         delete hook;
  2203. -   }
  2204. +       return true;
  2205. +   } else return false;
  2206.  }
  2207.  
  2208. -subsHandle PluginManager::setHook(HookID hookId, DCHOOK hookProc, void* pCommon) {
  2209. +HookSubscriber* PluginManager::bindHook(const string& guid, DCHOOK hookProc, void* pCommon) {
  2210. +   Lock l(csHook);
  2211. +
  2212.     PluginHook* hook;
  2213. -   hookList::iterator i = hooks.find(hookId);
  2214. +   auto i = hooks.find(guid);
  2215.  
  2216. -   // Handle "common" hooks
  2217.     if(i == hooks.end()) {
  2218. -       if(hookId < HOOK_USER) {
  2219. -           hook = (PluginHook*)createHook(hookId, HOOK_EVENT, NULL);
  2220. -           switch(hookId) {
  2221. -               case HOOK_TIMER: TimerManager::getInstance()->addListener(this); break;
  2222. -               case HOOK_HUBS: ClientManager::getInstance()->addListener(this); break;
  2223. -               case HOOK_QUEUE: QueueManager::getInstance()->addListener(this); break;
  2224. -               default: /* do nothing - except silence mingw */ break;
  2225. -           }
  2226. -       } else return NULL;
  2227. +       return NULL;
  2228.     } else hook = i->second;
  2229.  
  2230. -   Lock l((hook->type == HOOK_EVENT) ? csHook : csCb);
  2231. -
  2232.     HookSubscriber* subscribtion = new HookSubscriber();
  2233.     subscribtion->hookProc = hookProc;
  2234.     subscribtion->common = pCommon;
  2235. -   subscribtion->owner = hookId;
  2236. +   subscribtion->owner = hook->guid;
  2237.     hook->subscribers.push_back(subscribtion);
  2238.  
  2239.     return subscribtion;
  2240.  }
  2241.  
  2242. -bool PluginManager::callHook(PluginHook* hook, uint32_t eventId, dcptr_t pData) {
  2243. -   Lock l((hook->type == HOOK_EVENT) ? csHook : csCb);
  2244. +bool PluginManager::runHook(const string& guid, dcptr_t pObject, dcptr_t pData) {
  2245. +   Lock l(csHook);
  2246. +
  2247. +   PluginHook* hook;
  2248. +   auto i = hooks.find(guid);
  2249. +
  2250. +   if(i == hooks.end()) {
  2251. +       return false;
  2252. +   } else hook = i->second;
  2253.  
  2254.     Bool bBreak = False;
  2255.     Bool bRes = False;
  2256. -   for(PluginHook::subsList::const_iterator i = hook->subscribers.begin(); i != hook->subscribers.end(); ++i) {
  2257. +   for(auto i = hook->subscribers.cbegin(); i != hook->subscribers.cend(); ++i) {
  2258.         HookSubscriber* sub = *i;
  2259. -       switch(hook->type) {
  2260. -           case HOOK_CALLBACK:
  2261. -               bRes = (sub->common ? sub->hookProcCommonEx(eventId, pData, sub->common, &bBreak) : sub->hookProcEx(eventId, pData, &bBreak));
  2262. -               if(bBreak)
  2263. -                   return (bRes != False);
  2264. -               break;
  2265. -           case HOOK_EVENT:
  2266. -               if(sub->common ? sub->hookProcCommon(eventId, pData, sub->common) : sub->hookProc(eventId, pData))
  2267. -                   bRes = True;
  2268. -               break;
  2269. -           default:
  2270. -               dcassert(0);
  2271. -       }
  2272. +       if(sub->common ? sub->hookProcCommon(pObject, pData, sub->common, &bBreak) : sub->hookProc(pObject, pData, &bBreak))
  2273. +           bRes = True;
  2274. +       if(bBreak) return (bRes != False);
  2275.     }
  2276.  
  2277. -   // Call default hook procedure for all unused hooks and overloadables
  2278. -   if(hook->defProc && (hook->subscribers.empty() || hook->type == HOOK_CALLBACK)) {
  2279. -       if(hook->defProc(eventId, pData))
  2280. +   // Call default hook procedure for all unused hooks
  2281. +   if(hook->defProc && hook->subscribers.empty()) {
  2282. +       if(hook->defProc(pObject, pData, &bBreak))
  2283.             bRes = True;
  2284.     }
  2285.  
  2286.     return (bRes != False);
  2287.  }
  2288.  
  2289. -size_t PluginManager::unHook(subsHandle hHook) {
  2290. -   if(hHook == NULL)
  2291. +size_t PluginManager::releaseHook(HookSubscriber* subscription) {
  2292. +   Lock l(csHook);
  2293. +
  2294. +   if(subscription == NULL)
  2295.         return 0;
  2296.  
  2297. -   hookList::iterator i;
  2298.     PluginHook* hook = NULL;
  2299. -   HookSubscriber* subscription = reinterpret_cast<HookSubscriber*>(hHook);
  2300.  
  2301. -   if((i = hooks.find(subscription->owner)) != hooks.end())
  2302. +   auto i = hooks.find(subscription->owner);
  2303. +   if(i != hooks.end())
  2304.         hook = i->second;
  2305.  
  2306.     if(hook == NULL)
  2307.         return 0;
  2308.  
  2309. -   Lock l((hook->type == HOOK_EVENT) ? csHook : csCb);
  2310. -
  2311.     hook->subscribers.erase(std::remove(hook->subscribers.begin(), hook->subscribers.end(), subscription), hook->subscribers.end());
  2312.     delete subscription;
  2313.  
  2314. -   // Handle "common" hooks
  2315. -   if(hook->subscribers.empty() && hook->id < HOOK_USER) {
  2316. -       switch(hook->id) {
  2317. -           case HOOK_TIMER: TimerManager::getInstance()->removeListener(this); break;
  2318. -           case HOOK_HUBS: ClientManager::getInstance()->removeListener(this); break;
  2319. -           case HOOK_QUEUE: QueueManager::getInstance()->removeListener(this); break;
  2320. -           default: /* do nothing - except silence mingw */ break;
  2321. -       }
  2322. -       hooks.erase(i);
  2323. -       delete hook; return 0;
  2324. -   }
  2325. -
  2326.     return hook->subscribers.size();
  2327.  }
  2328.  
  2329. -// Listeners
  2330. -void PluginManager::on(TimerManagerListener::Second, uint64_t ticks) throw() {
  2331. -   callHook(hooks.find(HOOK_TIMER)->second, TIMER_SECOND, &ticks);
  2332. -}
  2333. -
  2334. -void PluginManager::on(TimerManagerListener::Minute, uint64_t ticks) throw() {
  2335. -   callHook(hooks.find(HOOK_TIMER)->second, TIMER_MINUTE, &ticks);
  2336. +// Plugin configuration
  2337. +void PluginManager::setPluginSetting(const string& pluginName, const string& setting, const string& value) {
  2338. +   settings[pluginName][setting] = value;
  2339. +}
  2340. +
  2341. +const string& PluginManager::getPluginSetting(const string& pluginName, const string& setting) {
  2342. +   auto i = settings.find(pluginName);
  2343. +   if(i != settings.end()) {
  2344. +       auto j = i->second.find(setting);
  2345. +       if(j != i->second.end())
  2346. +           return j->second;
  2347. +   }
  2348. +   return Util::emptyString;
  2349. +}
  2350. +
  2351. +void PluginManager::removePluginSetting(const string& pluginName, const string& setting) {
  2352. +   auto i = settings.find(pluginName);
  2353. +   if(i != settings.end()) {
  2354. +       auto j = i->second.find(setting);
  2355. +       if(j != i->second.end())
  2356. +           i->second.erase(j);
  2357. +   }
  2358.  }
  2359.  
  2360. -void PluginManager::on(ClientManagerListener::ClientDisconnected, Client* aClient) throw() {
  2361. -   ClientData data;
  2362. -   memset(&data, 0, sizeof(ClientData));
  2363. -
  2364. -   data.url = aClient->getHubUrl().c_str();
  2365. -   data.object = aClient;
  2366. -   data.protocol = dynamic_cast<AdcHub*>(aClient) ? PROTOCOL_ADC : PROTOCOL_NMDC;
  2367. -
  2368. -   callHook(hooks.find(HOOK_HUBS)->second, HUB_OFFLINE, &data);
  2369. +// Listeners
  2370. +void PluginManager::on(ClientManagerListener::ClientConnected, Client* aClient) noexcept {
  2371. +   runHook(HOOK_HUB_ONLINE, aClient);
  2372.  }
  2373.  
  2374. -void PluginManager::on(ClientManagerListener::ClientConnected, Client* aClient) throw() {
  2375. -   ClientData data;
  2376. -   memset(&data, 0, sizeof(ClientData));
  2377. -
  2378. -   data.url = aClient->getHubUrl().c_str();
  2379. -   data.ip = aClient->getIp().c_str();
  2380. -   data.object = aClient;
  2381. -   Util::toString(data.port) = aClient->getPort();
  2382. -   data.protocol = dynamic_cast<AdcHub*>(aClient) ? PROTOCOL_ADC : PROTOCOL_NMDC;
  2383. -   data.isOp = aClient->isOp() ? True : False;
  2384. -   data.isSecure = aClient->isSecure() ? True : False;
  2385. -
  2386. -   callHook(hooks.find(HOOK_HUBS)->second, HUB_ONLINE, &data);
  2387. +void PluginManager::on(ClientManagerListener::ClientDisconnected, Client* aClient) noexcept {
  2388. +   runHook(HOOK_HUB_OFFLINE, aClient);
  2389.  }
  2390.  
  2391. -void PluginManager::on(QueueManagerListener::Added, QueueItem* qi) throw() {
  2392. -   QueueData data;
  2393. -   memset(&data, 0, sizeof(QueueData));
  2394. -
  2395. -   data.file = qi->getTargetFileName().c_str();
  2396. -   data.target = qi->getTarget().c_str();
  2397. -   data.location = qi->isFinished() ? data.target : qi->getTempTarget().c_str();
  2398. -   data.hash = qi->getTTH().data;
  2399. -   data.object = qi;
  2400. -   data.size = qi->getSize();
  2401. -   data.isFileList = qi->isSet(QueueItem::FLAG_USER_LIST) ? True : False;
  2402. -
  2403. -   callHook(hooks.find(HOOK_QUEUE)->second, QUEUE_ADD, &data);
  2404. +void PluginManager::on(QueueManagerListener::Added, QueueItem* qi) noexcept {
  2405. +   runHook(HOOK_QUEUE_ADD, qi);
  2406.  }
  2407.  
  2408. -void PluginManager::on(QueueManagerListener::Moved, QueueItem* qi, const string&) throw() {
  2409. -   QueueData data;
  2410. -   memset(&data, 0, sizeof(QueueData));
  2411. -
  2412. -   data.file = qi->getTargetFileName().c_str();
  2413. -   data.target = qi->getTarget().c_str();
  2414. -   data.location = qi->isFinished() ? data.target : qi->getTempTarget().c_str();
  2415. -   data.hash = qi->getTTH().data;
  2416. -   data.object = qi;
  2417. -   data.size = qi->getSize();
  2418. -   data.isFileList = qi->isSet(QueueItem::FLAG_USER_LIST) ? True : False;
  2419. -
  2420. -   callHook(hooks.find(HOOK_QUEUE)->second, QUEUE_MOVE, &data);
  2421. +void PluginManager::on(QueueManagerListener::Moved, QueueItem* qi, const string& /*aSource*/) noexcept {
  2422. +   runHook(HOOK_QUEUE_MOVE, qi);
  2423.  }
  2424.  
  2425. -void PluginManager::on(QueueManagerListener::Removed, QueueItem* qi) throw() {
  2426. -   QueueData data;
  2427. -   memset(&data, 0, sizeof(QueueData));
  2428. -
  2429. -   data.file = qi->getTargetFileName().c_str();
  2430. -   data.target = qi->getTarget().c_str();
  2431. -   data.location = qi->isFinished() ? data.target : qi->getTempTarget().c_str();
  2432. -   data.hash = qi->getTTH().data;
  2433. -   data.object = qi;
  2434. -   data.size = qi->getSize();
  2435. -   data.isFileList = qi->isSet(QueueItem::FLAG_USER_LIST) ? True : False;
  2436. -
  2437. -   callHook(hooks.find(HOOK_QUEUE)->second, QUEUE_REMOVE, &data);
  2438. +void PluginManager::on(QueueManagerListener::Removed, QueueItem* qi) noexcept {
  2439. +   runHook(HOOK_QUEUE_REMOVE, qi);
  2440.  }
  2441.  
  2442. -// Finished items are no longer quaranteed to be removed right away
  2443. -void PluginManager::on(QueueManagerListener::Finished, QueueItem* qi, const string&, int64_t) throw() {
  2444. -   QueueData data;
  2445. -   memset(&data, 0, sizeof(QueueData));
  2446. -
  2447. -   data.file = qi->getTargetFileName().c_str();
  2448. -   data.target = qi->getTarget().c_str();
  2449. -   data.location = qi->isFinished() ? data.target : qi->getTempTarget().c_str();
  2450. -   data.hash = qi->getTTH().data;
  2451. -   data.object = qi;
  2452. -   data.size = qi->getSize();
  2453. -   data.isFileList = qi->isSet(QueueItem::FLAG_USER_LIST) ? True : False;
  2454. -
  2455. -   callHook(hooks.find(HOOK_QUEUE)->second, QUEUE_FINISHED, &data);
  2456. +void PluginManager::on(QueueManagerListener::Finished, QueueItem* qi, const string& /*dir*/, int64_t /*speed*/) noexcept {
  2457. +   runHook(HOOK_QUEUE_FINISHED, qi);
  2458.  }
  2459.  
  2460.  // Load / Save settings
  2461. -void PluginManager::on(SettingsManagerListener::Load, SimpleXML& /*xml*/) throw() {
  2462. +void PluginManager::on(SettingsManagerListener::Load, SimpleXML& /*xml*/) noexcept {
  2463.     Lock l(cs);
  2464.  
  2465.     try {
  2466. @@ -680,9 +442,9 @@
  2467.             while(xml.findChild("Plugin")) {
  2468.                 const string& pluginGuid = xml.getChildAttrib("Guid");
  2469.                 xml.stepIn();
  2470. -               StringMap settings = xml.getCurrentChildren();
  2471. -               for(StringMapIter j = settings.begin(); j != settings.end(); ++j) {
  2472. -                   setSetting(pluginGuid, j->first, j->second);
  2473. +               auto settings = xml.getCurrentChildren();
  2474. +               for(auto j = settings.cbegin(); j != settings.cend(); ++j) {
  2475. +                   setPluginSetting(pluginGuid, j->first, j->second);
  2476.                 }
  2477.                 xml.stepOut();
  2478.             }
  2479. @@ -693,17 +455,17 @@
  2480.     }
  2481.   }
  2482.  
  2483. -void PluginManager::on(SettingsManagerListener::Save, SimpleXML& /*xml*/) throw() {
  2484. +void PluginManager::on(SettingsManagerListener::Save, SimpleXML& /*xml*/) noexcept {
  2485.     Lock l(cs);
  2486.  
  2487.     try {
  2488.         SimpleXML xml;
  2489.         xml.addTag("Plugins");
  2490.         xml.stepIn();
  2491. -       for(settingsMap::const_iterator i = settings.begin(); i != settings.end(); ++i){
  2492. +       for(auto i = settings.cbegin(); i != settings.cend(); ++i){
  2493.             xml.addTag("Plugin");
  2494.             xml.stepIn();
  2495. -           for(StringMap::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
  2496. +           for(auto j = i->second.cbegin(); j != i->second.cend(); ++j) {
  2497.                 xml.addTag(j->first, j->second);           
  2498.             }
  2499.             xml.stepOut();
  2500. @@ -727,5 +489,5 @@
  2501.  
  2502.  /**
  2503.   * @file
  2504. - * $Id: PluginManager.cpp 712 2010-09-07 14:46:45Z crise $
  2505. + * $Id: PluginManager.cpp 1217 2012-01-08 16:15:57Z crise $
  2506.   */
  2507. --- PluginManager.h Tue Jan 20 00:26:36 1970
  2508. +++ PluginManager.h Tue Jan 20 00:26:36 1970
  2509. @@ -1,5 +1,5 @@
  2510.  /*
  2511. - * Copyright (C) 2001-2010 Jacek Sieka, arnetheduck on gmail point com
  2512. + * Copyright (C) 2001-2012 Jacek Sieka, arnetheduck on gmail point com
  2513.   *
  2514.   * This program is free software; you can redistribute it and/or modify
  2515.   * it under the terms of the GNU General Public License as published by
  2516. @@ -19,19 +19,15 @@
  2517.  #ifndef DCPLUSPLUS_DCPP_PLUGIN_MANAGER_H
  2518.  #define DCPLUSPLUS_DCPP_PLUGIN_MANAGER_H
  2519.  
  2520. -#include <vector>
  2521. -#include <algorithm>
  2522. -
  2523. -// for tstring
  2524. -#include "DCPlusPlus.h"
  2525. +#include "typedefs.h"
  2526.  
  2527.  #include "Singleton.h"
  2528.  #include "SettingsManager.h"
  2529.  #include "TimerManager.h"
  2530. -#include "ClientManager.h"
  2531. -#include "QueueManager.h"
  2532.  #include "LogManager.h"
  2533. -#include "UserConnection.h"
  2534. +
  2535. +#include "QueueManagerListener.h"
  2536. +#include "ClientManagerListener.h"
  2537.  
  2538.  #include "PluginDefs.h"
  2539.  #include "PluginApiImpl.h"
  2540. @@ -44,28 +40,35 @@
  2541.  
  2542.  namespace dcpp {
  2543.  
  2544. -using std::vector;
  2545. -using std::swap;
  2546. +// Internal types to plugin types
  2547. +// - Grants plugin data types same scope as their equivalent internal types
  2548. +template<typename PluginType>
  2549. +class PluginEntity
  2550. +{
  2551. +public:
  2552. +   PluginEntity() { pod.object = NULL; }
  2553. +   virtual ~PluginEntity() { }
  2554. +
  2555. +   virtual PluginType* getPluginObject() noexcept = 0;
  2556. +
  2557. +protected:
  2558. +   PluginType pod;
  2559. +};
  2560.  
  2561.  // Represents a plugin in hook context
  2562.  struct HookSubscriber {
  2563.     union {
  2564.         DCHOOK hookProc;
  2565. -       DCHOOKEX hookProcEx;
  2566.         DCHOOKCOMMON hookProcCommon;
  2567. -       DCHOOKCOMMONEX hookProcCommonEx;
  2568.     };
  2569.     void* common;
  2570. -   HookID owner;
  2571. +   string owner;
  2572.  };
  2573.  
  2574. -// Hookable event (or event group)
  2575. +// Hookable event
  2576.  struct PluginHook {
  2577. -   typedef vector<HookSubscriber*> subsList;
  2578. -
  2579. -   HookID id;
  2580. -   HookType type;
  2581. -   subsList subscribers;
  2582. +   string guid;
  2583. +   vector<HookSubscriber*> subscribers;
  2584.     DCHOOK defProc;
  2585.  };
  2586.  
  2587. @@ -73,14 +76,14 @@
  2588.  class PluginInfo : private boost::noncopyable
  2589.  {
  2590.  public:
  2591. -   typedef DCHOOK  (DCAPI *PLUGIN_INIT)(MetaDataPtr info);
  2592. +   typedef DCMAIN  (DCAPI *PLUGIN_INIT)(MetaDataPtr info);
  2593.  
  2594. -   PluginInfo(const string& aFile, pluginHandle hInst, MetaData aInfo, DCHOOK aHook)
  2595. -       : mainHook(aHook), info(aInfo), file(aFile), handle(hInst) { };
  2596. +   PluginInfo(const string& aFile, pluginHandle hInst, MetaData aInfo, DCMAIN aMain)
  2597. +       : dcMain(aMain), info(aInfo), file(aFile), handle(hInst) { };
  2598.  
  2599.     ~PluginInfo();
  2600.  
  2601. -   DCHOOK mainHook;
  2602. +   DCMAIN dcMain;
  2603.     const MetaData& getInfo() const { return info; }
  2604.     const string& getFile() const { return file; }
  2605.  
  2606. @@ -96,12 +99,12 @@
  2607.  public:
  2608.     typedef vector<PluginInfo*> pluginList;
  2609.  
  2610. -   PluginManager() : shutdown(false) {
  2611. -       memset(&dcCore, 0, sizeof(DCCore));
  2612. +   PluginManager() : shutdown(false), secNum(Util::rand()) {
  2613. +       memzero(&dcCore, sizeof(DCCore));
  2614.         SettingsManager::getInstance()->addListener(this);
  2615.     }
  2616.  
  2617. -   ~PluginManager() throw() {
  2618. +   ~PluginManager() {
  2619.         SettingsManager::getInstance()->removeListener(this);
  2620.     }
  2621.  
  2622. @@ -118,33 +121,42 @@
  2623.     const pluginList& getPluginList() { Lock l(cs); return plugins; };
  2624.     const PluginInfo* getPlugin(uint32_t index) { Lock l(cs); return plugins[index]; }
  2625.  
  2626. +   DCCorePtr getCore() { return &dcCore; }
  2627. +
  2628.     // Functions that call the plugin
  2629.     bool onChatDisplay(Client* client, tstring& line);
  2630.     bool onChatCommand(Client* client, const string& line);
  2631.     bool onChatCommandPM(const HintedUser& user, const string& line, bool isPriv);
  2632. -   bool onOutgoingChat(Client* client, const string& message);
  2633. -   bool onOutgoingPM(const OnlineUser& user, const string& message);
  2634. -   bool onIncomingChat(Client* client, const string& message);
  2635. -   bool onIncomingPM(const OnlineUser* user, const string& message);
  2636. -   bool onIncomingHubData(Client* client, const string& message);
  2637. -   bool onOutgoingHubData(Client* client, const string& message);
  2638. -   bool onIncomingConnectionData(UserConnection* uc, const string& message);
  2639. -   bool onOutgoingConnectionData(UserConnection* uc, const string& message);
  2640. -
  2641. -   bool callHook(HookID hookId, uint32_t eventId, dcptr_t pData) {
  2642. -       hookList::iterator i = hooks.find(hookId);
  2643. -       if(i == hooks.end()) return false;
  2644. -       return callHook(i->second, eventId, pData);
  2645. +
  2646. +   template<class T>
  2647. +   bool runHook(const string& guid, PluginEntity<T>* object) {
  2648. +       return runHook(guid, object->getPluginObject(), NULL);
  2649.     }
  2650.  
  2651. -private:
  2652. -   friend class PluginApiImpl;
  2653. +   template<class T>
  2654. +   bool runHook(const string& guid, PluginEntity<T>* object, const string& data) {
  2655. +       return runHook(guid, object->getPluginObject(), (dcptr_t)data.c_str());
  2656. +   }
  2657. +
  2658. +   // Plugin interface registry
  2659. +   intfHandle registerInterface(const string& guid, dcptr_t funcs);
  2660. +   dcptr_t queryInterface(const string& guid);
  2661. +   bool releaseInterface(intfHandle hInterface);
  2662. +
  2663. +   // Plugin Hook system
  2664. +   PluginHook* createHook(const string& guid, DCHOOK defProc);
  2665. +   bool destroyHook(PluginHook* hook);
  2666. +
  2667. +   HookSubscriber* bindHook(const string& guid, DCHOOK hookProc, void* pCommon);
  2668. +   bool runHook(const string& guid, dcptr_t pObject, dcptr_t pData);
  2669. +   size_t releaseHook(HookSubscriber* subscription);
  2670.  
  2671. -   typedef vector<pluginHandle> inactiveList;
  2672. -   typedef map<HookID, PluginHook*> hookList;
  2673. -   typedef map<string, StringMap> settingsMap;
  2674. -   typedef map<string, uint32_t> messageMap;
  2675. +   // Plugin configuration
  2676. +   void setPluginSetting(const string& pluginName, const string& setting, const string& value);
  2677. +   const string& getPluginSetting(const string& pluginName, const string& setting);
  2678. +   void removePluginSetting(const string& pluginName, const string& setting);
  2679.  
  2680. +private:
  2681.     // Plugin finder
  2682.     struct PluginCompare {
  2683.         PluginCompare(const char* guid) : tmpGuid(guid) { }
  2684. @@ -157,89 +169,34 @@
  2685.     // Check if plugin can be loaded
  2686.     bool checkPlugin(const MetaData& info);
  2687.  
  2688. -   // Hook functions
  2689. -   hookHandle createHook(HookID hookId, HookType hookType, DCHOOK defProc);
  2690. -   void destroyHook(hookHandle hHook);
  2691. -
  2692. -   subsHandle setHook(HookID hookId, DCHOOK hookProc, void* pCommon);
  2693. -   bool callHook(PluginHook* hook, uint32_t eventId, dcptr_t pData);
  2694. -   size_t unHook(subsHandle hHook);
  2695. -
  2696. -   // Settings management
  2697. -   void setSetting(const string& pluginName, const string& setting, const string& value) {
  2698. -       settings[pluginName][setting] = value;
  2699. -   }
  2700. -
  2701. -   const string& getSetting(const string& pluginName, const string& setting) {
  2702. -       settingsMap::const_iterator i;
  2703. -       if((i = settings.find(pluginName)) != settings.end()) {
  2704. -           StringMap::const_iterator j;
  2705. -           if((j = i->second.find(setting)) != i->second.end())
  2706. -               return j->second;
  2707. -       }
  2708. -       return Util::emptyString;
  2709. -   }
  2710. -
  2711. -   void removeSetting(const string& pluginName, const string& setting) {
  2712. -       settingsMap::iterator i;
  2713. -       if((i = settings.find(pluginName)) != settings.end()) {
  2714. -           StringMap::iterator j;
  2715. -           if((j = i->second.find(setting)) != i->second.end())
  2716. -               i->second.erase(j);
  2717. -       }
  2718. -   }
  2719. -
  2720. -   // Message register (to avoid collisions with plugin defined messages)
  2721. -   uint32_t registerMessage(HookType type, const string& messageName) {
  2722. -       messageMap::const_iterator i;
  2723. -       if((i = messages.find(messageName)) == messages.end()) {
  2724. -           messages[messageName] = ++(msgMaps[type]);
  2725. -           return msgMaps[type];
  2726. -       } else return i->second;
  2727. -   }
  2728. +   // Listeners
  2729. +   void on(TimerManagerListener::Second, uint64_t ticks) noexcept { runHook(HOOK_TIMER_SECOND, NULL, &ticks); }
  2730. +   void on(TimerManagerListener::Minute, uint64_t ticks) noexcept { runHook(HOOK_TIMER_MINUTE, NULL, &ticks); }
  2731.  
  2732. -   uint32_t registerRange(HookType type, const string& messageName, uint32_t count) {
  2733. -       messageMap::const_iterator i;
  2734. -       if((i = messages.find(messageName)) == messages.end()) {
  2735. -           messages[messageName] = msgMaps[type] + 1;
  2736. -           msgMaps[type] += count;
  2737. -           return (msgMaps[type] - count) + 1;
  2738. -       } else return i->second;
  2739. -   }
  2740. +   void on(ClientManagerListener::ClientConnected, Client* aClient) noexcept;
  2741. +   void on(ClientManagerListener::ClientDisconnected, Client* aClient) noexcept;
  2742.  
  2743. -   uint32_t seekMessage(const string& messageName) {
  2744. -       messageMap::const_iterator i;
  2745. -       if((i = messages.find(messageName)) != messages.end())
  2746. -           return i->second;
  2747. -       return 0; // always reserved
  2748. -   }
  2749. +   void on(QueueManagerListener::Added, QueueItem* qi) noexcept;
  2750. +   void on(QueueManagerListener::Moved, QueueItem* qi, const string& /*aSource*/) noexcept;
  2751. +   void on(QueueManagerListener::Removed, QueueItem* qi) noexcept;
  2752. +   void on(QueueManagerListener::Finished, QueueItem* qi, const string& /*dir*/, int64_t /*speed*/) noexcept;
  2753.  
  2754. -   // Listeners
  2755. -   void on(TimerManagerListener::Second, uint64_t ticks) throw();
  2756. -   void on(TimerManagerListener::Minute, uint64_t ticks) throw();
  2757. -   void on(ClientManagerListener::ClientConnected, Client* aClient) throw();
  2758. -   void on(ClientManagerListener::ClientDisconnected, Client* aClient) throw();
  2759. -   void on(QueueManagerListener::Added, QueueItem* qi) throw();
  2760. -   void on(QueueManagerListener::Moved, QueueItem* qi, const string&) throw();
  2761. -   void on(QueueManagerListener::Removed, QueueItem* qi) throw();
  2762. -   void on(QueueManagerListener::Finished, QueueItem* qi, const string&, int64_t) throw();
  2763. +   void on(SettingsManagerListener::Load, SimpleXML& /*xml*/) noexcept;
  2764. +   void on(SettingsManagerListener::Save, SimpleXML& /*xml*/) noexcept;
  2765.  
  2766. -   void on(SettingsManagerListener::Load, SimpleXML& /*xml*/) throw();
  2767. -   void on(SettingsManagerListener::Save, SimpleXML& /*xml*/) throw();
  2768. +   pluginList plugins;
  2769. +   vector<pluginHandle> inactive;
  2770.  
  2771. -   // Tracks plugin reserved messages
  2772. -   static uint32_t msgMaps[3];
  2773. +   map<string, PluginHook*> hooks;
  2774. +   map<string, dcptr_t> interfaces;
  2775.  
  2776. -   pluginList plugins;
  2777. -   inactiveList inactive;
  2778. -   hookList hooks;
  2779. -   settingsMap settings;
  2780. -   messageMap messages;
  2781. +   map<string, StringMap> settings;
  2782.  
  2783.     DCCore dcCore;
  2784. -   CriticalSection cs, csHook, csCb;
  2785. -   hookHandle coreHook;
  2786. +   CriticalSection cs, csHook;
  2787.     bool shutdown;
  2788. +
  2789. +   uintptr_t secNum;
  2790.  };
  2791.  
  2792.  } // namespace dcpp
  2793. @@ -248,5 +205,5 @@
  2794.  
  2795.  /**
  2796.   * @file
  2797. - * $Id: PluginManager.h 707 2010-09-03 15:40:16Z crise $
  2798. + * $Id: PluginManager.h 1217 2012-01-08 16:15:57Z crise $
  2799.   */
  2800. --- QueueItem.h Tue Jan 20 00:26:36 1970
  2801. +++ QueueItem.h Tue Jan 20 00:26:36 1970
  2802. @@ -38,7 +38,7 @@
  2803.  
  2804.  class QueueManager;
  2805.  
  2806. -class QueueItem : public Flags, public FastAlloc<QueueItem> {
  2807. +class QueueItem : public Flags, public FastAlloc<QueueItem>, public PluginEntity<QueueData> {
  2808.  public:
  2809.     typedef unordered_map<string*, QueueItemPtr, noCaseStringHash, noCaseStringEq> StringMap;
  2810.  
  2811. @@ -179,6 +179,22 @@
  2812.  
  2813.     const string& getTempTarget();
  2814.     void setTempTarget(const string& aTempTarget) { tempTarget = aTempTarget; }
  2815. +
  2816. +   QueueData* getPluginObject() noexcept {
  2817. +       pod.file = getTarget().c_str(); // yes, this member implemented like this is useless
  2818. +       pod.target = getTarget().c_str();
  2819. +       pod.location = isFinished() ? pod.target : getTempTarget().c_str();
  2820. +
  2821. +       if(pod.object)
  2822. +           return &pod;
  2823. +
  2824. +       pod.hash = tthRoot.data;
  2825. +       pod.object = this;
  2826. +       pod.size = size;
  2827. +       pod.isFileList = isSet(QueueItem::FLAG_USER_LIST) ? True : False;
  2828. +
  2829. +       return &pod;
  2830. +   }
  2831.  
  2832.     GETSET(SegmentSet, done, Done);
  2833.     GETSET(DownloadList, downloads, Downloads);
  2834. --- User.cpp    Tue Jan 20 00:26:36 1970
  2835. +++ User.cpp    Tue Jan 20 00:26:36 1970
  2836. @@ -33,6 +33,26 @@
  2837.  
  2838.  }
  2839.  
  2840. +UserData* OnlineUser::getPluginObject() noexcept {
  2841. +   pod.isOp = getIdentity().isOp() ? True : False;
  2842. +   pod.hubHint = getClient().getHubUrl().c_str();
  2843. +
  2844. +   if(pod.object)
  2845. +       return &pod;
  2846. +
  2847. +   pod.cid = getUser()->getCID().data();
  2848. +   pod.object = this;
  2849. +   if(getUser()->isNMDC()) {
  2850. +       pod.protocol = PROTOCOL_NMDC;
  2851. +       strncpy(pod.uid.nick, getIdentity().getNick().c_str(), 35);
  2852. +   } else {
  2853. +       pod.protocol = PROTOCOL_ADC;
  2854. +       pod.uid.sid = getIdentity().getSID();
  2855. +   }
  2856. +
  2857. +   return &pod;
  2858. +}
  2859. +
  2860.  bool Identity::isTcpActive() const {
  2861.     return isTcp4Active() || isTcp6Active();
  2862.  }
  2863. --- UserConnection.cpp  Tue Jan 20 00:26:36 1970
  2864. +++ UserConnection.cpp  Tue Jan 20 00:26:36 1970
  2865. @@ -56,7 +56,10 @@
  2866.         return;
  2867.     }
  2868.  
  2869. -   if(PluginManager::getInstance()->onIncomingConnectionData(this, aLine))
  2870. +   if(aLine[0] == '$')
  2871. +       setFlag(FLAG_NMDC);
  2872. +
  2873. +   if(PluginManager::getInstance()->runHook(HOOK_NETWORK_CONN_IN, this, aLine))
  2874.         return;
  2875.  
  2876.     if(aLine[0] == 'C' && !isSet(FLAG_NMDC)) {
  2877. @@ -66,9 +69,7 @@
  2878.         }
  2879.         dispatch(aLine);
  2880.         return;
  2881. -   } else if(aLine[0] == '$') {
  2882. -       setFlag(FLAG_NMDC);
  2883. -   } else {
  2884. +   } else if(!isSet(FLAG_NMDC)) {
  2885.         fire(UserConnectionListener::ProtocolError(), this, _("Invalid data"));
  2886.         return;
  2887.     }
  2888. @@ -267,11 +268,12 @@
  2889.  }
  2890.  
  2891.  void UserConnection::send(const string& aString) {
  2892. -       if(PluginManager::getInstance()->onOutgoingConnectionData(this, aString))
  2893. -           return;
  2894. +   if(PluginManager::getInstance()->runHook(HOOK_NETWORK_CONN_OUT, this, aString))
  2895. +       return;
  2896. +
  2897. +   lastActivity = GET_TICK();
  2898. +   COMMAND_DEBUG(aString, DebugManager::CLIENT_OUT, getRemoteIp());
  2899. +   socket->write(aString);
  2900. +}
  2901.  
  2902. -       lastActivity = GET_TICK();
  2903. -       COMMAND_DEBUG(aString, DebugManager::CLIENT_OUT, getRemoteIp());
  2904. -       socket->write(aString);
  2905. -   }
  2906.  } // namespace dcpp
  2907. --- UserConnection.h    Tue Jan 20 00:26:36 1970
  2908. +++ UserConnection.h    Tue Jan 20 00:26:36 1970
  2909. @@ -33,7 +33,7 @@
  2910.  
  2911.  namespace dcpp {
  2912.  
  2913. -class UserConnection : public Speaker<UserConnectionListener>,
  2914. +class UserConnection : public PluginEntity<ConnectionData>,  public Speaker<UserConnectionListener>,
  2915.     private BufferedSocketListener, public Flags, private CommandHandler<UserConnection>,
  2916.     private boost::noncopyable
  2917.  {
  2918. @@ -193,6 +193,21 @@
  2919.     GETSET(States, state, State);
  2920.     GETSET(uint64_t, lastActivity, LastActivity);
  2921.     GETSET(double, speed, Speed);
  2922. +
  2923. +   ConnectionData* getPluginObject() noexcept {
  2924. +       if(pod.object)
  2925. +           return &pod;
  2926. +
  2927. +       pod.ip = getRemoteIp().c_str();
  2928. +       pod.object = this;
  2929. +       pod.port = Util::toInt(getPort());
  2930. +       pod.protocol = isSet(UserConnection::FLAG_NMDC) ? PROTOCOL_NMDC : PROTOCOL_ADC;
  2931. +       pod.isOp = isSet(UserConnection::FLAG_OP) ? True : False;
  2932. +       pod.isSecure = isSecure() ? True : False;
  2933. +
  2934. +       return &pod;
  2935. +   }
  2936. +
  2937.  private:
  2938.     int64_t chunkSize;
  2939.     BufferedSocket* socket;
Advertisement
Add Comment
Please, Sign In to add comment