Previous Topic

Next Topic

Sending the XML header and script body

After the connection is established, the first line of script sent must be an XML document header, which tells the device's HTTPS web server that the following content is an XML script. The header must match the header used in the example exactly. After the header has been completely sent, the remainder of the script can be sent. In this example, the script is sent all at once. For example:

# usage: sendscript(host, script)

# sends the xmlscript script to host, returns reply

sub sendscript($$)

{

my $host = shift;

my $script = shift;

my ($ssl, $reply, $lastreply, $res, $n);

$ssl = openSSLconnection($host);

# write header

$n = Net::SSLeay::ssl_write_all($ssl, '<?xml version="1.0"?>'."\r\n");

rint "Wrote $n\n" if $debug;

# write script

$n = Net::SSLeay::ssl_write_all($ssl, $script);

print "Wrote $n\n$script\n" if $debug;

$reply = "";

$lastreply = "";

READLOOP:

while(1)

{

$n++;

$reply .= $lastreply;

$lastreply = Net::SSLeay::read($ssl);

die_if_ssl_error("ERROR: ssl read");

if($lastreply eq "")

{

sleep(2); # wait 2 sec for more text.

$lastreply = Net::SSLeay::read($ssl);

last READLOOP if($lastreply eq "");

}

sleep(2); # wait 2 sec for more text.

$lastreply = Net::SSLeay::read($ssl);

last READLOOP if($lastreply eq "");

}

print "READ: $lastreply\n" if $debug;

if($lastreply =~ m/STATUS="(0x[0-9A-F]+)"[\s]+MESSAGE=
'(.*)'[\s]+\/>[\s]*(([\s]|.)*?)<\/RIBCL>/)

{

if($1 eq "0x0000")

{

print STDERR "$3\n" if $3;

}

else

{

print STDERR "ERROR: STATUS: $1, MESSAGE: $2\n";

}

}

}

$reply .= $lastreply;

closeSSLconnection($ssl);

return $reply;

}

PERL scripts can also send a portion of the XML script, wait for the reply, and send more XML later. Using this technique, it is possible to use the reply produced by an earlier command as input to a later command. However, the PERL script must send data within a few seconds or the device will time out and disconnect.

When using the XML scripting interface with PERL scripts, the following restrictions apply: