<?xml version="1.0" encoding="UTF-8"?>
<!--
Release 1.1 - 2010-10-21
FIXED: ISSUE-737: -  declarations of var i and var result added
	
Release 1.3 - 2010-12-21
FIXED: 
no issue, comment added to assertion 1262 to state that it is not implemented and to ignore it if reporting among the "assertion left" list.

	-->

<ccxml xmlns="http://www.w3.org/2002/09/ccxml" xmlns:conf="http://www.w3.org/2005/ccxml-conformance" version="1.0">
	<!--
      <conf:fail reason="'Unexpected Event ' + event$.name"/>
-->
	<conf:docsetup/>
	
	<var name="general_connid"/>
	<var name="method"/>
	<var name="uri"/>
	<var name="sendid1262"/>
	
	<script><![CDATA[
	   function GetMilliseconds() {
     var d = new Date();
     return d.getTime();  // ms from midnight on Jan 1, 2000.
   }

var t_start, t_end, t_delay = 2000, t_delta, t_delta_e = 0.05 * t_delay;
		   ]]>
		   
	function extractCurrentDir(currUri)
	{
		<!-- FIXED ISSUE-737: declarations of var i and var result added-->
		var i = currUri.lastIndexOf("/");
		var result = currUri.substring(0,i+1);
		return result;
	}
		   
	</script>
	<script><![CDATA[
var i=0;

assertions[i++] = init_assertion('1262');

add_2_assert_trace('1260');
add_2_assert_trace('1261');

var assert_last = i - 1;
var assert_index = -1;
//
// out of the loop assertions (children?)
//
//
s_ASSERTIONS_LEFT = show_remained_assertions();
var b_in_test = false;


]]></script>
	<eventprocessor statevariable="current_state">
		<conf:setup type="alerting"/>
		<transition event="connection.alerting" state="init">
			<send targettype="'ccxml'" target="session.id" name="'user.timeout'" delay="TEST_LONG_TIMEOUT"/>
			<accept connectionid="event$.connectionid"/>
		</transition>
		<transition event="connection.connected" state="init">
			<assign name="general_connid" expr="event$.connectionid"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="user.PREPARE_NEW">
			<conf:comment expr="'Event: ' + event$.name"/>
			<if cond="assert_index &gt;= 0">
				<assign name="ASSERTION_NUM" expr="assertions[assert_index].number"/>
				<assign name="t_ASSERT_RESULT" expr="assertions[assert_index].P_F"/>
				<script>t_ASSERT_REASON = assertions[assert_index].reason</script>
				<if cond="t_ASSERT_RESULT == s_PASS">
					<conf:pass reason="t_ASSERT_REASON"/>
					<elseif cond="t_ASSERT_RESULT == s_FAIL"/>
					<conf:fail reason="t_ASSERT_REASON"/>
					<else/>
					<conf:not_exec reason="t_ASSERT_REASON"/>
				</if>
			</if>
			<assign name="assert_index" expr="assert_index + 1"/>
			<if cond="assert_index &gt; assert_last">
				<log label="s_TA" expr="s_ASSERTIONS_LEFT"/>
				<conf:uncond_exit expr="'DONE'"/>
				<else/>
				<log label="s_TA" expr="s_ASSERTIONS_LEFT"/>
				<assign name="ASSERTION_NUM" expr=" assertions[assert_index].number"/>
				<assign name="t_ASSERT_REASON" expr="''"/>
				<script>assertions[assert_index].P_F = s_FAIL;</script>
				<assign name="current_state" expr="state_prefix + ASSERTION_NUM"/>
				<send targettype="'ccxml'" target="session.id" name="start_name_prefix + ASSERTION_NUM" sendid="cur_event_ID"/>
				<log label="s_TA" expr="'Loop event: SendID=' + cur_event_ID"/>
			</if>
		</transition>
		
		<transition event="user.START_ASSERTION_1262" state="ASSERTION_NMBR_1262">
<!--
1067  	
Appendix L - Session Creation Event I/O Processor  	
Implementation MUST support HTTP Post  	
rgreen@voxeo.com  	Accepted
-->
			<conf:comment expr="'Event: ' + event$.name"/>
			
			<var name="eventsource" expr="session.ioprocessors['basichttp']"/>
			<var name="foo" expr="'bar'"/>
			<assign name="uri" expr="extractCurrentDir(session.uri)+'L_A_1067.ccxml'"/>
			
			<send name="'name'" targettype="'basichttp'" target="session.ioprocessors['createsession']" namelist="uri eventsource foo"/>
			
			<assign name="current_state" expr="'ASSERTION_NMBR_1262_PART_2'"/>

	    <send name="'user.continue'" targettype="'ccxml'" target="session.id" delay="'5000ms'"/>

		</transition>

<!--
1261
Appendix L - Session Creation Event I/O Processor  	
the http reserved parameter 'method' if missing must default to 'get'

1262
Appendix L - Session Creation Event I/O Processor  	
the http reserved parameter 'timeout' which is equivalent to <createccxml>'s 'timeout' attribute and is used to set the maximum time allowed when fetching a CCXML document before abandoning the fetch attempt and returning an error. If omitted, the CCXML platform will use a default value

-->

		
		<transition event="send.successful" state="ASSERTION_NMBR_1262">
			<conf:comment expr="'Event: ' + event$.name"/>
		</transition>



		
		<transition event="user.continue" state="ASSERTION_NMBR_1262_PART_2">
<!--
1260  	
Appendix L - Session Creation Event I/O Processor  	
The reserved http parameter 'method' which is equivalent to <createccxml>'s 'method' attribute; used to set the HTTP method applied in the fetch of the specified CCXML document. Allowed values are "get" or "post" (case-insensitive).  	
rgreen@voxeo.com  	Accepted
-->
			<conf:comment expr="'Event: ' + event$.name"/>
			
			<assign name="method" expr="'get'"/>
			<var name="currentbase" expr="extractCurrentDir(session.uri)"/>
			
			<assign name="uri" expr="currentbase+'cgi-bin/A1260_checkMethodPassOnGet.ircgi'"/>

			
			<send name="'one'" targettype="'basichttp'" target="session.ioprocessors['createsession']" namelist="uri method"/>

			<assign name="method" expr="'post'"/>
			<assign name="uri" expr="currentbase+'cgi-bin/A1260_checkMethodPassOnPost.ircgi'"/>

			<send name="'two'" targettype="'basichttp'" target="session.ioprocessors['createsession']" namelist="uri method"/>
			
			<script>remove_from_assert_trace(1260)</script>
			
			<assign name="current_state" expr="'ASSERTION_NMBR_1262_PART_3'"/>
		    <send name="'user.continue'" targettype="'ccxml'" target="session.id" delay="'3000ms'"/>
		</transition>
		
		<transition event="error.connection" state="ASSERTION_NMBR_1262_PART_2">
			<conf:comment expr="'Event: ' + event$.name"/>
			<disconnect connectionid="general_connid"/>
		</transition>
		
		<transition event="connection.disconnected" state="ASSERTION_NMBR_1262_PART_2">
			<conf:comment expr="'Event: ' + event$.name"/>
			<conf:uncond_exit reason="'Encountered an error; Connection was disconnected'"/>
		</transition>
		
		<transition event="*" state="ASSERTION_NMBR_1262_PART_2">
			<conf:comment expr="'Event: ' + event$.name"/>
		</transition>
		
		<!-- FIXED: no issue, comment added to assertion 1262 to state that it is not implemented 
		and to ignore it if reporting among the "assertion left" list. -->
		
		<transition event="user.continue" state="ASSERTION_NMBR_1262_PART_3">
			<conf:comment expr="'Event: ' + event$.name"/>
			<assign name="uri" expr="extractCurrentDir(session.uri)+'cgi-bin/A1261_checkMethodPassOnGet.ircgi'"/>
			
			<send name="'three'" targettype="'basichttp'" target="session.ioprocessors['createsession']" namelist="uri"/>
			
			<script>remove_from_assert_trace(1261)</script>
			
		 	<script>assertions[assert_index].P_F = s_NOT_EXECUTED;</script>
		 	<script>assertions[assert_index].reason = 'TA not implemented, ignore it';</script>
			
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
			
		</transition>


						

		
<!-- ============================================================ All-purpose handlers ============================================================ -->

		<transition event="dialog.exit">
			<conf:comment expr="'Event: ' + event$.name"/>
		</transition>

		<transition event="cancel.successful">
			<conf:comment expr="'Event: ' + event$.name"/>
		</transition>

		<transition event="dialog.started">
			<conf:comment expr="'Event: ' + event$.name"/>
		</transition>
		
		<transition event="user.timeout">
			<assign name="current_state" expr="'GEN'"/>
			<conf:uncond_exit expr="'TEST-TIMEOUT.' + show_remained_assertions()"/>
		</transition>
		
		<transition event="send.successful">
			<conf:comment expr="'Event: ' + event$.name + ' (generic handler) state=' + current_state"/>
		</transition>
		
		<transition event="error.send.failed">
			<conf:comment expr="'Event: ' + event$.name + ' : ' + event$.reason"/>
		</transition>
		
		<transition event="*">
			<assign name="t_ASSERT_REASON" expr="'UNEXPECTED EVENT ' + event$.name + ' IN STATE ' + current_state"/>
			<conf:comment expr="t_ASSERT_REASON"/>
			<if cond="current_state == 'init'">
				<conf:uncond_exit expr="'Did not come out from init state.'"/>
				<else/>
				<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
			</if>
		</transition>
	</eventprocessor>
</ccxml>
