//
//  File:               HTTP_Test_no_ASPs
//  Description:        To demonstrate how to use the test port
//  Rev:                R8C
//  Prodnr:             CNL 113 469
//  Updated:            2007-11-09
//  Contact:            http://ttcn.ericsson.se
//  Author:             ETH/RZX Eduard Czimbalmos
module HTTP_Test_no_ASPs {

modulepar {
  charstring  HttpServerHostName    := "www.eth.ericsson.se";
  integer     HttpServerPort        := 80;
  boolean     HTTPClientUseSSL      := false;
  integer     HttpServerListenPort  := 1026;
  boolean     HttpServerUseSSL      := false
}

import from HTTPmsg_Types all;
import from HTTPmsg_PortType all;

type component MTC {};

type component HTTP_client {
  port HTTPmsg_PT HTTP_client_port;
};

type component HTTP_server {
  port HTTPmsg_PT HTTP_server_port;
};

//=========================================================================
// Data Types
//=========================================================================

type record of charstring CHARSTRINGS;
type record of octetstring OCTETSTRINGS;

type record of HTTP_client ptcList;


template Half_close h := { client_id := ? };
template HTTPMessage recv_resp := { response := ? };
template HTTPMessage recv_req := { request := ? };
template HTTPMessage recv_err := { erronous_msg := ? };

function TC() runs on HTTP_client
{
/*    var HeaderLines hd := { {header_name := "Host", header_value := HttpServerHostName},
    {header_name := "Connection", header_value := "close" } };
    var HTTPRequest r := { method := "GET", uri := "/x1.xml",
        version_major := 1, version_minor := 1, header := hd, body := omit };*/
  var HeaderLines hd := { {header_name := "Content-Type", header_value := "text/xml"},
    {header_name := "Content-Length", header_value := "508" },
    {header_name := "Expires", header_value := "Sat, 01 Jan 2000 00:00:00 GMT" },
    {header_name := "Pragma", header_value := "no-cache" } };
  var HTTPRequest r := { client_id := omit, method := "POS T", uri := "/",
    version_major := 1, version_minor := 0, header := hd, body := "<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?><!DOCTYPE ANS SYSTEM 'file://mpp50_ans.dtd'><ANS ver=\"5.00\"><PUSH_USER><PUSH_ID>clientPush</PUSH_ID><PUSH_PWD>clientPush</PUSH_PWD></PUSH_USER><LPA><GMT_OFF>+0100</GMT_OFF><POS msid=\"4670112345\"><PD><TIME>20040117132719</TIME><POLYGON><LL_POINT><LAT>N100410</LAT><LONG>E0202020</LONG></LL_POINT><LL_POINT><LAT>N101610</LAT><LONG>E0202620</LONG></LL_POINT><LL_POINT><LAT>N101610</LAT><LONG>E0201420</LONG></LL_POINT></POLYGON></PD></POS></LPA></ANS>" };
  var HTTPMessage send_req := { request := r };
  var Connect conn := { hostname := HttpServerHostName,
    portnumber := HttpServerPort, use_ssl := HTTPClientUseSSL };
  var Close c := { client_id := omit };

  map(self:HTTP_client_port, system:HTTP_client_port);

  var boolean conn_ok := false;
  while(conn_ok == false)
  {
    timer t_connect := 2.0;
    t_connect.start;
    HTTP_client_port.send(conn);
    alt {
      [] HTTP_client_port.receive(recv_err) {
          timer t_wait := 2.0;
          t_wait.start;
          t_wait.timeout; }
      [] t_connect.timeout {
          conn_ok := true;
          log("connection to server ok"); }
    }
  } // endwhile

  timer T_guard := 5.0;
  T_guard.start;
  HTTP_client_port.send(send_req);

  alt {
    [] HTTP_client_port.receive(h) {
        HTTP_client_port.send(c);
        setverdict(fail); }
    [] HTTP_client_port.receive(recv_resp) {
        timer t := 10.0;
        t.start;
        alt {
          [] HTTP_client_port.receive(h) {
              HTTP_client_port.send(c);
              t.stop;
              setverdict(pass); }
          [] t.timeout {
              HTTP_client_port.send(c);
              t.stop;
              setverdict(fail); }
        };
      }
    [] HTTP_client_port.receive {
        HTTP_client_port.send(c);
        setverdict(fail);
      }
    [] T_guard.timeout {
        setverdict(fail); }
  };

  unmap(self:HTTP_client_port, system:HTTP_client_port);
}

function server_TC() runs on HTTP_server
{
  var Listen listen := { local_hostname := omit, portnumber := HttpServerListenPort, use_ssl := HttpServerUseSSL };
  var HTTPResponse resp := { client_id := omit, version_major := 1, version_minor := 1, statuscode := 200, statustext := "OK",
    header := { { header_name := "Server", header_value := "TTCN Test Suite simulated HTTP/1.1 server" },
      { header_name := "Content-Length", header_value := "643" } },
    body := "<?xml version= '1.0' encoding='ISO-8859-1' standalone='yes'?>\n<!DOCTYPE ANS>\n<ANS ver=\"3.00\">\n<LIA>\n<GMT_OFF>+0100</GMT_OFF>\n<POS msid=\"1234512345\">\n<PD>\n<TIME>20000626171825</TIME>\n<ARC>\n<LL_POINT>\n<LAT>N301628</LAT>\n<LONG>W974425</LONG>\n</LL_POINT>\n<IN_RAD>1100</IN_RAD>\n<OUT_RAD>1650</OUT_RAD>\n<START_ANGLE>120</START_ANGLE>\n<STOP_ANGLE>240</STOP_ANGLE>\n</ARC>\n</PD>\n</POS>\n<POS msid=\"1234512346\">\n<PD>\n<TIME>20000626171825</TIME>\n<ARC>\n<LL_POINT>\n<LAT>N301630</LAT>\n<LONG>W974450</LONG>\n</LL_POINT>\n<IN_RAD>0</IN_RAD>\n<OUT_RAD>1650</OUT_RAD>\n<START_ANGLE> 120 </START_ANGLE>\n<STOP_ANGLE>240</STOP_ANGLE>\n</ARC>\n</PD>\n</POS>\n</LIA>\n</ANS>\n\n" };
  var HTTPMessage send_resp := { response := resp };
  var Close c := { client_id := omit };

  map(self:HTTP_server_port, system:HTTP_server_port);

  HTTP_server_port.send(listen);

  timer T_guard := 500.0;
  T_guard.start;
  var boolean ready := false;

  while(ready == false) {
    alt {
      [] HTTP_server_port.receive(recv_req) {
          HTTP_server_port.send(send_resp);
        }
      [] HTTP_server_port.receive(h) {
          HTTP_server_port.send(c);
          ready := true;
          setverdict(pass);
        }
      [] T_guard.timeout {
          setverdict(fail);
        }
    };
  }

  unmap(self:HTTP_server_port, system:HTTP_server_port);
}

//==== Encode decode test ====

function f_singleEncDecCheck( in HTTPMessage p_msg)
{
  var template HTTPMessage tr_expectedMsg := p_msg;
  if(ischosen( p_msg.request ) ){
    tr_expectedMsg.request.client_id := *;
  }
  else if(ischosen( p_msg.response )){
    tr_expectedMsg.response.client_id := *;
  }

  var octetstring vloc_encodedMsg;
  log("Original message:",p_msg);
  log("\n======================\n");
  vloc_encodedMsg := enc_HTTPMessage(p_msg);
  log("Encoded message:",vloc_encodedMsg);

  //==== Request decoding ====
  var HTTPMessage vloc_decodedMsg;
  var integer vl_lengthOfRemainingMsg := dec_HTTPMessage( vloc_encodedMsg, vloc_decodedMsg ); //socket debugging has default value
  log("length of the encoded msg: ", lengthof(vloc_encodedMsg));
  log("length of the remaining msg after encoding:", vl_lengthOfRemainingMsg);
  if(  vl_lengthOfRemainingMsg<lengthof(vloc_encodedMsg))
  {
    log( "The decoded message:", vloc_decodedMsg);

    if(match( vloc_decodedMsg,tr_expectedMsg))
    {
      setverdict(pass);
    }
    else 
    {
      log(match( vloc_decodedMsg,tr_expectedMsg));
      setverdict(fail);
    }
  }
  else
  {
    log( "Decoding not happened");
    setverdict(fail);
  }
}

function f_EncDec() runs on MTC
{

  //=== Request Test ====

  var HeaderLines hd := { {header_name := "Content-Type", header_value := "text/xml"},
    {header_name := "Content-Length", header_value := "510" },
    {header_name := "Expires", header_value := "Sat, 01 Jan 2000 00:00:00 GMT" },
    {header_name := "Pragma", header_value := "no-cache" } };
  var HTTPRequest r := { client_id := omit, method := "POST", uri := "/",
    version_major := 1, version_minor := 0, header := hd, body := "<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?><!DOCTYPE ANS SYSTEM 'file://mpp50_ans.dtd'><ANS ver=\"5.00\"><PUSH_USER><PUSH_ID>clientPush</PUSH_ID><PUSH_PWD>clientPush</PUSH_PWD></PUSH_USER><LPA><GMT_OFF>+0100</GMT_OFF><POS msid=\"4670112345\"><PD><TIME>20040117132719</TIME><POLYGON><LL_POINT><LAT>N100410</LAT><LONG>E0202020</LONG></LL_POINT><LL_POINT><LAT>N101610</LAT><LONG>E0202620</LONG></LL_POINT><LL_POINT><LAT>N101610</LAT><LONG>E0201420</LONG></LL_POINT></POLYGON></PD></POS></LPA></ANS>xy" }; //xy will be fragmented?????

  var HTTPMessage send_req := { request := r };
  f_singleEncDecCheck( send_req );

  //==== Response Test ====
  var HTTPResponse resp := { client_id := omit, version_major := 1, version_minor := 1, statuscode := 200, statustext := "OK",
    header := { { header_name := "Server", header_value := "TTCN Test Suite simulated HTTP/1.1 server" },
      { header_name := "Content-Length", header_value := "643" } },
    body := "<?xml version= '1.0' encoding='ISO-8859-1' standalone='yes'?>\n<!DOCTYPE ANS>\n<ANS ver=\"3.00\">\n<LIA>\n<GMT_OFF>+0100</GMT_OFF>\n<POS msid=\"1234512345\">\n<PD>\n<TIME>20000626171825</TIME>\n<ARC>\n<LL_POINT>\n<LAT>N301628</LAT>\n<LONG>W974425</LONG>\n</LL_POINT>\n<IN_RAD>1100</IN_RAD>\n<OUT_RAD>1650</OUT_RAD>\n<START_ANGLE>120</START_ANGLE>\n<STOP_ANGLE>240</STOP_ANGLE>\n</ARC>\n</PD>\n</POS>\n<POS msid=\"1234512346\">\n<PD>\n<TIME>20000626171825</TIME>\n<ARC>\n<LL_POINT>\n<LAT>N301630</LAT>\n<LONG>W974450</LONG>\n</LL_POINT>\n<IN_RAD>0</IN_RAD>\n<OUT_RAD>1650</OUT_RAD>\n<START_ANGLE> 120 </START_ANGLE>\n<STOP_ANGLE>240</STOP_ANGLE>\n</ARC>\n</PD>\n</POS>\n</LIA>\n</ANS>\n\n" };
  var HTTPMessage send_resp := { response := resp };

  f_singleEncDecCheck( send_resp );


}//f_EncDec


function f_EncDec2() runs on MTC {

  var CHARSTRINGS test_msgs := {
    "HTTP/1.1 302 Moved Temporarily\r\nDate: Wed, 22 Feb 2006 13:37:49 GMT\r\nPragma: no-cache\r\nLocation: http://caylem.etm.ericsson.se:7001/McxOwu/list_useractions.jsp?reload\r\nContent-Type: text/html\r\nExpires: Sat, 6 May 1995 12:00:00 GMT\r\nTransfer-Encoding: chunked\r\nCache-Control: no-store, no-cache, must-revalidate\r\nCache-Control: post-check=0, pre-check=0\r\n\r\n014d\r\n<html><head><title>302 Moved Temporarily</title></head>\r\n<body bgcolor=\"#FFFFFF\">\r\n<p>This document you requested has moved temporarily.</p>\r\n<p>It's now at <a href=\"http://caylem.etm.ericsson.se:7001/McxOwu/list_useractions.jsp?reload\">http://caylem.etm.ericsson.se:7001/McxOwu/list_useractions.jsp?reload</a>.</p>\r\n</body></html>\r\n\r\n0000\r\n\r\n",
    "HTTP/1.1 200 OK\r\nDate: Wed, 22 Feb 2006 13:37:49 GMT\r\nContent-Type: text/html\r\nTransfer-Encoding: chunked\r\n\r\n0fe8\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n\r\n<html>\r\n<head>\r\n<title>Presence</title>\r\n\r\n<script>\r\nvar frameset2 = null;\r\nvar frameset1 = null;\r\n\r\nvar winW = 630, winH = 460;\r\n\r\nfunction getWinSize() {\r\n	if (parseInt(navigator.appVersion)>3) {\r\n	 if (navigator.appName==\"Netscape\") {\r\n	  winW = window.innerWidth;\r\n	  winH = window.innerHeight;\r\n	 }\r\n	 if (navigator.appName.indexOf(\"Microsoft\")!=-1) {\r\n	  winW = document.body.offsetWidth;\r\n	  winH = document.body.offsetHeight;\r\n	 }\r\n	}\r\n	//alert(\"winW=\" + winW + \" winH=\" + winH);\r\n}\r\nvar currRow = null;\r\nfunction tr_mouseover(row) {\r\n	if (!row) {\r\n		row = getrow(window.event.srcElement);\r\n		if (!row)return;\r\n	}\r\n	if (row.style.backgroundColor == \"\") {\r\n		row.style.backgroundColor = \"lightgrey\";\r\n	}\r\n}\r\n\r\nfunction tr_mouseout(row) {\r\n	if (!row) {\r\n		row = getrow(window.event.srcElement);\r\n		if (!row)return;\r\n	}\r\n	if (row.style.backgroundColor == \"lightgrey\") {\r\n		row.style.backgroundColor= \"\";\r\n	}\r\n}\r\n\r\nfunction getrow(obj)\r\n{\r\n	while(obj && obj.tagName != \"TR\") obj = obj.parentNode;\r\n	return obj;\r\n}\r\n// Remove leading and trailing white space\r\nfunction trim(txt) {	\r\n	//alert(\"trim=\" + txt);\r\n	\r\n	try {\r\n		return txt.replace(/(^ +)|( +$)|(\t)/g,\"\");\r\n	} catch (e) {\r\n		var x = new String(txt);\r\n			//alert(\"x=\" + x);\r\n		while (x.charAt(0) == \" \") {\r\n			x = x.substring(1);\r\n			if (x.length == 0) return \"\";\r\n			//alert(\"x=\" + x);\r\n		}\r\n		if (x.length == 0) return \"\";\r\n		while (x.charAt(x.length - 1) == \" \") {\r\n			x = x.substring(0, x.length-1);\r\n			if (x.length == 0) return \"\";\r\n		}\r\n	\r\n		return x;	\r\n		\r\n	\r\n	}\r\n\r\n}\r\n\r\nfunction notyetimplemented()\r\n{\r\n	alert(\"not yet implemented\");\r\n}\r\n\r\nfunction logout()\r\n{\r\n	top.frames[\"_owu_hidden\"].location.assign(\"hidden_logout.jsp\");\r\n//	window.parent.frames[\"_owu_hidden\"].location.assign(\"hidden_logout.jsp\");\r\n}\r\nfunction dorefresh()\r\n{\r\n	try {\r\n		top.frames[\"_owu_sidebar\"].location = \"PrepareSidebar?noselect\";\r\n	} catch (e) {\r\n		alert(\"failed to reload frames\" + e.toString());\r\n	}\r\n}\r\n\r\nfunction NumberChanged(obj) {\r\n\r\n	var val = obj.value;\r\n	var leadingplus = false;\r\n	if (val.search(/^\\+/) == 0) {\r\n		leadingplus = true;\r\n		val  = val.substring(1);\r\n	}\r\n	if (val.search(/[^0-9]/) >= 0) { \r\n		//alert(\"Give a number\");\r\n		val = val.replace(/[^0-9]/g, \"\");\r\n		if (leadingplus) {\r\n			obj.value = \"+\" + val;\r\n		} else {\r\n			obj.value = val;\r\n		}\r\n	}\r\n	\r\n}\r\n\r\nvar modalObj, modalFunc, modalWin;\r\nfunction showModal(obj, func, filename, args, args1) {\r\n	var retval = \"\";\r\n//	if (window.showModalDialog) {\r\n//		retval = window.showModalDialog(filename, args, args1);\r\n//	} else {\r\n		modalObj = obj;\r\n		modalFunc = func;\r\n		document.getElementById(\"modalArg\").value = args;\r\n		args1 = args1.replace(/;/g, \",\");\r\n		args1 = args1.replace(/:/g, \"=\");\r\n		args1 = args1.replace(/dialogWidth/g, \"width\");\r\n		args1 = args1.replace(/dialogHeight/g, \"height\");\r\n		args1 = args1.replace(/dialogTop/g, \"top\");\r\n		args1 = args1.replace(/dialogLeft/g, \"left\");\r\n		args1 = args1.replace(/scroll/g, \"scrollbars\");\r\n		\r\n		//alert(\"modal:\" + args1 );\r\n		//alert(\"window.left=\" + window.screen.left + \" window.top=\" + window.screen.top\r\n		//	+ \"\\window.screeX=\" + window.screenX + \" window.screenY=\" + window.screenY);\r\n\r\n		//alert(\"showmodal:\" + args1);\r\n	   	//modalWin = window.open(filename, \" \", args1 );\r\n	   	//filename = \"indexpopup.jsp?\" + filename;\r\n		modalWin = window.open(filename, \"_owu_popup\", args1);\r\n		modalWin.focus();\r\n		\r\n//	}\r\n	return retval;\r\n}\r\n\r\nfunction modalDone() {\r\n	if (modalObj && modalFunc) {\r\n		modalFunc(modalObj,  document.getElementById(\"modalRetval\").value);\r\n	}\r\n}\r\n\r\nfunction goBack() {\r\n	if (window.name == \"_owu_list\") {\r\n		window.location.assign(\"list_catalog.jsp?catalog=catalogue\");\r\n	} else {\r\n		window.history.go(-1);\r\n	}\r\n}\r\nfunction scroll2View(obj)\r\n{\r\n   try {\r\n    var parent = obj.parentNode;\r\n    while (parent && parent.tagName != (\"DIV\")) parent = parent.parentNode;\r\n" &
    // wrapped into max. 8000 columns lines because ClearCase complains about too long lines
    "   \r\n    //alert(\"scroll2view=\" + parent.id);\r\n    var totsize  = parent.offsetHeight;  // this is the visible area \r\n0fe8\r\nsize\r\n    var currtop = parent.scrollTop;      //here begins the visible area\r\n    var beginPos = obj.offsetTop;\r\n    var step = obj.offsetHeight + 3;\r\n   //	alert(\"step=\" + step + \" padding=\" + obj.style.paddingTop);\r\n    var endPos = beginPos + step;\r\n    \r\n    while (endPos > (currtop + totsize))  {\r\n       currtop += step;\r\n    }\r\n    while (beginPos < currtop) {\r\n       currtop -= step;\r\n    }\r\n    parent.scrollTop = currtop;\r\n    //window.status = \"scrolltop=\" + currtop;\r\n   } catch(e) {\r\n      window.status = \"Failed  scroll2view\";\r\n   }\r\n}\r\n\r\n</script>\r\n\r\n<script>\r\n\r\nfunction init() {\r\n	//document.getElementById(\"p_text\").select();\r\n\r\n\r\n		var doreload = \"reload\";\r\n		if (doreload== \"reload\") {\r\n			dorefresh();\r\n		}\r\n		\r\n		var errormsg = \"\";\r\n		if (errormsg != \"\") {\r\n			errormsg = errormsg.replace(/^error=/i, \"\");\r\n			errormsg = errormsg.replace(/\\%20/g, \" \");\r\n			alert(errormsg);\r\n		}\r\n	\r\n}\r\n\r\nfunction removePresence() {\r\n	document.getElementById(\"presence_code\").value = \"0\";\r\n	document.forms[\"presenceform\"].submit();\r\n}\r\n\r\nfunction pcodeChanged(obj) {\r\n	//alert(\"pcodechanged=\" + obj.options[obj.selectedIndex].value);\r\n	var pcodes = obj.options[obj.selectedIndex].value;\r\n	if (pcodes == \"\") return;\r\n	\r\n	var tmp = pcodes.split(\"_\");\r\n	var pcode = tmp[0];\r\n	var number = tmp[1];\r\n	\r\n	var actionimage = document.getElementById(\"actionimage\");\r\n	if (actionimage) {\r\n		if (number == \"\") {\r\n			actionimage.src=\"img/not_available_no_CFP.gif\";\r\n		} else {\r\n			actionimage.src=\"img/not_available_CFP.gif\";\r\n		}\r\n	}\r\n	if (number == \"x\") {\r\n		document.getElementById(\"diversionnbr\").style.display = \"\";\r\n	} else {\r\n		document.getElementById(\"diversionnbr\").style.display = \"none\";\r\n	}\r\n}\r\nfunction setPresence() {\r\n	var pcodelist = document.getElementById(\"pcodelist\");\r\n	if (pcodelist.selectedIndex <0 || pcodelist.options[pcodelist.selectedIndex].value == \"\") {\r\n		alert(\"do pick a valid option\")\r\n		return;\r\n	}\r\n	var pcodes = pcodelist.options[pcodelist.selectedIndex].value ;\r\n	var tmp = pcodes.split(\"_\");\r\n	var pcode = tmp[0];\r\n	var number = tmp[1];\r\n	\r\n	document.getElementById(\"presence_code\").value = pcode;\r\n	if (number == \"x\") {\r\n		number = trim(document.getElementById(\"diversionnbr\").value);\r\n	} \r\n	document.getElementById(\"presence_divertnbr\").value = number;\r\n	\r\n	var until = document.getElementById(\"untildate\").value \r\n				+ \" \" + document.getElementById(\"untiltime\").value;\r\n	until = trim(until);\r\n	if (until != \"\") {\r\n		document.getElementById(\"presence_until\").value = until;\r\n	}\r\n	\r\n	var msgelem  = document.getElementById(\"p_text\");\r\n	//just make sure that the text is not the initial expl. text.\r\n	if (msgelem.onkeydown == null) { \r\n		var ptext = trim(msgelem.value);\r\n		if (ptext != \"\") {\r\n			document.getElementById(\"presence_text\").value = ptext;\r\n		}\r\n	}\r\n	document.forms[\"presenceform\"].submit();\r\n}\r\nfunction presetPresence(idx) {\r\n	document.getElementById(\"presence_preset\").value = idx;\r\n	document.forms[\"presenceform\"].submit();\r\n	\r\n}\r\n\r\nfunction SetDeflect()\r\n{\r\n	var elems = document.getElementsByName(\"cf\");\r\n	for (var i=0; i <elems.length; i++) {\r\n		if (elems[i].checked) {\r\n			var deflectnr = elems[i].value;\r\n			if (deflectnr == \"X\") {\r\n				deflectnr = document.getElementById(\"cf_number\").value;\r\n			}\r\n			document.getElementById(\"calldeflectnr\").value = deflectnr;\r\n			break;\r\n		}\r\n	}\r\n	document.forms[\"calldeflectform\"].submit();\r\n}\r\n\r\nfunction cfClicked(obj) {\r\n	//alert(\"obj=\" + obj.checked);\r\n	if (obj.checked && obj.value == \"X\") {\r\n		document.getElementById(\"cf_number\").style.visibility = \"\";\r\n		document.getElementById(\"cf_number\").focus();\r\n	} else {\r\n		document.getElementById(\"cf_number\").style.visibility = \"hidden\";\r\n	}\r\n}\r\n\r\nfunction ActivateGroups()\r\n{\r\n	document.forms[\"hgsettng\"].submit();\r\n}\r\n\r\nfunction showmoreoptions() {\r\n	document.getElementById(\"moreoptionstable\").style.display = \"\";\r\n	document.getElementById(\"moreoptionsbutton\").style.display = \"\";\r\n}\r\nfunction divmsgChanged(obj) {\r\n	if (parseInt(obj.value.length) > 255) {\r\n		obj.value = obj.value.substring(0,255);\r\n		alert(\"Max 255\");\r\n	\r\n0fe8\r\n}\r\n	//window.status = obj.value.length;\r\n}	\r\nfunction resetUserSettings() \r\n{\r\n	document.forms[\"resetuserform\"].submit();\r\n}\r\n</script>\r\n<style type=\"text/css\">\r\n\r\nbody {\r\n	font-family: verdana, arial;\r\n	font-size: 100%;\r\n	background-image: url(img/body.gif);\r\n	color : black;\r\n}\r\n\r\ntable {\r\n	font-family: verdana, arial;\r\n	font-size: 90%;\r\n}\r\n\r\n.loginform {\r\n	font-size: 90%;\r\n	color : black;\r\n}\r\n.button {\r\n	font-size:80%;\r\n	font-weight:bold;\r\n	padding:1;\r\n}\r\n.mainform {\r\n	color : black;\r\n	background-color:#E0E0E0;\r\n	font-size:70%;\r\n	width:100%;\r\n	height:100%;\r\n	padding:0;\r\n	margin:0;\r\n\r\n}	\r\n.attendantform {\r\n	color : black;\r\n	background-image: url(img/body.gif);\r\n	margin:0;\r\n	padding:0;\r\n	width:100%;\r\n	height:100%;\r\n}\r\n\r\n.maintitle {\r\n	font-weight: bold;\r\n	color : black;\r\n	letter-spacing:1;\r\n	height:50px;\r\n	width:230px;\r\n	padding:0;" &
    "\r\n	margin:0;\r\n	background-image: url(img/top.gif);\r\n}\r\n\r\n.actionmenu {\r\n	font-size: 90%;\r\n	color : black;\r\n	background-color:#E0E0E0;\r\n	margin : 5;\r\n	padding:5;\r\n	width:99%;\r\n\r\n}\r\n.actiondropdown {\r\n	color : black;\r\n}\r\n\r\n.searchform {\r\n	font-size: 90%;\r\n	color : black;\r\n	background-image: url(img/body.gif);\r\n}\r\n\r\n/* Used by the sidebar */\r\n#mainbody {\r\n	height:99%;\r\n	background-color:#E0E0E0; \r\n	min-width:130px;\r\n	left:5;\r\n	top:3;\r\n	position:absolute;\r\n	\r\n}\r\n\r\n.menutree {\r\n	padding:0;\r\n	align:center;\r\n	color: black;\r\n	min-width:230px;\r\n	width:100%;\r\n}\r\n\r\n.settingsbody {\r\n	padding:0;\r\n	align:center;\r\n	color: black;\r\n	min-width:198px;\r\n	width:100%;\r\n	background-image: url(img/body.gif);\r\n	top:70px;\r\n	position:absolute;\r\n	font-weight:normal;\r\n	height:90%;\r\n	font-size:80%;\r\n}\r\n.settingslist {\r\n	font-size:80%;\r\n}\r\n.inputfield {\r\n	font-size:90%;\r\n}\r\n.settingsheading {\r\n	padding:0 0 0 12;\r\n	width:30%;\r\n}\r\n.treerow {\r\n	font-weight:normal;\r\n	font-size:85%;\r\n	vertical-align:text-top;\r\n	padding:3 0 3 0 ;\r\n	margin:0;\r\n	color : black;\r\n	cursor:hand;\r\n	min-height:16px;\r\n}\r\n.rowheading {\r\n	background-color:#CCCCCC;\r\n	font-weight:bold;\r\n	color:black;\r\n	border:3 outset lightgray;\r\n	margin:2px;\r\n	padding-left:5;\r\n	cursor:hand;\r\n	align:center;\r\n}\r\n\r\n#maincatalogbody {\r\n	height:99%;\r\n	background-image: url(img/body.gif);\r\n	width:100%;\r\n	left:5;\r\n	top:3;\r\n	position:absolute;\r\n}\r\n\r\n.imgbutton {\r\n	background-color:#CCCCCC;\r\n	font-weight:bold;\r\n	color:black;\r\n	border:3 outset lightgray;\r\n	margin:2px;\r\n	padding:2;\r\n	cursor:hand;\r\n	align:center;\r\n	font-size:80%;\r\n}\r\n\r\n.numberbutton {\r\n	background-color:#CCCCCC;\r\n	font-weight:normal;\r\n	color:black;\r\n	margin:1px;\r\n	cursor:hand;\r\n	align:center;\r\n	border:3 outset lightgray;\r\n	height:20px;;\r\n	width:120px;\r\n	vertical-align:bottom;\r\n	padding : 0 0 0 5;\r\n	font-size:80%;\r\n	\r\n}\r\n\r\n.numberbuttonpushed {\r\n	background-color:#E0E0E0;\r\n	font-weight:bold;\r\n	/*color:blue;*/\r\n	margin:1px;\r\n	cursor:hand;\r\n	align:center;\r\n	border:3 inset lightgray;\r\n	height:20px;;\r\n	width:120px;\r\n	vertical-align:bottom;\r\n	padding : 0 0 0 5;\r\n	font-size:80%;\r\n	\r\n}\r\n.actionsmallbutton {\r\n	background-color:#CCCCCC;\r\n	font-weight:bold;\r\n	color:black;\r\n	margin:1px;\r\n	cursor:hand;\r\n	align:center;\r\n	font-size:70%;\r\n	border:2 outset lightgray;\r\n	height:11px;\r\n	width:11px;\r\n	vertical-align:bottom;\r\n}\r\n.actionbutton {\r\n	background-color:#CCCCCC;\r\n	font-weight:bold;\r\n	color:black;\r\n	margin:2px;\r\n	cursor:hand;\r\n	align:center;\r\n	font-size:60%;\r\n	border:5 outset lightgray;\r\n	height:25px;\r\n	width:25px;\r\n	vertical-align:top;\r\n}\r\n\r\n.actionbuttonpushed {\r\n	background-color:#E0E0E0;\r\n	font-weight:bold;\r\n	color:black;\r\n	margin:2px;\r\n	align:center;\r\n	font-size:70%;\r\n	border:5 inset lightgray;\r\n	height:25px;\r\n	width:25px;\r\n	vertical-align:top;\r\n	cursor:hand;\r\n	\r\n}\r\n\r\n\r\n.treecell {\r\n	padding:0 0 2 2;\r\n}\r\n.treespacer {\r\n	padding:0;\r\n	margin:0;\r\n	min-height:2px;\r\n	font-size:1px;\r\n	width:200px;\r\n	\r\n}\r\n.popupform {\r\n	align : center;\r\n	font-size: 90%;\r\n	color : black;\r\n	background-image: url(img/body.gif);\r\n}\r\n\r\n.popuptitle {\r\n	font-size: 120%;\r\n	font-weight : bold;\r\n	letter-spacing : 1;\r\n}\r\n.popuptab {\r\n	font-size: 110%;\r\n	letter-spacing : 1;\r\n	border-top : 1 solid black;\r\n	border-right : 1 solid black;\r\n	bor\r\n0438\r\nder-left : 1 solid black;\r\n	padding : 4;\r\n	margin : 8 3 0 3;\r\n	width : 100%;\r\n	height:80%;\r\n	vertical-align:text-top;\r\n	background-color:black;\r\n	align:center;	\r\n	color:black;\r\n	cursor:hand;\r\n}\r\n.tabselected {\r\n	font-size: 110%;\r\n	letter-spacing : 1;\r\n	border : 1 solid black;\r\n	border-bottom : 0;\r\n	padding : 4 4 0 4;\r\n	margin : 0;\r\n	text-align : left;\r\n	vertical-align:text-top;\r\n	align:center;\r\n	background-color:#E0E0E0;\r\n	color:black;\r\n}\r\n\r\n.popupbutton {\r\n	width: 100px;\r\n}\r\n\r\n.resultlist {\r\n	align:center;\r\n	color: black;\r\n	width:100%;\r\n	height:89%;\r\n	overflow:auto;\r\n	position:absolute;\r\n	background-color:#E0E0E0;\r\n	\r\n}\r\n.resultrow {\r\n	font-weight:normal;\r\n	font-size:75%;\r\n	vertical-align:text-top;\r\n	padding:1;\r\n	margin:0;\r\n	color : black;\r\n	cursor:hand;\r\n	min-height:16px;\r\n}\r\n.resultheading {\r\n	background-color:#CCCCCC;\r\n	font-weight:bold;\r\n	color:black;\r\n	border:3 outset lightgray;\r\n	margin:2px;\r\n	padding-left:5;\r\n	cursor:hand;\r\n	align:center;\r\n	font-size:85%;\r\n}\r\n.actiontextarea {\r\n	font-size:90%;\r\n	text-align:left;\r\n	width:100%;\r\n	height:100px;\r\n}\r\n\r\n</style>\r\n0fe8\r\n\r\n\r\n</head>\r\n<body onload=\"init();\" >\r\n\r\n\r\n<div id=\"mainbody\" >\r\n\r\n<form name=\"resetuserform\" target=\"_self\" action=\"servlet/DrsResetUser\" method=\"post\">\r\n<input type=hidden name=\"resetuser_dirid\" id=\"resetuser_dirid\" value=\"3619010001:046182\">\r\n</form>\r\n\r\n<form name=\"presenceform\" target=\"_self\" action=\"DrsPresence\" method=\"post\">\r\n<input type=hidden name=\"presence_code\" id=\"presence_code\" value=\"\">\r\n<input type=hidden name=\"presence_divertnbr\" id=\"presence_divertnbr\" value=\"\">\r\n<input type=hidden name=\"presence_until\" id=\"presence_until\" value=\"\">\r\n<input type=hidden name=\"presence_dirid\" id=\"presence_dirid\" value=\"\">\r\n<input type=hidden name=\"presence_text\" id=\"presence_text\" value=\"\">\r\n<input type=hidden name=\"presence_preset\" id=\"presence_preset\" value=\"\">\r\n</form>\r\n\r\n<div class=\"maintitle\" style=\"width:100%\">\r\n<table cellspacing=0 cellpadding=3 width=\"100%\" >\r\n<tr>\r\n	<td class=\"maintitle\" style=\"width:100%\" align=baseline>\r\n	<img src=\"img/spacer.gif\" height=50 width=2>\r\n	Sambal Bij  (1100)\r\n<!-- toolbox -->\r\n	<td align=right  valign=baseline nowrap> \r\n		\r\n		<span id=\"resetbutton\"  class=\"actionbutton\" onclick=\"resetUserSettings()\"  >\r\n				<img src=\"img/spacer.gif\" width=\"25\" heigth=\"25\">Reset user settings\r\n		</span>\r\n		\r\n		<span id=\"logoutbutton\"  class=\"actionbutton\" onclick=\"logout()\"  >\r\n				<img src=\"img/spacer.gif\" width=\"25\" heigth=\"25\">Log out\r\n		</span>\r\n<tr><td colspan=2><hr>\r\n\r\n</table>\r\n\r\n</div>\r\n\r\n<div class=\"settingsbody\"  id=\"presencemenu\">\r\n\r\n<table  style=\"width:100%;color:black;background-color:#E0E0E0\" border=0 cellpadding=3 cellspacing=2>\r\n<tr><td style=\"width:35%;border:1 solid gray;\">\r\n\r\n	<table  style=\"width:100%;color:black;background-color:#E0E0E0\" border=0 cellpadding=3 cellspacing=2>\r\n		<tr><td  style=\"font-size:100%\"><b>Presence\r\n	\r\n\r\n		<td nowrap>	<img src='img/not_available_no_CFP.gif'>Left for the day\r\n\r\n\r\n	<tr>\r\n		<td colspan=2><hr>\r\n	\r\n\r\n" &
    "		<tr style=\"display:\"><td colspan=2>Predefined options\r\n	\r\n\r\n		<tr  style=\"display:\">\r\n			<td  colspan=2 >\r\n			<span style=\"width:70%\" class='imgbutton' onclick=\"presetPresence('0');\" >\r\n				<img src='img/available.gif' width=16 height=16>Change to Available\r\n			</span>\r\n			<br>\r\n\r\n		<tr  style=\"display:\">\r\n			<td  colspan=2 >\r\n			<span style=\"width:70%\" class='imgbutton' onclick=\"presetPresence('1');\" >\r\n				<img src='img/not_available_no_CFP.gif' width=16 height=16>Change to Busy\r\n			</span>\r\n			<br>\r\n\r\n		<tr  style=\"display:\">\r\n			<td  colspan=2 >\r\n			<span style=\"width:70%\" class='imgbutton' onclick=\"presetPresence('2');\" >\r\n				<img src='img/not_available_no_CFP.gif' width=16 height=16>Change to Meeting\r\n			</span>\r\n			<br>\r\n\r\n		<tr  style=\"display:\">\r\n			<td  colspan=2 >\r\n			<span style=\"width:70%\" class='imgbutton' onclick=\"presetPresence('3');\" >\r\n				<img src='img/not_available_no_CFP.gif' width=16 height=16>Change to Lunch\r\n			</span>\r\n			<br>\r\n\r\n		<tr  style=\"display:\">\r\n			<td  colspan=2 >\r\n			<span style=\"width:70%\" class='imgbutton' onclick=\"presetPresence('4');\" >\r\n				<img src='img/not_available_no_CFP.gif' width=16 height=16>Change to Left for the day\r\n			</span>\r\n			<br>\r\n\r\n		<tr>\r\n		<td  colspan=2><br><hr>\r\n		\r\n		<tr><td ><a href=# onclick=\"showmoreoptions()\" >More options...</a>\r\n		\r\n			<td style=\"display:none\" id=\"moreoptionsbutton\" nowrap align=right><span class=\"imgbutton\" style=\"font-size:75%\" onclick=\"setPresence();\">\r\n					<img id=\"actionimage\" src=\"img/spacer.gif\">&nbsp;&nbsp;\r\n				Change now</span>\r\n		\r\n\r\n		<tr>\r\n		<td colspan=2>\r\n		<table id=\"moreoptionstable\" style=\"display:none\">\r\n		<tr>\r\n			<td colspan=2 valign=top >\r\n			<select style=\"width:100%\" id=\"pcodelist\"  onchange=\"pcodeChanged(this)\" >\r\n			<option value=''>------------------------------------</option>\r\n<option value='1_'>Busy - No diversion\n<option value='1_-1'>Busy - All calls to main number\n<option value='1_-2'>Busy - All calls to voicemail\n<option value='1_x'>Busy - All calls to number\n<option value=''>------------------------------------</option>\n<option value='2_'>Meeting - No diversion\n<option value='2_-1'>Meeting - All calls to\r\n0f53\r\n main number\n<option value='2_-2'>Meeting - All calls to voicemail\n<option value='2_x'>Meeting - All calls to number\n<option value=''>------------------------------------</option>\n<option value='3_'>Lunch - No diversion\n<option value='3_-1'>Lunch - All calls to main number\n<option value='3_-2'>Lunch - All calls to voicemail\n<option value='3_x'>Lunch - All calls to number\n<option value=''>------------------------------------</option>\n<option value='4_'>Left for the day - No diversion\n<option value='4_-1'>Left for the day - All calls to main number\n<option value='4_-2'>Left for the day - All calls to voicemail\n<option value='4_x'>Left for the day - All calls to number\n<option value=''>------------------------------------</option>\n<option value='5_'>Returns - No diversion\n<option value='5_-1'>Returns - All calls to main number\n<option value='5_-2'>Returns - All calls to voicemail\n<option value='5_x'>Returns - All calls to number\n<option value=''>------------------------------------</option>\n\r\n					\r\n			</select>\r\n			<tr><td colspan=2>\r\n				<input type=text value=\"\" onkeyup=\"NumberChanged(this)\" style=\"display:none\" id=\"diversionnbr\">\r\n\r\n	<tr>\r\n	<td style=\"font-size:90%;\" nowrap colspan=2>Back \r\n		<span style=\"font-size:75%\">(MM/dd/yyyy)</span>\r\n			<input type=text id=\"untildate\" value=\"\" size=\"10\">\r\n		<span style=\"font-size:75%\">(HH:mm)</span>\r\n			<input type=text id=\"untiltime\" value=\"\" size=\"5\">\r\n	<tr>\r\n			<td colspan=2 valign=top width=30%><b>Message\r\n		\r\n		<tr >			\r\n			<td colspan=2 valign=top >\r\n			<textarea style=\"width:99%;\" rows=5 classname=\"actiontextarea\"\r\n				id=\"p_text\" onkeydown=\"this.value='';this.onkeydown=null\" onkeyup=\"divmsgChanged(this)\">Here you can write your message to the attendant and others. Max 255 characters.</textarea>\r\n		\r\n		\r\n			</table><!--more options-->\r\n	</table>\r\n\r\n<!-- Call deflect -->\r\n<td style=\"width:35%;border:1 solid gray;display:none\" valign=top>\r\n	<table  style=\"color:black;background-color:#E0E0E0;width:100%\" border=0 cellpadding=3 cellspacing=2>\r\n		<tr><td style=\"font-size:100%\"><b>Deflect call\r\n			<td align=right><input  class=\"imgbutton\" style=\"font-size:80%;\" \r\n				type=\"button\" value=\"Change\" onclick=\"SetDeflect()\" >\r\n			\r\n		<tr><td colspan=2><hr>	\r\n		<tr onmouseover=\"tr_mouseover(this);\" onmouseout=\"tr_mouseout(this)\" class=treerow>\r\n			<td colspan=2><input onclick=\"cfClicked(this);\" type=radio id=\"cf_operator\" name=\"cf\" value=\"-1\" >&nbsp;&nbsp;Main number\r\n		<tr onmouseover=\"tr_mouseover(this);\" onmouseout=\"tr_mouseout(this)\" class=treerow>\r\n			<td colspan=2><input onclick=\"cfClicked(this);\" type=radio id=\"cf_voicemail\" name=\"cf\" value=\"-2\" >&nbsp;&nbsp;Voicemail\r\n		<tr onmouseover=\"tr_mouseover(this);\" onmouseout=\"tr_mouseout(this)\" class=treerow>\r\n			<td colspan=2><input onclick=\"cfClicked(this);\" type=radio id=\"cf_x\" name=\"cf\" value=\"X\" >&nbsp;&nbsp;Phone\r\n			<input type=text name=\"cf_number\" id=\"cf_number\" onkeyup=\"NumberChanged(this);\" style=\"visibility:hidden\" value=\"\">\r\n		\r\n	</table>\r\n\r\n\r\n<form name=\"calldeflectform\" target=\"_self\" action=\"servlet/DrsDeflect\" method=\"post\">\r\n<input type=hidden name=\"dirid\" id=\"dirid\" value=\"\">\r\n<input type=hidden name=\"calldeflectnr\" id=\"calldeflectnr\" value=\"\">\r\n</form>\r\n\r\n<!-- CDG/huntgroups -->\r\n<td style=\"width:35%;border:1 solid gray;\" valign=top>\r\n	<form name=\"hgsettng\" target=\"_self\" action=\"servlet/DrsHuntGroup\" method=\"post\">\r\n	<input type=hidden name=\"dirid\" id=\"dirid\" value=\"\">\r\n	<table  style=\"color:black;background-color:#E0E0E0;width:100%\" border=0 cellpadding=3 cellspacing=2>\r\n		<tr><td style=\"font-size:100%;\"><b>Activate/deactivate <br>Call distribution groups\r\n			<td align=right valign=top><input  class=\"imgbutton\" style=\"font-size:80%;\" \r\n				type=\"button\" value=\"Change\" onclick=\"ActivateGroups()\" >\r\n		<tr><td colspan=2><hr>	\r\n<tr><td>Not member of any call distribution group\n\r\n	</form>\r\n	</table>\r\n\r\n</table>\r\n</div>\r\n</div>\r\n\r\n</body>\r\n</html>\r\n\r\n0000\r\n\r\n"
  };

  var HTTPResponse resp := { client_id := omit, version_major := 1, version_minor := 1, statuscode := 200, statustext := "OK",
    header := { { header_name := "Server", header_value := "TTCN Test Suite simulated HTTP/1.1 server" },
      { header_name := "Content-Length", header_value := int2str(lengthof(test_msgs[0])+ lengthof(test_msgs[1])) } },
    body :=  test_msgs[0] & test_msgs[1] };
  var HTTPMessage send_resp := { response := resp };

  f_singleEncDecCheck( send_resp );

  var octetstring received_reply := '[encoded data, 7554 characters]'O & 
  '[encoded data, 7920 characters]'O & 
  '[encoded data, 7906 characters]'O & 
  '[encoded data, 7910 characters]'O & 
  '[encoded data, 7914 characters]'O & 
  '[encoded data, 4974 characters]'O;

  //

  var integer vl_remainingStringLength := lengthof(received_reply);
  var CHARSTRINGS vl_decodedMessagePieces := {};
  var HTTPMessage vloc_decodedMsg;
  while( vl_remainingStringLength  >0 )
  {
    log("Original msg string length = ", lengthof(received_reply) );
    vl_remainingStringLength:= dec_HTTPMessage( received_reply, vloc_decodedMsg, true)
    log(" The decoded message Piece = ", vloc_decodedMsg );
    log("remaining msg string length:", vl_remainingStringLength);
  }


}//eof  TC


  function singleTC() runs on HTTP_client
  {
    // These may be declared as templates at global scope.
    // Variables are used for performance reasons:
    //     sending is faster in this way.
    var HeaderLines hd := { {header_name := "Host", header_value := HttpServerHostName},
      {header_name := "Content-Length", header_value := "0" } };
    //        {header_name := "Connection", header_value := "close" } 

    var HTTPRequest r := { client_id := omit, method := "GET", uri := "/", 
      version_major := 1, version_minor := 1, header := hd, body := "" };

    var HTTPMessage send_req := { request := r };
    var Connect conn := { hostname := HttpServerHostName,
      portnumber := HttpServerPort, use_ssl := HTTPClientUseSSL };
    var Close c := { client_id := omit };
    timer T_guard := 5.0;
    var integer i;
    var integer how_many_times := 1; //100

    map(self:HTTP_client_port, system:HTTP_client_port);

    HTTP_client_port.send(conn);

    for(i := 0; i < how_many_times; i := i + 1 ) {
      HTTP_client_port.send(send_req);
      if(T_guard.running) { T_guard.stop }
      
      T_guard.start;

      alt {
        [] HTTP_client_port.receive(recv_resp) {
            if(i == how_many_times - 1) {
              HTTP_client_port.send(c);
              setverdict(pass);
            }
          }
        [] HTTP_client_port.receive(h) { 
            HTTP_client_port.send(c);
            setverdict(fail);
            i := how_many_times;
          }
        [] HTTP_client_port.receive {
            HTTP_client_port.send(c); 
            setverdict(fail); 
          }	
        [] T_guard.timeout {
            setverdict(fail); }	
      };
    }

    unmap(self:HTTP_client_port, system:HTTP_client_port);
  }
  //==================================
  //=        Testcases               =
  //==================================


  testcase parallel_TC_client() runs on HTTP_client
  {
    var HTTP_client client_PTC;
    client_PTC := HTTP_client.create;
    client_PTC.start(TC());
    client_PTC.done;
  }

  testcase tc_parallel_server() runs on HTTP_server
  {
    var HTTP_server server_PTC;
    server_PTC := HTTP_server.create;
    server_PTC.start(server_TC());
    server_PTC.done;
  }

  testcase tc_stress(in integer n) runs on HTTP_client
  {
    var ptcList ptc;
    var integer r;

    for( r := 0; r < n; r := r + 1 ) {
      ptc[r] := HTTP_client.create;
    };

    for( r := 0; r < n; r := r + 1 ) {
      ptc[r].start(singleTC());
    };

    for( r := 0; r < n; r := r + 1 ) {
      ptc[r].done;
    };
  }

  testcase tc_stress_Persistent_both() runs on HTTP_client
  {
    var HTTP_client client_PTC;
    client_PTC := HTTP_client.create;
    var HTTP_server server_PTC;
    server_PTC := HTTP_server.create;

    server_PTC.start(server_TC());
    timer t_wait := 0.1;
    t_wait.start;
    t_wait.timeout;
    client_PTC.start(singleTC());

    client_PTC.done;
    server_PTC.done;
  }

  testcase tc_server() runs on HTTP_server
  {
    server_TC();
  }

  testcase tc_client() runs on HTTP_client
  {
    singleTC();
  }


  testcase tc_http_encDec() runs on MTC
  {
    f_EncDec();
  }

  testcase tc_http_encDec2() runs on MTC
  {
    f_EncDec2();
  }
  control
  {
    log("control started");
    //execute(tc_parallel_server());
    //execute(tc_stress(1));
    //execute(tc_stress_Persistent_both());
    //execute(tc_server);
    //execute(tc_client);
    execute(tc_http_encDec());
    execute(tc_http_encDec2());
  }

}
