| 204 | } |
| 205 | |
| 206 | ts_lua_instance_conf * |
| 207 | ts_lua_script_registered(lua_State *L, char *script) |
| 208 | { |
| 209 | TSMgmtInt curr_time; |
| 210 | ts_lua_instance_conf *conf = nullptr; |
| 211 | |
| 212 | Dbg(dbg_ctl, "[%s] checking if script [%s] is registered", __FUNCTION__, script); |
| 213 | |
| 214 | // first check the reconfigure_time for the script. if it is not found, then it is new |
| 215 | // if it matches the current reconfigure_time, then it is loaded already |
| 216 | // And we return the conf pointer of it. Otherwise it can be loaded again. |
| 217 | if (TS_SUCCESS == TSMgmtIntGet("proxy.process.proxy.reconfigure_time", &curr_time)) { |
| 218 | lua_pushliteral(L, "__scriptTime"); |
| 219 | lua_pushstring(L, script); |
| 220 | lua_concat(L, 2); |
| 221 | lua_rawget(L, LUA_REGISTRYINDEX); |
| 222 | if (lua_isnil(L, -1)) { |
| 223 | Dbg(dbg_ctl, "[%s] failed to get script time for [%s]", __FUNCTION__, script); |
| 224 | lua_pop(L, -1); |
| 225 | return nullptr; |
| 226 | } else { |
| 227 | int time = lua_tonumber(L, -1); |
| 228 | lua_pop(L, -1); |
| 229 | |
| 230 | if (time == curr_time) { |
| 231 | lua_pushliteral(L, "__scriptPtr"); |
| 232 | lua_pushstring(L, script); |
| 233 | lua_concat(L, 2); |
| 234 | lua_rawget(L, LUA_REGISTRYINDEX); |
| 235 | if (lua_isnil(L, -1)) { |
| 236 | Dbg(dbg_ctl, "[%s] failed to get script ptr for [%s]", __FUNCTION__, script); |
| 237 | lua_pop(L, -1); |
| 238 | return nullptr; |
| 239 | } else { |
| 240 | conf = static_cast<decltype(conf)>(lua_touserdata(L, -1)); |
| 241 | lua_pop(L, -1); |
| 242 | return conf; |
| 243 | } |
| 244 | } else { |
| 245 | Dbg(dbg_ctl, "[%s] script time not matching for [%s]", __FUNCTION__, script); |
| 246 | return nullptr; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | } else { |
| 251 | TSError("[ts_lua][%s] failed to get node's reconfigure time while checking script registration", __FUNCTION__); |
| 252 | return nullptr; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | void |
| 257 | ts_lua_script_register(lua_State *L, char *script, ts_lua_instance_conf *conf) |
no test coverage detected