debugging = 1;
# print out incoming hash
if ($webspace) // use html-friendly output
{
echo "at process, incoming data: ";
while (list($key, $value) = each($data))
echo htmlspecialchars($key) . " = " . htmlspecialchars($value, ENT_COMPAT, CHARSET, TRUE) . " \n";
}
else // don't use html output
{
echo "at process, incoming data: \n";
while (list($key, $value) = each($data))
echo "$key = $value\n";
}
reset($data);
}
}
if (isset($data["xml"])) // if XML string is passed in, we'll use it
{
$using_xml = 1;
$xml = $data["xml"];
}
else
{
// otherwise convert incoming hash to XML string
$xml = $this->buildXML($data);
}
// then set up transaction variables
$key = $data["keyfile"];
$host = $data["host"];
$port = $data["port"];
# FOR PERFORMANCE, Use the 'extensions' statement in your php.ini to load
# this library at PHP startup, then comment out the next seven lines
// load library
if (!extension_loaded('liblphp'))
{
if (!dl('liblphp.so'))
{
exit("cannot load liblphp.so, bye\n");
}
}
if ($this->debugging)
{
if ($webspace)
echo " sending xml string: " . htmlspecialchars($xml, ENT_COMPAT, CHARSET, TRUE) . "
";
else
echo "\nsending xml string:\n$xml\n\n";
}
// send transaction to LSGS
$retstg = send_stg($xml, $key, $host, $port);
if (strlen($retstg) < 4)
exit ("cannot connect to lsgs, exiting");
if ($this->debugging)
{
if ($this->webspace) // we're web space
echo " server responds: " . htmlspecialchars($retstg, ENT_COMPAT, CHARSET, TRUE) . "
";
else // not html output
echo "\nserver responds:\n $retstg\n\n";
}
if ($using_xml != 1)
{
// convert xml response back to hash
$retarr = $this->decodeXML($retstg);
// and send it back to caller
return ($retarr);
}
else
{
// send server response back
return $retstg;
}
}
#####################################################
#
# F U N C T I O N c u r l _ p r o c e s s ( )
#
# process hash table or xml string table using
# curl, either with PHP built-in curl methods
# or binary executable curl
#
#####################################################
function curl_process($data)
{
$using_xml = 0;
$webspace = 1;
if (isset($data["webspace"]))
{
if ($data["webspace"] == "false") // if explicitly set to false, don't use html output
$webspace = 0;
}
if (isset($data["debugging"]) || isset($data["debug"]) )
{
if ($data["debugging"] == "true" || $data["debug"] == "true" )
{
$this->debugging = 1;
# print out incoming hash
if ($webspace) // use html-friendly output
{
echo "at curl_process, incoming data: ";
while (list($key, $value) = each($data))
echo htmlspecialchars($key) . " = " . htmlspecialchars($value) . " \n";
}
else // don't use html output
{
echo "at curl_process, incoming data: \n";
$this->sendData = "\nat curl_process, incoming data: \n";
while (list($key, $value) = each($data)) {
echo "$key = $value\n";
if ($key != 'cardnumber' && $key != 'cvmvalue') $this->sendData .= "$key = $value\n";
}
}
reset($data);
}
}
// for logging purposes:
$this->sendData = "";
while (list($key, $value) = each($data)) {
if ($key != 'cardnumber' && $key != 'cvmvalue' && $key != 'keyfile') $this->sendData .= "$key = " . (is_array($value) ? print_r($value, true) : $value) . "\n";
if ($key == 'cardnumber' || $key == 'cvmvalue') $this->sendData .= "$key = ******\n";
if ($key == 'keyfile') $this->sendData .= "$key = **specified**\n";
}
if (isset($data["xml"])) // if XML string is passed in, we'll use it
{
$using_xml = 1;
$xml = $data["xml"];
}
else
{
// otherwise convert incoming hash to XML string
$xml = $this->buildXML($data);
}
if ($this->debugging)
{
if ($webspace)
echo " sending xml string: " . htmlspecialchars($xml, ENT_COMPAT, CHARSET, TRUE) . "
";
else
echo "\nsending xml string:\n$xml\n\n";
$this->xmlString .= "\nsending xml string:\n$xml\n\n";
}
$this->xmlString .= "\nsending xml string:\n$xml\n\n";
// set up transaction variables
$key = $data["keyfile"];
$port = $data["port"];
$host = "https://".$data["host"].":".$port."/LSGSXML";
if (isset($data["cbin"])) //using BINARY curl methods
{
if ($data["cbin"] == "true")
{
if (isset($data["cpath"]))
$cpath = $data["cpath"];
else // curl path has not been set, try to find curl binary
{
if (getenv("OS") == "Windows_NT")
$cpath = "c:\\curl\\curl.exe";
else
$cpath = "/usr/bin/curl";
}
// look for $cargs variable, otherwise use default curl arguments
if (isset($data["cargs"]))
$args = $data["cargs"];
else
$args = "-m 300 -s -S"; // default curl args; 5 min. timeout
# TRANSACT #
if (getenv("OS") == "Windows_NT")
{
if ($this->debugging)
$result = exec ("$cpath -v -d \"$xml\" -E $key -k $host", $retarr, $retnum);
else
$result = exec ("$cpath -d \"$xml\" -E $key -k $host", $retarr, $retnum);
}
else //*nix string
{
if ($this->debugging)
$result = exec ("'$cpath' $args -v -k -E '$key' -d '$xml' '$host'", $retarr, $retnum);
else
$result = exec ("'$cpath' $args -v -k -E '$key' -d '$xml' '$host'", $retarr, $retnum);
}
# EVALUATE RESPONSE #
if (strlen($result) < 2) // no response
{
$result = "FAILURECould not connect.";
return $result;
}
if ($this->debugging)
{
if ($this->webspace)
echo " server responds: " . htmlspecialchars($result, ENT_COMPAT, CHARSET, TRUE) . "
";
else // non html output
echo "\nserver responds:\n $result\n\n";
}
$this->serverResponse .= "\nserver responds:\n $result\n\n";
if ($using_xml == 1)
{
// return xml string straight from server
return ($result);
}
else
{
// convert xml response back to hash
$retarr = $this->decodeXML($result);
// and send it back to caller. Done.
return ($retarr);
}
}
}
else // using BUILT-IN PHP curl methods
{
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL,$host);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt ($ch, CURLOPT_SSLCERT, $key);
curl_setopt ($ch, CURLOPT_CAINFO, $key);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_SSLVERSION, 3);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
if (CURL_PROXY_REQUIRED == 'True') {
$proxy_tunnel_flag = (defined('CURL_PROXY_TUNNEL_FLAG') && strtoupper(CURL_PROXY_TUNNEL_FLAG) == 'FALSE') ? false : true;
curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, $proxy_tunnel_flag);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY, CURL_PROXY_SERVER_DETAILS);
}
if ($this->debugging)
curl_setopt ($ch, CURLOPT_VERBOSE, 1);
# use curl to send the xml SSL string
$result = curl_exec ($ch);
$this->commInfo = @curl_getinfo($ch);
if ($this->debugging)
{
if ($webspace) // html-friendly output
echo " server responds: " . htmlspecialchars(curl_error($ch), ENT_COMPAT, CHARSET, TRUE). ' ErrNo#: ' . curl_errno($ch) . "