← Back to team overview

linuxdcpp-team team mailing list archive

[Merge] lp:~klondike/adchpp/adchpp into lp:adchpp

 

klondike has proposed merging lp:~klondike/adchpp/adchpp into lp:adchpp.

Requested reviews:
  Dcplusplus-team (dcplusplus-team)
Related bugs:
  Bug #1128591 in ADCH++: "+regnick is broken on trunk"
  https://bugs.launchpad.net/adchpp/+bug/1128591
  Bug #1130835 in ADCH++: "Allow TTH searchs on the bloom plugin to other plugins"
  https://bugs.launchpad.net/adchpp/+bug/1130835
  Bug #1131570 in ADCH++: "adchpp::Core *getCurrentCore in swig/lua.i is broken because it shouldn't use fixed indices"
  https://bugs.launchpad.net/adchpp/+bug/1131570
  Bug #1131962 in ADCH++: "Some local variables aren't marked as such"
  https://bugs.launchpad.net/adchpp/+bug/1131962
  Bug #1131963 in ADCH++: "The function add_stats(stat) should be exported"
  https://bugs.launchpad.net/adchpp/+bug/1131963

For more details, see:
https://code.launchpad.net/~klondike/adchpp/adchpp/+merge/150163

This branch includes fixes for various bugs which are linked to the branch itself.
-- 
https://code.launchpad.net/~klondike/adchpp/adchpp/+merge/150163
Your team Dcplusplus-team is requested to review the proposed merge of lp:~klondike/adchpp/adchpp into lp:adchpp.
=== modified file 'SConstruct'
--- SConstruct	2012-09-25 17:35:20 +0000
+++ SConstruct	2013-02-22 23:03:25 +0000
@@ -45,7 +45,7 @@
 }
 
 gcc_link_flags = {
-	'common' : ['-g', '-Wl,--no-undefined', '-time'],
+	'common' : ['-g', '$UNDEF', '-time'],
 	'debug' : [],
 	'release' : ['-O3']				
 }
@@ -179,6 +179,7 @@
 
 env.Append(LINKFLAGS = link_flags[env['mode']])
 env.Append(LINKFLAGS = link_flags['common'])
+env.Append(UNDEF = '-Wl,--no-undefined')
 
 if dev.is_win32():
 	env.Append(LIBS = ['ws2_32', 'mswsock'])

=== modified file 'plugins/Bloom/src/BloomManager.cpp'
--- plugins/Bloom/src/BloomManager.cpp	2013-01-18 21:41:53 +0000
+++ plugins/Bloom/src/BloomManager.cpp	2013-02-22 23:03:25 +0000
@@ -58,6 +58,27 @@
 	statsConn = manage(pm.onCommand("stats", std::bind(&BloomManager::onStats, this, _1)));
 }
 
+bool BloomManager::hasBloom(Entity& c) const {
+	return c.getPluginData(bloomHandle);
+}
+
+bool BloomManager::hasTTH(Entity& c,const TTHValue& tth) const {
+	HashBloom* bloom = reinterpret_cast<HashBloom*>(c.getPluginData(bloomHandle));
+	return !bloom || bloom->match(tth);
+}
+
+int64_t BloomManager::getSearches() const {
+	return searches;
+}
+
+int64_t BloomManager::getTTHSearches() const {
+	return tthSearches;
+}
+
+int64_t BloomManager::getStoppedSearches() const {
+	return stopped;
+}
+
 BloomManager::~BloomManager() {
 	LOG(className, "Shutting down");
 }
@@ -145,8 +166,7 @@
 		string tmp;
 		if(cmd.getParam("TR", 0, tmp)) {
 			tthSearches++;
-			HashBloom* bloom = reinterpret_cast<HashBloom*>(c.getPluginData(bloomHandle));
-			if((bloom && !bloom->match(TTHValue(tmp))) || !adchpp::Util::toInt(c.getField("SF"))) {
+			if(!hasTTH(c,TTHValue(tmp)) || !adchpp::Util::toInt(c.getField("SF"))) {
 				ok = false;
 				stopped++;
 			}

=== modified file 'plugins/Bloom/src/BloomManager.h'
--- plugins/Bloom/src/BloomManager.h	2013-01-18 21:41:53 +0000
+++ plugins/Bloom/src/BloomManager.h	2013-02-22 23:03:25 +0000
@@ -29,15 +29,28 @@
 
 STANDARD_EXCEPTION(BloomException);
 
-class BloomManager : public Plugin {
+class ADCHPP_VISIBLE BloomManager : public Plugin {
 public:
 	BloomManager(Core &core);
 	virtual ~BloomManager();
 
-	virtual int getVersion() { return 0; }
+	virtual int getVersion() { return 1; }
 
 	void init();
 
+        /*Check if the entity has a bloom filter*/
+	bool hasBloom(Entity& c) const;
+        
+        /*Check if the entity may have the desired TTH according to the filter*/
+	bool hasTTH(Entity& c,const TTHValue& tth) const;
+
+	/*Get the number of searches sent (to clients)*/
+	int64_t getSearches() const;
+	/*Get the number of searches by TTH sent (to clients)*/
+	int64_t getTTHSearches() const;
+	/*Get the number of sent searches stopped*/
+	int64_t getStoppedSearches() const;
+        
 	static const std::string className;
 private:
 	PluginDataHandle bloomHandle;

=== modified file 'plugins/Script/examples/access.guard.lua'
--- plugins/Script/examples/access.guard.lua	2013-02-17 14:35:16 +0000
+++ plugins/Script/examples/access.guard.lua	2013-02-22 23:03:25 +0000
@@ -2250,9 +2250,9 @@
 	
 	local NATT, SEGA, TTH, chars, cid , params, params_size
 	if (fl_settings.fl_commandstats.value >= 0 or access.get_level(c) <= fl_settings.fl_level.value) or (li_settings.li_limitstats.value >= 0 and access.get_level(c) <= li_settings.li_level.value) then
-		cid = c:getCID():toBase32()
-		params = cmd:getParameters()
-		params_size = params:size()
+		local cid = c:getCID():toBase32()
+		local params = cmd:getParameters()
+		local params_size = params:size()
 		if #cmd:getParam("TR", 0) > 0 then
 			TTH = true
 		end

=== modified file 'plugins/Script/examples/access.lua'
--- plugins/Script/examples/access.lua	2013-02-10 16:35:37 +0000
+++ plugins/Script/examples/access.lua	2013-02-22 23:03:25 +0000
@@ -488,7 +488,7 @@
 	end
 end
 
-local function add_stats(stat)
+function add_stats(stat)
 	if stats[stat] then
 		stats[stat] = stats[stat] + 1
 	else
@@ -1524,7 +1524,7 @@
 			return
 		end
 
-		local my_user = get_user_c(c)
+		local ulevel = get_level(c)
 
 		local other = cm:findByNick(nick)
 

=== modified file 'plugins/Script/examples/access.op.lua'
--- plugins/Script/examples/access.op.lua	2013-02-10 16:35:37 +0000
+++ plugins/Script/examples/access.op.lua	2013-02-22 23:03:25 +0000
@@ -108,6 +108,7 @@
 		end
 
 		local count = 0
+                local i = 0
 		for i = 0, size - 1 do
 			local other = entities[i]:asClient()
 			if other then

=== modified file 'swig/SConscript'
--- swig/SConscript	2012-10-23 12:42:02 +0000
+++ swig/SConscript	2013-02-22 23:03:25 +0000
@@ -130,8 +130,8 @@
 	pyd = env.SharedLibrary(target, sources, SHLIBPREFIX='')
 	targets.append(pyd)
 
-def buildLuaModule():
-	env, target, sources = dev.prepare_build(source_path, 'luadchpp', 'lua.i')
+def buildLuaModule(lib,mod,plugin):
+	env, target, sources = dev.prepare_build(source_path, lib, mod)
 
 	env['SWIGOUTDIR'] = Dir(dev.get_build_path('bin'))
 	
@@ -150,6 +150,8 @@
 	# on x64, SWIG includes some unsafe pointer conversions that the compiler of course disallows...
 	if 'gcc' in env['TOOLS'] and env['arch'] != 'x86':
 		env.Append(CPPFLAGS = ['-fpermissive'])
+		if plugin:
+			env.Replace(UNDEF = '')
 
 	luadchpp = env.SharedLibrary(target, sources, SHLIBPREFIX='')
 	targets.append(luadchpp)
@@ -205,7 +207,9 @@
 		buildPyModule()
 
 if 'lua' in dev.env['langs']:
-	buildLuaModule()
+	buildLuaModule('luadchpp','lua.i',False)
+	if 'Bloom' in dev.env['plugins']:
+		buildLuaModule('luadchppbloom','bloom.i',True)
 
 # TODO buildPHPModule()
 

=== added file 'swig/bloom.i'
--- swig/bloom.i	1970-01-01 00:00:00 +0000
+++ swig/bloom.i	2013-02-22 23:03:25 +0000
@@ -0,0 +1,60 @@
+%module luadchppbloom
+
+%runtime %{
+
+#include <adchpp/adchpp.h>
+
+#include <adchpp/PluginManager.h>
+#include <adchpp/Core.h>
+
+using namespace adchpp;
+using namespace std;
+
+%}
+
+%include "exception.i"
+%import "lua.i"
+
+%runtime %{
+#include <memory> 
+#include <plugins/Bloom/src/BloomManager.h>
+#include <iostream>
+%}
+
+%{
+	static adchpp::Core *getCurrentCore(lua_State *l) {
+		lua_getglobal(l, "currentCore");
+		void *core = lua_touserdata(l, lua_gettop(l));
+		lua_pop(l, 1);
+		return reinterpret_cast<Core*>(core);
+	}
+
+%}
+
+class BloomManager {
+public:
+	bool hasBloom(adchpp::Entity& c);
+	int64_t getSearches() const;
+	int64_t getTTHSearches() const;
+	int64_t getStoppedSearches() const;
+};
+
+%extend BloomManager {
+	bool hasTTH(adchpp::Entity& c,const std::string tth) {
+		return self->hasTTH(c,TTHValue(tth));
+	}
+}
+
+%template(TBloomManagerPtr) shared_ptr<BloomManager>;
+
+%inline %{
+
+namespace adchpp {
+/* Get Bloom Manager */
+shared_ptr<BloomManager> getBM(lua_State* l) {
+	return (std::dynamic_pointer_cast<BloomManager>(getCurrentCore(l)->getPluginManager().getPlugin("BloomManager")));
+}
+
+}
+
+%}

=== modified file 'swig/lua.i'
--- swig/lua.i	2013-02-07 21:44:55 +0000
+++ swig/lua.i	2013-02-22 23:03:25 +0000
@@ -24,7 +24,7 @@
 %{
 	static adchpp::Core *getCurrentCore(lua_State *l) {
 		lua_getglobal(l, "currentCore");
-		void *core = lua_touserdata(l, 1);
+		void *core = lua_touserdata(l, lua_gettop(l));
 		lua_pop(l, 1);
 		return reinterpret_cast<Core*>(core);
 	}


Follow ups