【问题标题】:FreeSWITCH: Error when loading config with Lua insted of CURLFreeSWITCH:使用安装了 CURL 的 Lua 加载配置时出错
【发布时间】:2016-10-07 09:50:00
【问题描述】:

我有带有 xml_curl 模块选项的 freeswitch 的工作设置

<param name="gateway-url" 
       value="http://localhost:444/index.php" 
       bindings="directory|dialplan|configuration"/>

我想在 lua 模块上更改 xml_curl 模块,所以我关闭了 xml_curl 模块并将下一个选项设置为 lua 模块

<param name="xml-handler-script"
       value="/var/www/callcenter/current/freeswitch/index.lua"/>
<param name="xml-handler-bindings"
       value="dialplan|directory|configuration"/>

但是 sofia 模块会抛出错误 Error Creating SIP UA for profile。模块lua有什么问题吗?也许我应该为 lua 模块设置一些其他选项?

我有 FreeSWITCH 1.6

【问题讨论】:

  • 首先使用, 而不是|。接下来检查你的 Lua 代码返回给 FS 的内容。它应该返回 full XML 结构以用于以 &lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;&lt;document type="freeswitch/xml"&gt;&lt;section name="configuration"&gt; 开头的配置
  • Lua 读取与 CURL 相同的文件,因此应该没有区别。将 | 更改为 , 没有帮助

标签: curl lua freeswitch


【解决方案1】:

mod_lua 在初始启动期间加载,然后在初始启动后加载的模块可能会在它们请求配置时由绑定脚本提供其配置,这对于许多模块来说正在加载。

<configuration name="lua.conf" description="LUA Configuration">
   <settings>
      <param name="xml-handler-script" value="configuration.lua"/>
      <param name="xml-handler-bindings" value="configuration"/>
   </settings>
</configuration>

那么当模块启动时,XML_REQUEST 会有:

key_value = 'iax.conf'|'event_socket.conf'|sofia.conf'|...
key_name = 'name'
section = 'configuration'
tag_name = 'configuration'

【讨论】:

    【解决方案2】:

    50 年后,万一有人撞到了这个:

    问题是${foo} 变量默认没有展开。此代码将启用它:

    local rpc = require("rpc")    
        
    freeswitch.consoleLog("NOTICE", table.concat({    
        "Loading configuration " ..    
        tostring(XML_REQUEST["section"]) ..     
        " -> "..    
        tostring(XML_REQUEST["key_value"]) ..    
        " using lua\n"    
    }, " "))    
        
    local ret    
        
    rpc.context(function(rpc_api)    
        local conf = rpc_api.get_configuration {    
            section   = XML_REQUEST.section,      
            tag_name  = XML_REQUEST.tag_name,     
            key_name  = XML_REQUEST.key_name,                                                                
            key_value = XML_REQUEST.key_value,                                                               
            params    = params and params:serialize("json") or false,                                        
        }    
            
        ret = type(conf.result) == "string" and conf.result or conf.result[1]    
    end)    
        
    assert(ret, tostring(XML_REQUEST["section"]) .. " "..  tostring(XML_REQUEST["key_value"]) .. " lacks a config generator")                              
                                         
    -- Apply the global variables        
    local function apply_globals(txt)    
        return txt:gsub('([$]+%b{})', function(w)    
            local var = w:match("[{]([^}]+)[}]")    
            freeswitch.consoleLog("WARNING", "Apply global: "..var .. " = ".. tostring(freeswitch.getGlobalVariable(var)).."\n")    
            return freeswitch.getGlobalVariable(var)                                                         
        end)                                                                                                 
    end                                                                                                      
                                                                                                             
    XML_STRING = apply_globals(ret)    
        
    if XML_REQUEST.key_value == "sofia.conf" then    
        freeswitch.consoleLog("WARNING", "CONF   " .. XML_STRING.. "\n")    
    end  
    

    还要确保您的文档具有在普通文件中找不到的额外标题:

    local CONF_HEADER = [[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <document type="freeswitch/xml">                                                                                                            
            <section name="configuration">
    ]]
    
    local CONF_FOOTER = [[
        </section>
    </document>
    ]]
    
    return CONF_HEADER..read_xml_from_disk()..CONF_FOOTER
    
    

    【讨论】:

      猜你喜欢
      • 2016-09-30
      • 2020-03-24
      • 2018-12-26
      • 2016-08-04
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      相关资源
      最近更新 更多