local xml = require("xml.init")
local config = require("xml_util.config")

freeswitch.consoleLog("notice", "Section: " .. XML_REQUEST.section .. " Value: " .. XML_REQUEST.key_value .. "\n")

if XML_REQUEST.section ~= "configuration"  or XML_REQUEST.key_value ~= "sofia.conf" then
    freeswitch.consoleLog("warning", "Got wrong section or configuration: " .. XML_REQUEST.section .. "/" .. XML_REQUEST.key_value .. ". Do nothing...\n")

    -- Possible this is mistake but we need to answer with NOT FOUND
    XML_STRING = config.xml_notfound()
else
    local xml_doc = {xml="document", type="freeswitch/xml",
        {
            xml="configuration",
            name="sofia.conf",
            config.sofia_global(),
            {
                xml="profiles",
                config.sofia_profile("internal",nil,nil),
                config.sofia_profile("external",nil,nil),
            }
        }
    }

    local xml_test = [[
    <?xml version="1.0"?>
    <document type="freeswitch/xml">
    <configuration name="sofia.conf" description="sofia Endpoint">
    <global_settings>
    <param name="log-level" value="0"/>
    <param name="debug-presence" value="0"/>
    </global_settings>
    <profiles>
    <profile name="internal">
    <settings>
    <param name="debug" value="0"/>
    <param name="sip-trace" value="no"/>
    <param name="sip-capture" value="no"/>
    <param name="dialplan" value="XML"/>
    <param name="sip-port" value="5060"/>
    </settings>
    <gateways>
    </gateways>
    </profile>
    </profiles>
    </configuration>
    </document>
    ]]

    XML_STRING = xml_test .. "\n"
    --XML_STRING = config.header .. xml.dump(xml_doc) .. "\n"

    freeswitch.consoleLog("notice", "Reply with: " .. XML_STRING .. "\n")
end
