return rc;
}
-static inline void init_lsd(LuaStateDescriptor* lsd, const std::string& detector_name,
+static bool init_lsd(LuaStateDescriptor* lsd, const std::string& detector_name,
lua_State* L)
{
lsd->service_id = APP_ID_UNKNOWN;
lsd->package_info.name = detector_name;
lua_pop(L, 1); // pop client table
lua_pop(L, 1); // pop DetectorPackageInfo table
+
+ if (lsd->package_info.validateFunctionName.empty())
+ return false;
+
+ return true;
}
LuaServiceDetector::LuaServiceDetector(AppIdDiscovery* sdm, const std::string& detector_name,
LuaClientObject::LuaClientObject(const std::string& detector_name,
const std::string& log_name, bool is_custom, IpProtocol protocol, lua_State* L,
- OdpContext& odp_ctxt) : LuaObject(odp_ctxt)
+ OdpContext& odp_ctxt, bool& has_validate) : LuaObject(odp_ctxt)
{
- init_lsd(&lsd, detector_name, L);
+ has_validate = init_lsd(&lsd, detector_name, L);
if (init(L))
{
// Leaves 1 value (the Detector userdata) at the top of the stack when succeeds
LuaObject* LuaDetectorManager::create_lua_detector(const char* detector_name,
- bool is_custom, const char* detector_filename)
+ bool is_custom, const char* detector_filename, bool& has_validate)
{
std::string log_name;
IpProtocol proto = IpProtocol::PROTO_NOT_SET;
+ has_validate = false;
+
Lua::ManageStack mgr(L);
lua_getfield(L, LUA_REGISTRYINDEX, detector_name);
lua_getfield(L, -1, "client");
if ( lua_istable(L, -1) )
{
- return new LuaClientObject(detector_name, log_name, is_custom, proto, L, ctxt.get_odp_ctxt());
+ return new LuaClientObject(detector_name, log_name, is_custom, proto, L, ctxt.get_odp_ctxt(), has_validate);
}
else
{
lua_getfield(L, -1, "server");
if ( lua_istable(L, -1) )
{
+ has_validate = true;
return new LuaServiceObject(&ctxt.get_odp_ctxt().get_service_disco_mgr(),
detector_name, log_name, is_custom, proto, L, ctxt.get_odp_ctxt());
}
return 0;
}
-void LuaDetectorManager::load_detector(char* detector_filename, bool is_custom, bool reload, std::string& buf)
+bool LuaDetectorManager::load_detector(char* detector_filename, bool is_custom, bool reload, std::string& buf)
{
if (reload and !buf.empty())
{
if (init(L))
ErrorMessage("Error - appid: can not load Lua detector, %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
- return;
+ return false;
}
}
else
if (init(L))
ErrorMessage("Error - appid: can not load Lua detector, %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
- return;
+ return false;
}
if (reload and lua_dump(L, dump, &buf))
{
if (init(L))
ErrorMessage("Error - appid: can not compile Lua detector, %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
- return;
+ return false;
}
}
ErrorMessage("Error - appid: can not set env of Lua detector %s : %s\n",
detector_filename, lua_tostring(L, -1));
lua_pop(L, 1);
- return;
+ return false;
}
- LuaObject* lua_object = create_lua_detector(detectorName, is_custom, detector_filename);
+ bool has_validate;
+ LuaObject* lua_object = create_lua_detector(detectorName, is_custom, detector_filename, has_validate);
if (lua_object)
allocated_objects.push_front(lua_object);
+
+ return has_validate;
}
void LuaDetectorManager::load_lua_detectors(const char* path, bool is_custom, bool reload)
}
file.close();
- load_detector(globs.gl_pathv[n], is_custom, reload, buf);
+ bool has_validate = load_detector(globs.gl_pathv[n], is_custom, reload, buf);
if (reload)
{
for (auto& lua_detector_mgr : lua_detector_mgr_list)
- lua_detector_mgr->load_detector(globs.gl_pathv[n], is_custom, reload, buf);
+ {
+ if (has_validate)
+ lua_detector_mgr->load_detector(globs.gl_pathv[n], is_custom, reload, buf);
+ }
buf.clear();
}
lua_settop(L, 0);
void initialize_lua_detectors(bool reload = false);
void activate_lua_detectors();
void list_lua_detectors();
- void load_detector(char* detector_name, bool is_custom, bool reload, std::string& buf);
+ bool load_detector(char* detector_name, bool is_custom, bool reload, std::string& buf);
void load_lua_detectors(const char* path, bool is_custom, bool reload = false);
LuaObject* create_lua_detector(const char* detector_name, bool is_custom,
- const char* detector_filename);
+ const char* detector_filename, bool& has_validate);
AppIdContext& ctxt;
std::list<LuaObject*> allocated_objects;