From: Matthew Nicholson Date: Fri, 6 May 2011 15:18:46 +0000 (+0000) Subject: Add a datastore fixup to fix a pbx_lua crash. X-Git-Tag: 1.6.2.19-rc1~3^2~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c4ed0bac68a0780d6ad6b605a66007788695f094;p=thirdparty%2Fasterisk.git Add a datastore fixup to fix a pbx_lua crash. (closes issue #19055) Reported by: jamhed Patches: lua_datastore_fixup1.diff uploaded by mnicholson (license 96) Tested by: mnicholson, jamhed git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.2@317666 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c index c9ac561038..c22dab5567 100644 --- a/pbx/pbx_lua.c +++ b/pbx/pbx_lua.c @@ -85,6 +85,7 @@ static void lua_create_autoservice_functions(lua_State *L); static void lua_create_hangup_function(lua_State *L); void lua_state_destroy(void *data); +static void lua_datastore_fixup(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan); static lua_State *lua_get_state(struct ast_channel *chan); static int exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data); @@ -102,6 +103,7 @@ static struct ast_hashtab *local_table = NULL; static const struct ast_datastore_info lua_datastore = { .type = "lua", .destroy = lua_state_destroy, + .chan_fixup = lua_datastore_fixup, }; @@ -114,6 +116,21 @@ void lua_state_destroy(void *data) lua_close(data); } +/*! + * \brief The fixup function for the lua_datastore. + * \param data the datastore data, in this case it will be a lua_State + * \param old_chan the channel we are moving from + * \param new_chan the channel we are moving to + * + * This function updates our internal channel pointer. + */ +static void lua_datastore_fixup(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan) +{ + lua_State *L = data; + lua_pushlightuserdata(L, new_chan); + lua_setfield(L, LUA_REGISTRYINDEX, "channel"); +} + /*! * \brief [lua_CFunction] Find an app and return it in a lua table (for access from lua, don't * call directly)