ad_library {

    Definitions for VXML

    You may use this software free under the GNU General Public License.

    @author Eve Andersson (eveander@eveander.com)
}

# HTML entity/ iso8859-1 character code map
# for vxml purposes, it's useful to have the HTML entity as the key, since these
# are what we need to strip out
ns_share -init {
    set html_to_iso_character_codes(&Agrave\;) "&#192\;"
    set html_to_iso_character_codes(&Aacute\;) "&#193\;"
    set html_to_iso_character_codes(&Acirc\;) "&#194\;"
    set html_to_iso_character_codes(&Atilde\;) "&#195\;"
    set html_to_iso_character_codes(&Auml\;) "&#196\;"
    set html_to_iso_character_codes(&Aring\;) "&#197\;"
    set html_to_iso_character_codes(&AElig\;) "&#198\;"
    set html_to_iso_character_codes(&Ccedil\;) "&#199\;"
    set html_to_iso_character_codes(&Egrave\;) "&#200\;"
    set html_to_iso_character_codes(&Eacute\;) "&#201\;"
    set html_to_iso_character_codes(&Ecirc\;) "&#202\;"
    set html_to_iso_character_codes(&Euml\;) "&#203\;"
    set html_to_iso_character_codes(&Igrave\;) "&#204\;"
    set html_to_iso_character_codes(&Iacute\;) "&#205\;"
    set html_to_iso_character_codes(&Icirc\;) "&#206\;"
    set html_to_iso_character_codes(&Iuml\;) "&#207\;"
    set html_to_iso_character_codes(&ETH\;) "&#208\;"
    set html_to_iso_character_codes(&Dstrok\;) "&#208\;"
    set html_to_iso_character_codes(&Ntilde\;) "&#209\;"
    set html_to_iso_character_codes(&Ograve\;) "&#210\;"
    set html_to_iso_character_codes(&Oacute\;) "&#211\;"
    set html_to_iso_character_codes(&Ocirc\;) "&#212\;"
    set html_to_iso_character_codes(&Otilde\;) "&#213\;"
    set html_to_iso_character_codes(&Ouml\;) "&#214\;"
    set html_to_iso_character_codes(&Oslash\;) "&#216\;"
    set html_to_iso_character_codes(&Ugrave\;) "&#217\;"
    set html_to_iso_character_codes(&Uacute\;) "&#218\;"
    set html_to_iso_character_codes(&Ucirc\;) "&#219\;"
    set html_to_iso_character_codes(&Uuml\;) "&#220\;"
    set html_to_iso_character_codes(&Yacute\;) "&#221\;"
    set html_to_iso_character_codes(&THORN\;) "&#222\;"
    set html_to_iso_character_codes(&szlig\;) "&#223\;"
    set html_to_iso_character_codes(&agrave\;) "&#224\;"
    set html_to_iso_character_codes(&aacute\;) "&#225\;"
    set html_to_iso_character_codes(&acirc\;) "&#226\;"
    set html_to_iso_character_codes(&atilde\;) "&#227\;"
    set html_to_iso_character_codes(&auml\;) "&#228\;"
    set html_to_iso_character_codes(&aring\;) "&#229\;"
    set html_to_iso_character_codes(&aelig\;) "&#230\;"
    set html_to_iso_character_codes(&ccedil\;) "&#231\;"
    set html_to_iso_character_codes(&egrave\;) "&#232\;"
    set html_to_iso_character_codes(&eacute\;) "&#233\;"
    set html_to_iso_character_codes(&ecirc\;) "&#234\;"
    set html_to_iso_character_codes(&euml\;) "&#235\;"
    set html_to_iso_character_codes(&igrave\;) "&#236\;"
    set html_to_iso_character_codes(&iacute\;) "&#237\;"
    set html_to_iso_character_codes(&icirc\;) "&#238\;"
    set html_to_iso_character_codes(&iuml\;) "&#239\;"
    set html_to_iso_character_codes(&eth\;) "&#240\;"
    set html_to_iso_character_codes(&ntilde\;) "&#241\;"
    set html_to_iso_character_codes(&ograve\;) "&#242\;"
    set html_to_iso_character_codes(&oacute\;) "&#243\;"
    set html_to_iso_character_codes(&ocirc\;) "&#244\;"
    set html_to_iso_character_codes(&otilde\;) "&#245\;"
    set html_to_iso_character_codes(&ouml\;) "&#246\;"
    set html_to_iso_character_codes(&oslash\;) "&#248\;"
    set html_to_iso_character_codes(&ugrave\;) "&#249\;"
    set html_to_iso_character_codes(&uacute\;) "&#250\;"
    set html_to_iso_character_codes(&ucirc\;) "&#251\;"
    set html_to_iso_character_codes(&uuml\;) "&#252\;"
    set html_to_iso_character_codes(&yacute\;) "&#253\;"
    set html_to_iso_character_codes(&thorn\;) "&#254\;"
    set html_to_iso_character_codes(&yuml\;) "&#255\;"
} html_to_iso_character_codes


ad_proc vxml_convert_illegal_characters { the_string } {
    Changes < to &lt;, > to &gt; and & to &amp; (otherwise, these break VXML).
    Also convert HTML character codes (e.g., &ouml;) to the right iso8859-1 code (e.g., &#246;).
} { 
    # first character code conversions
    ns_share html_to_iso_character_codes

    foreach html_code [array names html_to_iso_character_codes] {
	# in the iso code, change & to \\& and ; to \;
	set iso_code [lindex [array get html_to_iso_character_codes $html_code] 1]
	regsub -all "&" $iso_code {\\&} iso_code
	regsub -all $html_code $the_string $iso_code the_string
    }

    # change & to &amp; only if & is not followed by a #
    regsub -all "&(\[^#\])" $the_string {\&amp;\1} the_string
    regsub -all "&$" $the_string {\&amp;} the_string
    regsub -all < $the_string \\&lt\; the_string
    regsub -all > $the_string \\&gt\; the_string

    return $the_string
}

ad_proc vxml_return_content { content } {
    ns_return doesn't work for returning VXML (there appears to be a hidden character ^@ at the
    end which confuses the VXML parser), so this ns_writes the headers explicitly
} {
    set header_time [ns_httptime [ns_time]]
    set content_length [expr [string length $content] + 1]

    ns_write "HTTP/1.0 200 OK
MIME-Version: 1.0
Date: $header_time
Server: NaviServer/2.0 AOLserver/2.3.2
Content-Type: text/plain
Content-Length: $content_length

$content"
}

ad_proc vxml_tellme_phone_dir_passcode {} {
    # CHANGE ME
    return "1111"
}