Serving sofia.conf via lua (updated)
Hi. Sending again with a bit of clarification - my original message hasn't hit the list yet, so I'm hoping people can reply to just this one... I am trying to get Freeswitch to get its sofia configuation from lua instead of static XML files. https://freeswitch.org/confluence/display/FREESWITCH/mod_xml_curl tells me for example that "Section: configuration - This is used to send back configuration files such as sofia.conf." Yes, I know that that page refers to mod_xml_curl and not mod_xml_lua but I'm pretty certain that the principle is the same, and https://freeswitch.org/confluence/display/FREESWITCH/Serving+Configuration+w... seems to confirm this, although is it much thinner on examples. I do not that this page also says "there is no Lua page yet, and Lua-related docs are scattered all over the place..." :( So, anyway, I'm pretty sure what I want to do should be possible, but nowhere have I so far been able to find a fully working example telling me how to do it. My understanding so far is that: 1. I need to create a lua script which generates the *complete* XML as would be served from /etc/freeswitch/autoload_configs/sofia.conf.xml and all its included sub-directories/files 2. This XML as output from the script should be enclosed within tags: <document type="freeswitch/xml"> <section name="configuration"> ... XML goes here ... </section> </document> 3. I should place this lua script in freeswitch's scripting directory, which on my (Debian) machine is /usr/share/freeswitch/scripts 4. I need to enable this script to be run by including in /etc/freeswitch/autoload_configs/lua.conf.xml: <param name="xml-handler-script" value="sofia.conf.lua"/> <param name="xml-handler-bindings" value="configuration"/> The first thing which is not clear to me is what I should do about /etc/freeswitch/autoload_configs/sofia.conf.xml - if I leave it as it is, it appears to be used in the normal way, and my lua script is ignored - if I delete it (or rename it to sofia.conf.xml.noload for example) then sofia doesn't get loaded *at all* and when I go into fs_cli I do not even have a "sofia" command - if I "touch" the filename so that /etc/reeswitch/autoload_configs/sofia.conf.xml exists but is empty, I get the same result egain - the "sofia" command does not even exist in the cli So, can anyone point me at how to join these things up correctly so that I can serve sofia configuration settings from a lua script? I've been told here that: On Friday 05 November 2021 at 12:28:55, David Villasmil wrote:
In FS there’s the embedded lua. You can do almost anything with it.
I'm struggling to find the documentation telling me how, though :( Thanks in advance, Antony. -- "It would appear we have reached the limits of what it is possible to achieve with computer technology, although one should be careful with such statements; they tend to sound pretty silly in five years." - John von Neumann (1949) Please reply to the list; please *don't* CC me.
On Tuesday 30 November 2021 at 11:20:02, Antony Stone wrote:
I am trying to get Freeswitch to get its sofia configuation from lua instead of static XML files.
I've worked out what the problem was, even before my question/s appear to have reached the list!? It turns out that I needed to move: <load module="mod_lua"/> much higher up in /etc/freeswitch/autoload_configs/modules.conf.xml so that it got loaded before: <load module="mod_sofia"/> After that, my lua script's configuration does get used to configure sofia :) (This seems like either missing documentation, or even an inappropriate default setting to me - after all, in what circumstance would it be better to load lua after nearly everything else, given that it can be used to actually configure everything else and is then needed first?) Anyway, I now have another problem. If I take my (static, nothing fancy yet) and monolithic sofia configuration file and put it into /etc/freeswitch/autoload_configs/sofia.conf.xml (and disable lua) then it does what I expect and all works. If I take the same file and put it into my lua script (correctly enclosed within the extra <document> and <section> tags), then it does get loaded, but it produces errors relating to some of the variables pre-defined in vars.xml. So, for example, one of my SIP profiles contains: <param name="rtp-ip" value="$${local_ip_v4}"/> <param name="sip-ip" value="$${local_ip_v4}"/> This produces (when sofia gets loaded) the error messages: -------- tport.c:1844 tport_server_addrinfo() tport_server_addrinfo(0x56318f75ee20): su_getaddrinfo($${local_ip_v4}, 5080) for *: Name or service not known nta.c:2276 nta_agent_add_tport() nta: bind($${local_ip_v4}:5080;transport=*;maddr=$${local_ip_v4}): No such file or directory nua_stack.c:195 nua_stack_init() nua: initializing SIP stack failed -------- Inside the console fs_cli I can do: eval $${local_ip_v4} and it gives me the correct answer. If I replace $${local_ip_v4} in the xml configuration delivered by lua with the numeric IP address, then sofia loads and works as it did with the plain XML file in /etc/freeswitch/autoload_configs/sofia.conf.xml However, I see that some other variables, also defined in vars.xml, are being correctly interpreted and used from the XML provided by lua, so this isn't a consistent "you can't reference variables" problem. Does anyone have a clue what I need to do to fix this? Thanks, Antony. -- I bought a book about anti-gravity. The reviews say you can't put it down. Please reply to the list; please *don't* CC me.
On Tuesday 30 November 2021 at 14:17:47, Antony Stone wrote:
If I take my (static, nothing fancy yet) and monolithic sofia configuration file and put it into /etc/freeswitch/autoload_configs/sofia.conf.xml (and disable lua) then it does what I expect and all works.
If I take the same file and put it into my lua script (correctly enclosed within the extra <document> and <section> tags), then it does get loaded, but it produces errors relating to some of the variables pre-defined in vars.xml.
<...snip...>
However, I see that some other variables, also defined in vars.xml, are being correctly interpreted and used from the XML provided by lua, so this isn't a consistent "you can't reference variables" problem.
I'm no longer so sure about *any* of the variables working correctly. I've now converted the static XML being served by lua into something which does the database lookups which I needed lua for in the first place, and that is working very nicely, however any variables included in the XML output are not being interpreted when the configuration is actually used by Freeswitch. Does that mean that variables (for example, defined in vars.xml) simply cannot be used in XML when that XML comes from lua instead of being in a standard file? What's the way round this, so that I can use the values variables as normal in a configuration file, when the configuration is being generated by lua? Thanks, Antony. -- Pavlov is in the pub enjoying a pint. The barman rings for last orders, and Pavlov jumps up exclaiming "Damn! I forgot to feed the dog!" Please reply to the list; please *don't* CC me.
On Tuesday 30 November 2021 at 15:55:11, Antony Stone wrote:
I've now converted the static XML being served by lua into something which does the database lookups which I needed lua for in the first place, and that is working very nicely, however any variables included in the XML output are not being interpreted when the configuration is actually used by Freeswitch.
Does that mean that variables (for example, defined in vars.xml) simply cannot be used in XML when that XML comes from lua instead of being in a standard file?
I found http://lists.freeswitch.org/pipermail/freeswitch-users/2011- October/077171.html which explains how to do this, and I couldn't find this clue anywhere in the documentation at https://freeswitch.org/confluence/ Antony. -- Warum können Seeräuber nicht den Umfang eines Kreises berechnen? Weil sie Piraten... Please reply to the list; please *don't* CC me.
https://github.com/seven1240/xui it is outdated and stopped updating. but the lua scripts should still work. On Tue, Nov 30, 2021 at 10:08 PM Antony Stone < Antony.Stone@freeswitch.open.source.it> wrote:
Hi.
Sending again with a bit of clarification - my original message hasn't hit the list yet, so I'm hoping people can reply to just this one...
I am trying to get Freeswitch to get its sofia configuation from lua instead of static XML files.
https://freeswitch.org/confluence/display/FREESWITCH/mod_xml_curl tells me for example that "Section: configuration - This is used to send back configuration files such as sofia.conf." Yes, I know that that page refers to mod_xml_curl and not mod_xml_lua but I'm pretty certain that the principle is the same, and
https://freeswitch.org/confluence/display/FREESWITCH/Serving+Configuration+w... seems to confirm this, although is it much thinner on examples. I do not that this page also says "there is no Lua page yet, and Lua-related docs are scattered all over the place..." :(
So, anyway, I'm pretty sure what I want to do should be possible, but nowhere have I so far been able to find a fully working example telling me how to do it.
My understanding so far is that:
1. I need to create a lua script which generates the *complete* XML as would be served from /etc/freeswitch/autoload_configs/sofia.conf.xml and all its included sub-directories/files
2. This XML as output from the script should be enclosed within tags:
<document type="freeswitch/xml"> <section name="configuration"> ... XML goes here ... </section> </document>
3. I should place this lua script in freeswitch's scripting directory, which on my (Debian) machine is /usr/share/freeswitch/scripts
4. I need to enable this script to be run by including in /etc/freeswitch/autoload_configs/lua.conf.xml:
<param name="xml-handler-script" value="sofia.conf.lua"/> <param name="xml-handler-bindings" value="configuration"/>
The first thing which is not clear to me is what I should do about /etc/freeswitch/autoload_configs/sofia.conf.xml
- if I leave it as it is, it appears to be used in the normal way, and my lua script is ignored - if I delete it (or rename it to sofia.conf.xml.noload for example) then sofia doesn't get loaded *at all* and when I go into fs_cli I do not even have a "sofia" command - if I "touch" the filename so that /etc/reeswitch/autoload_configs/sofia.conf.xml exists but is empty, I get the same result egain - the "sofia" command does not even exist in the cli
So, can anyone point me at how to join these things up correctly so that I can serve sofia configuration settings from a lua script?
I've been told here that:
On Friday 05 November 2021 at 12:28:55, David Villasmil wrote:
In FS there’s the embedded lua. You can do almost anything with it.
I'm struggling to find the documentation telling me how, though :(
Thanks in advance,
Antony.
-- "It would appear we have reached the limits of what it is possible to achieve with computer technology, although one should be careful with such statements; they tend to sound pretty silly in five years."
- John von Neumann (1949)
Please reply to the list; please *don't* CC me.
_________________________________________________________________________
The FreeSWITCH project is sponsored by SignalWire https://signalwire.com Enhance your FreeSWITCH install with disruptive priced SMS and PSTN services. Build your next product on our scalable cloud platform.
Join our online community to chat in real time https://signalwire.community
Professional FreeSWITCH Services sales@freeswitch.com https://freeswitch.com
Official FreeSWITCH Sites https://freeswitch.com/oss https://freeswitch.org/confluence https://cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users https://freeswitch.com
-- About: http://about.me/dujinfang Blog: http://www.dujinfang.com Proj: http://www.freeswitch.org.cn
participants (2)
-
Antony Stone
-
Seven Du