Last modified 2 years ago
SOAP SIMPLE Proxy
This software exposes a simple to use SOAP interface for the OpenXCAP server available at http://openxcap.org
It is a transparent proxy for SOAP to XCAP requests relying on XCAP server for authenticating requests.
Bellow is an example for how to use the software with PHP and SOAP package provided by Pear project.
Create a file generate.php as follows:
#!/usr/bin/php
<?
require_once('SOAP/WSDL.php');
$wsdl = new SOAP_WSDL('http://node03.dns-hosting.info:9300/wsdl');
print "<?\n";
print $wsdl->generateAllProxies();
print "?>\n";
?>
Run the script and redirect its output to a file, it will contain the actual library with the SOAP functions that you can call from your main PHP program:
./generate.php > soap_simple_client.php
Bellow is the actual content of the library:
<?
class WebService_SoapSIMPLEProxy_PresencePort extends SOAP_Client
{
function WebService_SoapSIMPLEProxy_PresencePort($path)
{
$this->SOAP_Client($path, 0);
}
function &setPresenceInformation($sipId, $password, $information)
{
// sipId is a ComplexType SipId,
// refer to wsdl for more info
$sipId = new SOAP_Value('sipId', '{urn:AGProjects:SoapSIMPLEProxy}SipId', $sipId);
// information is a ComplexType PresenceInformation,
// refer to wsdl for more info
$information = new SOAP_Value('information', '{urn:AGProjects:SoapSIMPLEProxy}PresenceInformation', $information);
$result = $this->call('setPresenceInformation',
$v = array('sipId' => $sipId, 'password' => $password, 'information' => $information),
array('namespace' => 'urn:AGProjects:SoapSIMPLEProxy:Presence',
'soapaction' => '',
'style' => 'rpc',
'use' => 'encoded'));
return $result;
}
function &getPresenceInformation($sipId, $password)
{
// sipId is a ComplexType SipId,
// refer to wsdl for more info
$sipId = new SOAP_Value('sipId', '{urn:AGProjects:SoapSIMPLEProxy}SipId', $sipId);
$result = $this->call('getPresenceInformation',
$v = array('sipId' => $sipId, 'password' => $password),
array('namespace' => 'urn:AGProjects:SoapSIMPLEProxy:Presence',
'soapaction' => '',
'style' => 'rpc',
'use' => 'encoded'));
return $result;
}
function &deletePresenceInformation($sipId, $password)
{
// sipId is a ComplexType SipId,
// refer to wsdl for more info
$sipId = new SOAP_Value('sipId', '{urn:AGProjects:SoapSIMPLEProxy}SipId', $sipId);
$result = $this->call('deletePresenceInformation',
$v = array('sipId' => $sipId, 'password' => $password),
array('namespace' => 'urn:AGProjects:SoapSIMPLEProxy:Presence',
'soapaction' => '',
'style' => 'rpc',
'use' => 'encoded'));
return $result;
}
function &getWatchers($sipId, $password)
{
// sipId is a ComplexType SipId,
// refer to wsdl for more info
$sipId = new SOAP_Value('sipId', '{urn:AGProjects:SoapSIMPLEProxy}SipId', $sipId);
$result = $this->call('getWatchers',
$v = array('sipId' => $sipId, 'password' => $password),
array('namespace' => 'urn:AGProjects:SoapSIMPLEProxy:Presence',
'soapaction' => '',
'style' => 'rpc',
'use' => 'encoded'));
return $result;
}
function &setPolicy($sipId, $password, $policy)
{
// sipId is a ComplexType SipId,
// refer to wsdl for more info
$sipId = new SOAP_Value('sipId', '{urn:AGProjects:SoapSIMPLEProxy}SipId', $sipId);
// policy is a ComplexType PresencePolicy,
// refer to wsdl for more info
$policy = new SOAP_Value('policy', '{urn:AGProjects:SoapSIMPLEProxy}PresencePolicy', $policy);
$result = $this->call('setPolicy',
$v = array('sipId' => $sipId, 'password' => $password, 'policy' => $policy),
array('namespace' => 'urn:AGProjects:SoapSIMPLEProxy:Presence',
'soapaction' => '',
'style' => 'rpc',
'use' => 'encoded'));
return $result;
}
function &getPolicy($sipId, $password)
{
// sipId is a ComplexType SipId,
// refer to wsdl for more info
$sipId = new SOAP_Value('sipId', '{urn:AGProjects:SoapSIMPLEProxy}SipId', $sipId);
$result = $this->call('getPolicy',
$v = array('sipId' => $sipId, 'password' => $password),
array('namespace' => 'urn:AGProjects:SoapSIMPLEProxy:Presence',
'soapaction' => '',
'style' => 'rpc',
'use' => 'encoded'));
return $result;
}
}
?>
Now you have the functions you can call from your program, the following scripts just calls the functions for a given user you can supply in the command line as arguments:
#!/usr/bin/php
<?
if (!count($argv) || count($argv) != 3) {
printf ("Syntax: %s user@domain password\n",$_SERVER['PHP_SELF']);
exit;
}
$url='Set You SOAP Server URL here';
include("SOAP/Client.php");
require("soap_simple_client.php");
$PresencePort = new WebService_SoapSIMPLEProxy_PresencePort($url);
$PresencePort->setOpt('curl', CURLOPT_CONNECTTIMEOUT, 5);
list($username,$domain)=explode("@",trim($argv[1]));
$password=trim($argv[2]);
print "Information\n";
$result = $PresencePort->getPresenceInformation(array("username" =>$username,"domain" =>$domain),$password);
if (PEAR::isError($result)) {
$error_msg=$result->getMessage();
$error_fault=$result->getFault();
$error_code=$result->getCode();
print "$error_msg\n";
printf ("%s %s\n",$error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
exit;
} else {
print_r($result);
}
// getWatchers
print "Watchers\n";
$result = $PresencePort->getWatchers(array("username" =>$username,"domain" =>$domain),$password);
if (PEAR::isError($result)) {
$error_msg=$result->getMessage();
$error_fault=$result->getFault();
$error_code=$result->getCode();
print "$error_msg\n";
printf ("%s %s\n",$error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
exit;
} else {
print_r($result);
}
// getPolicy
print "Policy\n";
$result = $PresencePort->getPolicy(array("username" =>$username,"domain" =>$domain),$password);
if (PEAR::isError($result)) {
$error_msg=$result->getMessage();
$error_fault=$result->getFault();
$error_code=$result->getCode();
print "$error_msg\n";
printf ("%s %s\n",$error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring);
exit;
} else {
print_r($result);
}
