diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..bd06500
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,8 @@
+/examples export-ignore
+/vendor export-ignore
+/docs export-ignore
+/tests export-ignore
+/.gitattributes export-ignore
+/.gitignore export-ignore
+/.travis.yml export-ignore
+/phpunit.xml export-ignore
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c9388d8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/.idea/
+
+/vendor/
diff --git a/README.md b/README.md
index ae5f74e..d065767 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# cloudking
-A SOAP Server Engine for PHP 5.2 and higher.
+A SOAP Server Engine for PHP 5.6 and higher.
+
+It supports SOAP 1.1, 1.2 or both. JAVA usually supports 1.1, C# supports both.
-For php 7.0 and higher its not working, so its in ALPHA.
---It doesn't work--
\ No newline at end of file
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..43d1a63
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,22 @@
+{
+ "name": "eftec/cloudking",
+ "type": "library",
+ "description": "A SOAP webserver for PHP",
+ "license": "LGPL",
+ "version": "2.4",
+ "authors": [
+ {
+ "name": "Jorge Castro",
+ "email": "jorge.castro.c@gmail.com"
+ }
+ ],
+ "require": {
+ "php": ">=5.6",
+ "ext-json": "*"
+ },
+ "autoload": {
+ "psr-4": {
+ "eftec\\cloudking\\": "lib/"
+ }
+ }
+}
diff --git a/examples/Example2WSService.php b/examples/Example2WSService.php
new file mode 100644
index 0000000..1cca898
--- /dev/null
+++ b/examples/Example2WSService.php
@@ -0,0 +1,92 @@
+'Caught exception: '. $_exception->getMessage()));
+ }
+ }
+
+ function GetProducto($idProducto) {
+ try {
+
+ $all=$this->getDB();
+ foreach($all as $item) {
+ if($item['idProducto']===$idProducto) {
+ $_Producto=$item;
+ break;
+ }
+ }
+
+ return $_Producto;
+ } catch (Exception $_exception) {
+ return(array("soap:Fault"=>'Caught exception: '. $_exception->getMessage()));
+ }
+ }
+
+ function InsertProducto($Producto) {
+ try {
+
+ $all=$this->getDB();
+ $all[]=$Producto;
+ $this->saveDB($all);
+ return count($all);
+ } catch (Exception $_exception) {
+ return(array("soap:Fault"=>'Caught exception: '. $_exception->getMessage()));
+ }
+ }
+
+ function GetProductos() {
+ try {
+
+ return $this->getDB();
+ } catch (Exception $_exception) {
+ return(array("soap:Fault"=>'Caught exception: '. $_exception->getMessage()));
+ }
+ }
+
+ function factoryProducto($idProduct=0,$nombre='',$precio=0) {
+ $_Producto['idProduct']=$idProduct;
+ $_Producto['nombre']=$nombre;
+ $_Producto['precio']=$precio;
+
+ }
+
+ function factoryProductoArray($Producto=array()) {
+ $_ProductoArray['Producto']=$Producto;
+
+ }
+} // end class
+
+/************************************ Complex Types (Classes) ************************************/
+
+class Producto {
+ var $idProduct; // s:integer
+ var $nombre; // s:string
+ var $precio; // s:integer
+}
+
+class ProductoArray {
+ var $Producto; // tns:Producto
+}
\ No newline at end of file
diff --git a/examples/clientexample2.php b/examples/clientexample2.php
new file mode 100644
index 0000000..1972186
--- /dev/null
+++ b/examples/clientexample2.php
@@ -0,0 +1,51 @@
+
+
+use eftec\cloudking\CloudKingClient;
+
+include "../vendor/autoload.php";
+
+
+$x=new ExampleCLient();
+echo "
";
+var_dump($x->GetProductos());
+echo "
";
+/***************************************** Implementation *****************************************/
+class ExampleCLient {
+ var $url='http://localhost/currentproject/cloudking/examples/example2.php';
+ var $tempuri='examplenamespace';
+
+ // Descripcion :Prueba de conexion
+ // ping_param =
+ function ping($ping_param) {
+ $_obj=new CloudKingClient();
+ $_obj->soap='1.1';
+ $_obj->tempuri=$this->tempuri;
+ $_param='';
+ $_param.=$_obj->array2xml($ping_param,'ts:ping_param',false,false);
+ $resultado=$_obj->loadurl($this->url,$_param,'ping');
+ return @$resultado['pingResult'];
+ }
+
+ // Descripcion :GetSin obtiene los datos de una SIN
+ // idProducto =
+ function GetProducto($idProducto) {
+ $_obj=new CloudKingClient();
+ $_obj->soap='1.1';
+ $_obj->tempuri=$this->tempuri;
+ $_param='';
+ $_param.=$_obj->array2xml($idProducto,'ts:idProducto',false,false);
+ $resultado=$_obj->loadurl($this->url,$_param,'GetProducto');
+ return @$resultado['GetProductoResult'];
+ }
+
+ // Descripcion :Get_sin obtiene los datos de una SIN
+ function GetProductos() {
+ $_obj=new CloudKingClient();
+ $_obj->soap='1.1';
+ $_obj->tempuri=$this->tempuri;
+ $_param='';
+ $resultado=$_obj->loadurl($this->url,$_param,'GetProductos');
+ return @$resultado['GetProductosResult'];
+ }
+} // end Sin_WS
+?>
\ No newline at end of file
diff --git a/csin.class.php b/examples/csin.class.php
similarity index 99%
rename from csin.class.php
rename to examples/csin.class.php
index db94266..401a297 100644
--- a/csin.class.php
+++ b/examples/csin.class.php
@@ -312,7 +312,7 @@ function GetSins($filtro,&$error) {
$cuenta_zonas++;
}
if($cuenta_zonas>1){
- $desc_zonas=substr(substr($desc_zonas,0,strlen($desc_zonas)-1),0,25).'...(más)';
+ $desc_zonas=substr(substr($desc_zonas,0,strlen($desc_zonas)-1),0,25).'...(m�s)';
}else {
$desc_zonas=substr($desc_zonas,0,strlen($desc_zonas)-1);
}
@@ -332,7 +332,7 @@ function GetSins($filtro,&$error) {
$cuenta_ciudades++;
}
if ($cuenta_ciudades>1){
- $desc_ciudades=substr(substr($desc_ciudades,0,strlen($desc_ciudades)-1),0,25).'...(más)';
+ $desc_ciudades=substr(substr($desc_ciudades,0,strlen($desc_ciudades)-1),0,25).'...(m�s)';
}else{
$desc_ciudades=substr($desc_ciudades,0,strlen($desc_ciudades)-1);
}
@@ -352,7 +352,7 @@ function GetSins($filtro,&$error) {
$cuenta_localidades++;
}
if($cuenta_localidades>1){
- $desc_localidades=substr(substr($desc_localidades,0,strlen($desc_localidades)-1),0,25).'...(más)';
+ $desc_localidades=substr(substr($desc_localidades,0,strlen($desc_localidades)-1),0,25).'...(m�s)';
}else{
$desc_localidades=substr($desc_localidades,0,strlen($desc_localidades)-1);
}
diff --git a/examples/data.txt b/examples/data.txt
new file mode 100644
index 0000000..169dfd3
--- /dev/null
+++ b/examples/data.txt
@@ -0,0 +1 @@
+a:3:{i:0;a:3:{s:10:"idProducto";s:1:"2";s:6:"nombre";s:1:"3";s:6:"precio";s:1:"4";}i:1;a:3:{s:10:"idProducto";s:1:"2";s:6:"nombre";s:1:"3";s:6:"precio";s:1:"4";}i:2;a:3:{s:10:"idProducto";s:1:"6";s:6:"nombre";s:6:"fdfdfd";s:6:"precio";s:6:"dffdfd";}}
\ No newline at end of file
diff --git a/examples/example2.php b/examples/example2.php
new file mode 100644
index 0000000..40e4886
--- /dev/null
+++ b/examples/example2.php
@@ -0,0 +1,80 @@
+
+
+use eftec\cloudking\CloudKing;
+
+@session_start();
+
+include "../vendor/autoload.php";
+include "Example2WSService.php";
+
+$service=new Example2WSService();
+//$objws->GetSin
+
+
+$FILE = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"];
+$NAMESPACE="examplenamespace";
+$NAME_WS='Example2WS';
+
+
+$ns=new CloudKing($FILE, $NAMESPACE, $NAME_WS);
+
+$ns->soap12=false;
+$ns->verbose=2;
+$ns->allowed_format["POST"]=true;
+//$ns->allowed_format["GET"]=false;
+$ns->variable_type="array";
+$ns->serviceInstance=$service;
+$ns->description="Ejemplo servidor SOAPUI";
+
+$ns->addfunction("ping",
+ array(
+ CloudKing::argPrim('ping_param', 's:string'),
+ ),
+ array(
+ CloudKing::argPrim('return', 's:string')
+ ),
+ "Descripcion :Prueba de conexion"
+ );
+$ns->addfunction("GetProducto",
+ [
+ CloudKing::argPrim('idProducto', 's:integer')
+ ],
+ [
+ CloudKing::argComplex('return', 'tns:Producto')
+ ],
+ "Descripcion :obtiene los datos de una objeto"
+ );
+$ns->addfunction("InsertProducto",
+ array(
+ CloudKing::argComplex('Producto', 'tns:Producto')
+ ),
+ array(
+ CloudKing::argPrim('return', 's:boolean')
+ ),
+ "Descripcion :obtiene los datos de una objeto"
+);
+$ns->addfunction("GetProductos",
+ [
+
+ ],
+ [
+ CloudKing::argList('return', 'tns:Producto', 0, 'unbounded')
+ ],
+ "Descripcion :Obtiene una lista de productos"
+ );
+
+// ***** type
+$ns->addtype("Producto",
+ [
+ CloudKing::argPrim('idProduct','s:integer'),
+ CloudKing::argPrim('nombre','s:string'),
+ CloudKing::argPrim('precio','s:integer')
+ ]);
+$ns->addtype("ProductoArray",
+ array(
+ CloudKing::argList('Producto','tns:Producto','0','unbounded')
+ ));
+
+$r=$ns->run();
+echo $r;
+exit;
diff --git a/generic_client.php b/examples/generic_client.php
similarity index 96%
rename from generic_client.php
rename to examples/generic_client.php
index 930bf80..cba170f 100644
--- a/generic_client.php
+++ b/examples/generic_client.php
@@ -1,19 +1,21 @@
-include_once "./wslib/ckclient.2.3.php";
+use eftec\cloudking\CloudKingClient;
+
+include "../vendor/autoload.php";
/***************************************** Implementation *****************************************/
-class Sin_WSClient {
- var $url='http://localhost/currentproject/cloudking/webservice_example.php';
- var $tempuri='http://localhost/currentproject/cloudking/webservice_example.php/';
+class ExampleCLient {
+ var $url='http://desannoc.vtr.cl/jcastro/sinws/webservice1.php';
+ var $tempuri='http://desannoc.vtr.cl/jcastro/sinws/webservice1.php/';
// Descripcion :Prueba de conexion
// ping_param =
function ping($ping_param) {
- $_obj=new CKClient();
+ $_obj=new CloudKingClient();
$_obj->tempuri=$this->tempuri;
$_param='';
$_param.=$_obj->array2xml($ping_param,'ts:ping_param',false,false);
@@ -262,7 +264,7 @@ function GetCombo_pat_localidad($codi_localidad) {
}
} // end Sin_WS
-$obj=new Sin_WSClient();
+$obj=new ExampleCLient();
echo "llamando al webservice, funcion ping con parametro string
";
diff --git a/webservice_example.php b/examples/webservice_example.php
similarity index 100%
rename from webservice_example.php
rename to examples/webservice_example.php
diff --git a/lib/CloudKing.php b/lib/CloudKing.php
new file mode 100644
index 0000000..6d819ac
--- /dev/null
+++ b/lib/CloudKing.php
@@ -0,0 +1,2115 @@
+ true, "rest" => true, "php" => true, "xml" => true, "none" => true);
+ /**
+ * If the service is not set, then it will be unable to answer any call.
+ * @var null|object
+ */
+ var $serviceInstance = null;
+ var $oem = false;
+ var $encoding = "UTF-8";
+ var $custom_wsdl = "";
+ var $copyright = "";
+ var $description = "CLOUDKING Server is running in this machine";
+ var $verbose = 0;
+ var $wsse_username = "";
+ var $wsse_password = "";
+ var $wsse_nonce = "";
+ var $wsse_created = ""; // ISO-8859-1
+ var $wsse_password_type = "None";
+ var $variable_type = "array"; //Copyright (c)2009 - 2020, SouthProject www.southprojects.com";
+ var $allowed = array("*");
+ var $disallowed = array("");
+ protected $FILE;
+ protected $NAMESPACE;
+ protected $NAME_WS;
+ protected $operation; //None, PasswordDigest, PasswordText
+ protected $complextype; // array or object. it define if the implementation will use array (or primitives) or objects
+
+ protected $predef_types = [
+ "string",
+ "long",
+ "int",
+ "integer",
+ "boolean",
+ "decimal",
+ "float",
+ "double",
+ "duration",
+ "dateTime",
+ "time",
+ "date",
+ "gYearMonth",
+ "gYear",
+ "gMonthDay",
+ "gDay",
+ "gMonth",
+ "hexBinary",
+ "base64Binary",
+ "anyURI",
+ "QName",
+ "NOTATION"
+ ];
+ protected $predef_typesNS = [
+ "s:string",
+ "s:long",
+ "s:int",
+ "s:integer",
+ "s:boolean",
+ "s:decimal",
+ "s:float",
+ "s:double",
+ "s:duration",
+ "s:dateTime",
+ "s:time",
+ "s:date",
+ "s:gYearMonth",
+ "s:gYear",
+ "s:gMonthDay",
+ "s:gDay",
+ "s:gMonth",
+ "s:hexBinary",
+ "s:base64Binary",
+ "s:anyURI",
+ "s:QName",
+ "s:NOTATION"
+ ];
+ protected $predef_types_num = array(
+ "long",
+ "int",
+ "integer",
+ "boolean",
+ "decimal",
+ "float",
+ "double",
+ "duration"
+ );
+
+ public function __construct($FILE, $NAMESPACE = "http://test-uri/", $NAME_WS = "CKService1") {
+ $this->_CKLIB($FILE, $NAMESPACE, $NAME_WS);
+ }
+
+ private function _CKLIB($FILE, $NAMESPACE, $NAME_WS) {
+
+ if (@$_SERVER["HTTPS"]) {
+ $FILE = str_replace("http://", "https://", $FILE);
+ }
+ $this->FILE = $FILE;
+
+
+ $this->NAMESPACE = ($NAMESPACE != "") ? $NAMESPACE : $FILE . "/";
+ $this->NAME_WS = ($NAME_WS != "") ? $NAME_WS : "CKService1";
+ $this->operation = array();
+ $this->complextype = array();
+ $this->custom_wsdl = $this->FILE . "?wsdl";
+ }
+
+ public static function argList($name = 'return', $type = 'tns:*', $minOccurs = 0, $maxOccurs = 'unbounded') {
+ return ["name" => $name, "type" => $type, "minOccurs" => $minOccurs, "maxOccurs" => $maxOccurs];
+ }
+
+ /**
+ * @param string $name
+ * @param string $type=$this->predef_typesNS[$i]
+ * @param bool $byref
+ * @return array
+ */
+ public static function argPrim($name = 'return', $type = 's:*', $byref = false) {
+ return ["name" => $name, "type" => $type, "byref" => false];
+ }
+
+ public static function argComplex($name = 'return', $type = 'tns:*', $byref = false) {
+ return ["name" => $name, "type" => $type, "byref" => false];
+ }
+
+ public function set_copyright($copyright) {
+ $this->copyright = $copyright;
+ }
+
+ public function save_wsdl($filename) {
+ return $this->save_wsdl($filename);
+ }
+
+ public function password_correct($password, $type = "None") {
+ if ($type != $this->wsse_password_type) {
+ return false; // method not equal
+ }
+ if ($this->wsse_password_type == "PasswordDigest") {
+ $wsse_nonce = $this->wsse_nonce;
+ $wsse_created = $this->wsse_created;
+ $nonce = base64_decode($wsse_nonce);
+ $password_digest = base64_encode(sha1($nonce . $wsse_created . $password, true));
+ return ($this->wsse_password == $password_digest);
+ }
+ if ($this->wsse_password_type == "PasswordText") {
+ return ($this->wsse_password == $password);
+ }
+ return true;
+ }
+
+ public function run() {
+ return $this->_run();
+ }
+
+ private function _run() {
+ $result = '';
+ if (!$this->security()) {
+ return false;
+ }
+ global $_REQUEST;
+ $param = @$_SERVER['QUERY_STRING'] . "&=";
+ $p = strpos($param, "&");
+ $p1 = strpos($param, "=");
+ $paraminit = substr($param, 0, min($p, $p1)); // ?{value}&other=aaa
+
+
+ //$HTTP_RAW_POST_DATA=@$GLOBALS['HTTP_RAW_POST_DATA'];
+ $HTTP_RAW_POST_DATA = file_get_contents('php://input');
+
+
+ $isget = false;
+ $methodcalled = ($paraminit == "") ? "soap" : $paraminit;
+ $methoddefined = false;
+ if (strlen($methodcalled) >= 3) {
+ if (substr($methodcalled, 0, 3) == "get" and $this->get) {
+ $methodcalled = str_replace("get", "", $methodcalled);
+ $methodcalled = ($methodcalled == "" ? "none" : $methodcalled);
+ $isget = true;
+ $methoddefined = true;
+ }
+ }
+ if (strlen($methodcalled) >= 4) {
+ if (substr($methodcalled, 0, 4) == "post" and $this->post) {
+ $methodcalled = str_replace("post", "", $methodcalled);
+ $methodcalled = ($methodcalled == "" ? "none" : $methodcalled);
+ $isget = false;
+ $methoddefined = true;
+ }
+ }
+ $info = explode("/", @$_SERVER["PATH_INFO"]);
+ $function_name = (count($info) >= 2) ? $info[1] : "unknown_unknown";
+ $function_out = (count($info) >= 3) ? $info[2] : $methodcalled;
+
+ if (count($info) >= 4 and $this->get) {
+ // is passing more that the functionname and output type 0> is rest myphp?php/functionname/typeout/p1/p2....
+ $isget = true;
+ $methodcalled = "rest";
+ $methoddefined = true;
+ }
+ if ($this->soap12) {
+ if (!$methoddefined and $HTTP_RAW_POST_DATA == "" and $function_name != "unknown_unknown" and $this->get) {
+ // mypage.php/functioname?param1=......
+ $methodcalled = "none";
+ $function_out = "xml";
+ $isget = true;
+ $methoddefined = true;
+ }
+ if (!$methoddefined and $function_name != "unknown_unknown" and $this->post) {
+ // mypage.php/functioname (it must be soap http post).
+
+ $methodcalled = "none";
+ $function_out = "xml";
+ $HTTP_RAW_POST_DATA = " "; // only for evaluation.
+ $isget = false;
+ $methoddefined = true;
+ }
+ }
+ if (!@$this->allowed_input[$methodcalled] and $methoddefined) {
+
+ trigger_error("method $methodcalled not allowed. Did you use SOAP 1.1 or 1.2?", E_USER_ERROR);
+ }
+
+
+ if ($HTTP_RAW_POST_DATA != "" or $isget) {
+ // is trying to evaluate a function.
+
+ // ejemplo :http://www.micodigo.com/webservice.php/functionname/xml?getjson&value1={json..}&value2={json}
+ //info(0)=0
+ //info(1)=functionname
+ //info(2)=serialize return type (optional, by default is the same name as passed)
+
+
+ $res = false;
+ switch ($methodcalled) {
+ case "soap":
+ case "wsdl":
+ $res = $this->requestSOAP($HTTP_RAW_POST_DATA);
+ break;
+ case "json":
+ case "rest":
+ case "php":
+ case "xml":
+ case "none":
+
+ $res = $this->requestNOSOAP($function_name, $function_out, $methodcalled, $isget, $info);
+ break;
+ }
+ if ($res) {
+ $result .= $res;
+ return $result;
+ } else {
+ return false;
+ }
+ } else {
+ switch ($paraminit) {
+ case "wsdl":
+ header("content-type:text/xml;charset=" . $this->encoding);
+ $result .= $this->genwsdl();
+ return $result;
+ break;
+ case "source":
+ if ($this->verbose >= 2) {
+ switch (@$_GET["source"]) {
+ case "php":
+
+ if (method_exists($this, 'genphp')) {
+ header("content-type:text/plain;charset=" . $this->encoding);
+ $result .= $this->genphp();
+ } else {
+ $result .= "not supported
";
+ }
+ break;
+ case "phpclient":
+
+ if (method_exists($this, 'genphpclient')) {
+ header("content-type:text/plain;charset=" . $this->encoding);
+ /** @see \CKLIB_SRC::genphpclient */
+ $result .= $this->genphpclient();
+ } else {
+ $result .= "Not supported
";
+ }
+ break;
+ case "unity":
+ if (method_exists($this, 'genunitycsharp')) {
+ header("content-type:text/plain;charset=" . $this->encoding);
+ $result .= $this->genunitycsharp();
+ } else {
+ $result .= "not supported
";
+ }
+ break;
+ default:
+ if (method_exists($this, 'source')) {
+ header("content-type:text/html");
+ $result .= $this->source();
+ } else {
+ $result .= "not supported
";
+ }
+ break;
+ }
+ return $result;
+ }
+ break;
+ case "unitycsharp":
+ if ($this->verbose >= 2) {
+ header("content-type:text/plain;charset=" . $this->encoding);
+ $result .= $this->genunitycsharp();
+ return $result;
+ }
+ break;
+ }
+
+ }
+ if (method_exists($this, 'gen_description')) {
+ $result .= $this->gen_description();
+ } else {
+ $result .= $this->html_header();
+ $result .= "Name Web Service :" . $this->NAME_WS . "
";
+ $result .= $this->html_footer();
+ }
+ return $result;
+ }
+
+ private function security() {
+ $ip = $_SERVER['REMOTE_ADDR'];
+ $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
+ foreach ($this->disallowed as $value) {
+ if ($value == $hostname or $value == $ip) {
+ echo("host $ip $hostname not allowed (blacklist)\n");
+ return false;
+ }
+ }
+ foreach ($this->allowed as $value) {
+ if ($value == "*" or $value == $hostname or $value == $ip) {
+ return true;
+ }
+ }
+ echo("host $ip $hostname not allowed \n");
+ return false;
+ }
+
+ private function requestSOAP($HTTP_RAW_POST_DATA) {
+ global $param, $r;
+ $soapenv = "";
+ if (strpos($HTTP_RAW_POST_DATA, "http://schemas.xmlsoap.org/soap/envelope/")) {
+ if ($this->soap11) {
+ header("content-type:text/xml;charset=" . $this->encoding);
+ $soapenv = "http://schemas.xmlsoap.org/soap/envelope/";
+ }
+ }
+ if (strpos($HTTP_RAW_POST_DATA, "http://www.w3.org/2003/05/soap-envelope")) {
+ if ($this->soap12) {
+ header("content-type:application/soap+xml;charset=" . $this->encoding);
+ $soapenv = "http://www.w3.org/2003/05/soap-envelope";
+ }
+ }
+ if ($soapenv == "") {
+ die("soap incorrect or not allowed");
+ }
+ $arr = $this->xml2array($HTTP_RAW_POST_DATA, 0);
+ $this->wsse_username = @$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Username"];
+ $this->wsse_password = @$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Password"];
+ $this->wsse_nonce = @$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Nonce"];
+ $this->wsse_created = @$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Created"];
+ $tmp = @$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Password_attr"]["Type"];
+
+ if (strpos($tmp, "#PasswordText")) {
+ $this->wsse_password_type = "PasswordText";
+ } else {
+ if (strpos($tmp, "#PasswordDigest")) {
+ $this->wsse_password_type = "PasswordDigest";
+ } else {
+ $this->wsse_password_type = "None";
+ }
+ }
+
+
+ $funcion = array_keys($arr["Envelope"]["Body"]);
+ $function_name0 = $funcion[0];
+ $function_name = $this->fixtag($function_name0); // "tem:getSix" (deberia ser solo una funcion?)
+ // pasar los parametros
+ $param = array();
+
+ $paramt = " ";
+ $i = 0;
+ $indice_operation = -1;
+ foreach ($this->operation as $key => $value) {
+ if ($value["name"] == $function_name) {
+ $indice_operation = $key;
+ }
+ }
+ if ($indice_operation >= 0) {
+ $my_operation = $this->operation[$indice_operation];
+ foreach ($my_operation["in"] as $value) {
+ $param[] = @$arr["Envelope"]["Body"][$function_name0][$value["name"]];
+ if (empty($param[$i])) {
+ $param[$i] = "";
+ }
+ $paramt .= '@$param[' . $i . '],';
+ $i++;
+ }
+
+ if ($this->variable_type == "object") {
+ // convert all parameters in classes.
+ foreach ($param as $key => $value) {
+ $classname = $my_operation["in"][$key]["type"];
+
+ if (strpos($classname, "tns:", 0) !== false) {
+
+ $param[$key] = $this->array2class($value, $this->fixtag($classname));
+ }
+
+ }
+ }
+ //$param_count = count($param);
+ $paramt = substr($paramt, 0, strlen($paramt) - 1);
+ $r = "";
+
+ if ($this->serviceInstance === null ) {
+ $evalstr = "\$r=$function_name($paramt);";
+ } else {
+ // @eval("global \$" . $this->serviceInstance . ";");
+ $evalstr = "\$r=\$this->serviceInstance->$function_name($paramt);";
+ }
+
+
+ $evalret = eval($evalstr);
+ if ($this->variable_type == "object") {
+ $classname = $my_operation["out"][0]["type"];
+ if (strpos($classname, "tns:", 0) !== false) {
+ //$ttype = $this->fixtag($classname);
+ $r = $this->class2array($r, $this->fixtag($classname));
+
+
+ }
+ //var_dump($r);
+ //$r=@$r[$ttype];
+
+
+ }
+ } else {
+ $evalret = array("soap:Fault" => 'Caught exception: function not defined');
+ }
+ if (!isset($my_operation)) {
+ $evalret = array("soap:Fault" => 'Caught exception: no operation found');
+ return $evalret; // no operation
+ }
+
+ if (is_array($r)) {
+
+ $objectName = @$my_operation["out"][0]["name"];
+ if (!$objectName) {
+ $classname = $my_operation["out"][0]["type"];
+ $objectName = $this->separateNS($classname);
+ }
+
+ // the \n is for fixarray2xml
+ $serial = "\n" . $this->array2xml($r, "array", false, false, $objectName) . "\n";
+ //var_dump($serial);
+ $l = strlen($serial);
+ if ($l > 2) {
+ if (substr($serial, $l - 1, 1) == "\n") {
+ $serial = substr($serial, 0, $l - 1);
+ }
+ }
+
+
+ $serial = $this->fixarray2xml($serial);
+ //var_dump($serial);
+
+
+ if (@$r["soap:Fault"] != "") {
+ $evalret = false;
+ }
+
+ } else {
+ $serial = $r;
+ }
+ // agregamos si tiene valor byref.
+ $extrabyref = "";
+ $indice = 0;
+ $key = $indice_operation;
+ $value = $this->operation[$indice_operation];
+
+ foreach ($value["in"] as $key2 => $value2) {
+ if (@$value2["byref"]) {
+ $paramtmp = @$param[$indice];
+ if (is_array($paramtmp)) {
+ $tmp2 = $this->array2xml($paramtmp, "array", false, false);
+ $tmp2 = $this->fixarray2xml($tmp2);
+ } else {
+ $tmp2 = $paramtmp;
+ }
+ $extrabyref .= "<" . $value2["name"] . ">" . $tmp2 . "" . $value2["name"] . ">";
+ }
+ $indice++;
+ }
+
+
+ if ($evalret !== false) {
+ $resultado = 'encoding . '"?>';
+ $resultado .= '' .
+ "\n";
+ $resultado .= '<' . $function_name . 'Response xmlns="' . $this->NAMESPACE . '">';
+ $resultado .= '<' . $function_name . 'Result>' . $serial . '' . $function_name . 'Result>';
+ $resultado .= $extrabyref;
+ $resultado .= '' . $function_name . 'Response>';
+ $resultado .= '';
+ $resultado .= '';
+ } else {
+ $resultado = '' .
+ "\n";
+ $resultado .= 'soap:Sender' .
+ $function_name . ' failed to evaluate .' . @$r["soap:Fault"] . '';
+ $resultado .= '';
+ }
+
+
+ return $resultado;
+ }
+
+ private function xml2array($contents, $get_attributes = 0, $priority = 'tag') {
+ if (!$contents) {
+ return array();
+ }
+ if (!function_exists('xml_parser_create')) {
+ //print "'xml_parser_create()' function not found!";
+ return array();
+ }
+ //Get the XML parser of PHP - PHP must have this module for the parser to work
+ $parser = xml_parser_create('');
+ xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING,
+ $this->encoding); # http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
+ xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
+ xml_parse_into_struct($parser, trim($contents), $xml_values);
+ xml_parser_free($parser);
+ if (!$xml_values) {
+ return null;
+ } //Hmm...
+ //Initializations
+ $xml_array = array();
+ $parents = array();
+ $opened_tags = array();
+ $arr = array();
+ $current =& $xml_array; //Refference
+ //Go through the tags.
+ $repeated_tag_index = array(); //Multiple tags with same name will be turned into an array
+ foreach ($xml_values as $data) {
+ unset($attributes, $value); //Remove existing values, or there will be trouble
+ //This command will extract these variables into the foreach scope
+ // tag(string), type(string), level(int), attributes(array).
+ extract($data); //We could use the array by itself, but this cooler.
+ $result = array();
+ $attributes_data = array();
+ if (isset($value)) {
+ if ($priority == 'tag') {
+ $result = $value;
+ } else {
+ $result['value'] = $value;
+ } //Put the value in a assoc array if we are in the 'Attribute' mode
+ }
+ //Set the attributes too.
+ if (isset($attributes) and $get_attributes) {
+ foreach ($attributes as $attr => $val) {
+ if ($priority == 'tag') {
+ $attributes_data[$attr] = $val;
+ } else {
+ $result['attr'][$attr] = $val;
+ } //Set all the attributes in a array called 'attr'
+ }
+ }
+ //See tag status and do the needed.
+ $tag = $this->fixtag($tag);
+ if ($type == "open") { //The starting of the tag ''
+ $parent[$level - 1] =& $current;
+ if (!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
+ $current[$tag] = $result;
+ if ($attributes_data) {
+ $current[$tag . '_attr'] = $attributes_data;
+ }
+ $repeated_tag_index[$tag . '_' . $level] = 1;
+ $current =& $current[$tag];
+ } else { //There was another element with the same tag name
+ if (isset($current[$tag][0])) { //If there is a 0th element it is already an array
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
+ $repeated_tag_index[$tag . '_' . $level]++;
+ } else { //This section will make the value an array if multiple tags with the same name appear together
+ $current[$tag] = array(
+ $current[$tag],
+ $result
+ ); //This will combine the existing item and the new item together to make an array
+ $repeated_tag_index[$tag . '_' . $level] = 2;
+ if (isset($current[$tag .
+ '_attr'])) { //The attribute of the last(0th) tag must be moved as well
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
+ unset($current[$tag . '_attr']);
+ }
+ }
+ $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
+ $current =& $current[$tag][$last_item_index];
+ }
+ } elseif ($type == "complete") { //Tags that ends in 1 line ''
+ //See if the key is already taken.
+ if (!isset($current[$tag])) { //New Key
+ $current[$tag] = $result;
+ $repeated_tag_index[$tag . '_' . $level] = 1;
+ if ($priority == 'tag' and $attributes_data) {
+ $current[$tag . '_attr'] = $attributes_data;
+ }
+ } else { //If taken, put all things inside a list(array)
+ if (isset($current[$tag][0]) and is_array($current[$tag])) { //If it is already an array...
+ // ...push the new element into that array.
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
+ if ($priority == 'tag' and $get_attributes and $attributes_data) {
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
+ }
+ $repeated_tag_index[$tag . '_' . $level]++;
+ } else { //If it is not an array...
+ $tmp = $current[$tag];
+ //echo "tag = $tag result = $result current=$tmp
";
+ //var_dump($current);
+ @$current[$tag] = array(
+ $tmp,
+ $result
+ ); //...Make it an array using using the existing value and the new value
+ $repeated_tag_index[$tag . '_' . $level] = 1;
+ if ($priority == 'tag' and $get_attributes) {
+ if (isset($current[$tag .
+ '_attr'])) { //The attribute of the last(0th) tag must be moved as well
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
+ unset($current[$tag . '_attr']);
+ }
+ if ($attributes_data) {
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
+ }
+ }
+ $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
+ }
+ }
+ } elseif ($type == 'close') { //End of tag ''
+ $current =& $parent[$level - 1];
+ }
+ }
+ return ($xml_array);
+ }
+
+ private function array2class($arr, $newclass) {
+ if ($arr == null) {
+ return null;
+ }
+ $object = (object)$arr;
+ if (!class_exists($newclass)) {
+ // We'll save unserialize the work of triggering an error if the class does not exist
+ trigger_error('Class ' . $newclass . ' not found', E_USER_ERROR);
+ }
+ $serialized_parts = explode(':', serialize($object));
+ $serialized_parts[1] = strlen($newclass);
+ $serialized_parts[2] = '"' . $newclass . '"';
+ $result = unserialize(implode(':', $serialized_parts));
+ // aqui recorremos los miembros
+ $idx = $this->findIdxComplexType($newclass);
+ if ($idx == -1) {
+ trigger_error('Complex Type ' . $newclass . ' not found', E_USER_ERROR);
+ }
+ foreach ($this->complextype[$idx]["elements"] as &$value) {
+ if (strpos($value["type"], "tns:", 0) !== false) {
+ $result->$value["name"] = $this->array2class($result->$value["name"], $this->fixtag($value["type"]));
+ }
+ }
+
+ return $result;
+ }
+
+ private function class2array($class, $classname) {
+ if (is_object($class)) {
+ $resultado = (array)$class;
+
+ $idx = $this->findIdxComplexType($classname);
+ foreach ($this->complextype[$idx]["elements"] as &$value) {
+ if (strpos($value["type"], "tns:", 0) !== false) {
+ $this->class2array($resultado[$value["name"]], $this->fixtag($value["type"]));
+ //$tmp=$this->class2array($resultado[$value["name"]], $this->fixtag($value["type"]));
+ //if ($tmp != "") {
+ //$resultado[$value["name"]]=$tmp;
+ //}
+ }
+ }
+ } else {
+ $resultado[$classname] = $class;
+ }
+ return $resultado;
+ }
+
+ private function findIdxComplexType($complexname) {
+
+ foreach ($this->complextype as $key => $value) {
+ if ($value["name"] == $complexname) {
+ return $key;
+ }
+ }
+ return -1;
+
+ }
+
+ protected function fixtag($tag) {
+ $arr = explode(":", $tag);
+ return ($arr[count($arr) - 1]);
+ }
+
+ /**
+ * @param $tnsName
+ */
+ private function separateNS($tnsName) {
+ if (strpos($tnsName, ':') === false) {
+ return $tnsName;
+ }
+ $r = explode(':', $tnsName, 2);
+ return $r[1];
+ }
+
+ function array2xml($array, $name = "root", $contenttype = true, $start = true, $keyx = "") {
+ // \n is important, you should not remove it.
+ if (!is_array($array)) {
+ return $array;
+ }
+
+ $xmlstr = "";
+ if ($start) {
+ if ($contenttype) {
+ @header("content-type:text/xml;charset=" . $this->encoding);
+ }
+ $xmlstr .= 'encoding . "\"?>\n";
+ $xmlstr .= '<' . $name . ">\n";
+ }
+
+ foreach ($array as $key => $child) {
+ if (is_array($child)) {
+ $xmlstr .= (is_string($key)) ? "<" . $key . ">\n" : "<" . $keyx . ">\n";
+ $child = $this->array2xml($child, "", "", false, $key);
+ $xmlstr .= $child;
+ $xmlstr .= (is_string($key)) ? "" . $key . ">\n" : "" . $keyx . ">\n";
+ } else {
+ $type = $this->array2xmltype($child);
+ if ($this->variable_type == "object" and is_object($child)) {
+ $xmlstr .= "<$type>" .
+ $this->array2xml($this->class2array($child, $type), $type, false, false, $key) . "$type>\n";
+ } else {
+ $xmlstr .= '<' . (is_string($key) ? $key : $type) . '>' . $child . '' .
+ (is_string($key) ? $key : $type) . ">\n";
+ }
+ }
+ }
+ if ($start) {
+ $xmlstr .= '' . $name . ">\n";
+ }
+ return $xmlstr;
+ }
+
+ function array2xmltype($value) {
+ if (is_float($value)) {
+ return "float";
+ }
+ if (is_int($value)) {
+ return "int";
+ }
+ if (is_object($value)) {
+ return get_class($value);
+ }
+ return "string";
+ }
+
+ private function fixarray2xml($string) {
+ //if (!is_array($string)) { return $string; }
+ // we remove the first and last element of the xml file so.
+
+ $arr = explode("\n", $string);
+
+ $resultado = "";
+ for ($i = 1; $i < count($arr) - 1; $i++) {
+ $l = trim($arr[$i]);
+ $lant = trim($arr[$i - 1]);
+ if ($l != $lant) {
+ $resultado .= $arr[$i] . "\n";
+ }
+ }
+
+ return $resultado;
+ }
+
+ private function requestNOSOAP($function_name, $function_out, $methodcalled, $isget, $info = array()) {
+ global $param, $r;
+
+
+ $this->wsse_username = @$_POST["Username"];
+ $this->wsse_password = @$_POST["Password"];
+ $this->wsse_nonce = @$_POST["Nonce"];
+ $this->wsse_created = @$_POST["Created"];
+ $tmp = @$_POST["Type"];
+
+ if (strpos($tmp, "#PasswordText")) {
+ $this->wsse_password_type = "PasswordText";
+ } else {
+ if (strpos($tmp, "#PasswordDigest")) {
+ $this->wsse_password_type = "PasswordDigest";
+ } else {
+ $this->wsse_password_type = "None";
+ }
+ }
+ // pasar los parametros
+ $param = array();
+
+ $paramt = "";
+
+ $indice_operation = -1;
+ foreach ($this->operation as $key => $value) {
+ if ($value["name"] == $function_name) {
+ $indice_operation = $key;
+ }
+ }
+ $operation = array("in" => array());
+ if ($indice_operation >= 0) {
+ $i = 0;
+ $operation = $this->operation[$indice_operation];
+ foreach ($operation["in"] as $key => $value) {
+ $tmpvalue = ($isget) ? @$_GET[$value["name"]] : @$_POST[$value["name"]];
+ if ($methodcalled == "rest") {
+ $param[] = @$info[$i + 3];
+ } else {
+ $param[] = $this->decodeNOSOAP($methodcalled, $tmpvalue);
+ }
+ $paramt .= '@$param[' . $i . '],';
+ $i++;
+ }
+ if ($this->variable_type == "object") {
+ // convert all parameters in classes.
+ foreach ($param as $key => $value) {
+ $classname = $operation["in"][$key]["type"];
+ if (strpos($classname, "tns:", 0) !== false) {
+ $param[$key] = $this->array2class($value, $this->fixtag($classname));
+ } else {
+ // not touched.
+ }
+ }
+ }
+ // $param_count = count($param);
+ $paramt = substr($paramt, 0, strlen($paramt) - 1);
+ $r = "";
+ if ($this->serviceInstance == "") {
+ $evalstr = "\$r=$function_name($paramt);";
+ } else {
+ //@eval("global \$" . $this->serviceInstance . ";");
+ $evalstr = "\$r=\$this->serviceInstance->$function_name($paramt);";
+
+ }
+
+ $evalret = eval($evalstr);
+
+ if ($this->variable_type == "object") {
+
+
+ $r = $this->class2array($r, $this->fixtag($operation["out"][0]["type"]));
+
+ }
+ } else {
+ $evalret = array("soap:Fault" => 'Caught exception: function not defined');
+ }
+
+ $max_result = array();
+
+
+ $max_result[$function_name . 'Result'] = $r;
+
+ // agregamos si tiene valor byref.
+ $extrabyref = "";
+ $indice = 0;
+
+ foreach ($operation["in"] as $key2 => $value2) {
+ if (@$value2["byref"]) {
+ $paramtmp = @$param[$indice];
+ $max_result[$value2["name"]] = $paramtmp;
+ $extrabyref .= $value2["name"] . "=" . $paramtmp . "\n";
+
+ }
+ $indice++;
+ }
+
+ if (count($max_result) == 1) {
+
+ $max_result = $r; // if not byref then we returned as a single value
+ }
+
+ if ($evalret !== false) {
+
+ $resultado = $max_result;
+ } else {
+ $resultado = $r;
+ }
+
+
+ $resultado = $this->encodeNOSOAP($function_out, $resultado, $function_name . 'Result');
+ return $resultado;
+ }
+
+ private function decodeNOSOAP($methodcalled, $tmpvalue) {
+ // pass json/xml/php/raw --> return a array or value.
+ $tmp = "";
+ switch ($methodcalled) {
+ case "json":
+ $tmp = json_decode($tmpvalue);
+ break;
+ case "xml":
+ $this->xml2array($tmpvalue, 1);
+ break;
+ case "php":
+ $tmp = @unserialize($tmpvalue);
+ break;
+ case "none":
+ /*if (is_array($tmpvalue)) {
+ $tmpvalue=ex(",",$tmpvalue);
+ }
+ */ $tmp = $tmpvalue; // urlencode is done
+ break;
+ }
+ return $tmp;
+ }
+
+ private function encodeNOSOAP($methodcalled, $tmpvalue, $tmpname) {
+ $tmp = "";
+ switch ($methodcalled) {
+ case "json":
+ $tmp = json_encode($tmpvalue);
+ break;
+ case "xml":
+ if (!is_array($tmpvalue)) {
+ @header("content-type:text/xml;charset=" . $this->encoding);
+ $tmp = '<' . '?' . 'xml version="1.0" encoding="' . $this->encoding . '"' . '?' . '>' . "\n";
+ $tmp .= "<$tmpname>$tmpvalue$tmpname>";
+ } else {
+ $tmp = $this->array2xml($tmpvalue, "array", true, true);
+ }
+ $tmp = $this->fixarray2xml($tmp);
+
+ break;
+ case "php":
+ $tmp = serialize($tmpvalue);
+ break;
+ case "none":
+ if (is_array($tmpvalue)) {
+ $tmp = "";
+ foreach ($tmpvalue as $key => $value) {
+ $tmp .= $key . "=" . $value . "&";
+ }
+ $tmpvalue = $tmp;
+ $tmpvalue = substr($tmpvalue, 0, strlen($tmpvalue) - 1);
+ }
+ $tmp = $tmpvalue;
+ break;
+ }
+ return $tmp;
+ }
+
+ protected function genphp() {
+
+ $r=<<NAME_WS}Service
+ */
+class {$this->NAME_WS}Service {
+cin;
+
+
+ foreach ($this->operation as $key => $value) {
+ $param = "";
+ foreach ($value["in"] as $key2 => $value2) {
+ $param .= ($value2["byref"]) ? "&" : "";
+ $param .= "$" . $value2["name"] . ", ";
+
+ }
+ if ($param != "") {
+ $param = $this->right($param, 2);
+ }
+ $r .= "\n";
+ $r .= "\tfunction " . $value["name"] . "($param) {\n";
+ $r .= "\t\ttry {\n";
+
+ $r .= "\t\t\t// todo: missing implementation \n";
+ $r .= "\t\t\t/*\n";
+ $param = "";
+ foreach ($value["in"] as $key2 => $value2) {
+ $param .= "\t\t\t\$_" . $value2["name"] . "=" .
+ $this->Param2PHPValue($value2["type"], $value2["maxOccurs"]) . ";\n";
+ }
+
+ $r .= $param;
+ $r .= "\t\t\t*/\n";
+ $r .= "\t\t\t// End Input Values \n";
+ foreach ($value["out"] as $key2 => $value2) {
+ $r .= "\t\t\t\$_" . $value["name"] . "Result=" .
+ $this->Param2PHPValue($value2["type"], $value2["maxOccurs"]) . ";\n";
+ }
+ foreach ($value["out"] as $key2 => $value2) {
+
+ $param .= $this->Param2PHPvalue($value2["type"], $value2["maxOccurs"]);
+
+ }
+ //$r.="\t\t \$result=\$_".$value["name"]."Result ".$param."; \n";
+ $r .= "\t\t\t return \$_" . $value["name"] . "Result; \n";
+ $r .= "\t\t} catch (Exception \$_exception) {\n";
+ $r .= "\t\t\treturn(array(\"soap:Fault\"=>'Caught exception: '. \$_exception->getMessage()));\n";
+ $r .= "\t\t}\n";
+ $r .= "\t}\n";
+ }
+ foreach ($this->complextype as $key => $value) {
+
+
+ $r.="\n\t function factory".$value["name"]."("
+ .$this->Param2PHPArg("tns:" . $value["name"], @$value["maxOccurs"],',').") {";
+ $r .= "\n";
+ $r .= $this->Param2PHP("tns:" . $value["name"], @$value["maxOccurs"]) . "\n";
+ $r.="\n\t }\n";
+ }
+ $r .= "} // end class \n ";
+
+ $r .= "\n" . $this->genphpast("Complex Types (Classes)");
+ foreach ($this->complextype as $key => $value) {
+ $r .= "\nclass " . $value["name"] . " {\n";
+ foreach ($value["elements"] as $key2 => $value2) {
+ $r .= "\tvar $" . $value2["name"] . "; // " . $value2["type"] . "\n";
+ }
+ $r .= "}\n";
+ }
+
+
+ return $r;
+ }
+
+ protected function genphpast($text, $lenght = 100) {
+ $L = ($lenght - 6 - strlen($text)) / 2;
+ $L = ($L < 1) ? 1 : $L;
+ $ast = str_repeat("*", $L);
+ return "/*" . $ast . " " . $text . " " . $ast . "*/\n";
+ }
+
+ protected function right($string, $num_cut = 1) {
+ if (strlen($string) - $num_cut >= 0) {
+ return substr($string, 0, strlen($string) - $num_cut);
+ }
+ return $string;
+ }
+
+ protected function Param2PHPvalue($type, $max) {
+ $x1 = explode(":", $type);
+ if (count($x1) != 2) {
+ return "// type $type not defined ";
+ }
+ $space = $x1[0];
+ $name = $x1[1];
+ $p = "";
+ if ($space == "s") {
+ if (!in_array($name, $this->predef_types)) {
+ return "// type $type not found";
+ }
+ if (!in_array($name, $this->predef_types_num)) {
+
+ $p = "''";
+ } else {
+ $p = "0";
+ }
+ }
+ if ($space == "tns") {
+ foreach ($this->complextype as $key => $value) {
+ if ($name == $value["name"]) {
+ $p = '$_' . $name;
+ }
+ }
+ if ($p === "") {
+ return "// complex type $type not found";
+ }
+ }
+ if ($p !== "") {
+ switch ($max) {
+ case "unbounded":
+ return "array($p,$p,...)";
+ break;
+ case "1":
+ return $p;
+ break;
+ default:
+ $tmp = "array(";
+ for ($i = 0; $i < $max; $i++) {
+ $tmp .= $p . ",";
+ }
+ $tmp = $this->right($tmp, 1) . ")";
+ return ($tmp);
+ break;
+ }
+ }
+ return "\\ complex type $type not defined";
+ }
+
+ protected function Param2PHP($type, $max, $separator=";\n",$pre="\t\t") {
+ $x1 = explode(":", $type);
+ if (count($x1) != 2) {
+ return "// type $type not defined ";
+ }
+ $space = $x1[0];
+ $name = $x1[1];
+ if ($space == "s") {
+ if (!in_array($name, $this->predef_types)) {
+ return "// type $type not found";
+ }
+ $p = $this->Param2PHPvalue($type, $max);
+ if ($max == "unbounded") {
+ return "array($p,$p,...)";
+ }
+ if ($max == 1) {
+ return $p;
+ }
+ $tmp = "array(";
+ for ($i = 0; $i < $max; $i++) {
+ $tmp .= $p . ",";
+ }
+ $tmp = $this->right($tmp, 1) . ")";
+ return ($tmp);
+ }
+ $resultado = "";
+ if ($space == "tns") {
+ foreach ($this->complextype as $key => $value) {
+ if ($name == $value["name"]) {
+
+ foreach ($value["elements"] as $key2 => $value2) {
+ $resultado .= $pre."\$_" . $name . "['" . $value2["name"] . "']=$" .
+ $value2["name"] . $separator;
+ //$resultado.="'".$value2["name"]."'=>".$this->Param2PHP($value2["type"],$value2["maxOccurs"]).",";
+ }
+ $resultado = $this->right($resultado);
+ return ($resultado);
+ }
+ }
+ return "\\ complex type $type not defined";
+ }
+ return "";
+ }
+ protected function Param2PHPArg($type, $max, $separator=";\n") {
+ $x1 = explode(":", $type);
+ if (count($x1) != 2) {
+ return "// type $type not defined ";
+ }
+ $space = $x1[0];
+ $name = $x1[1];
+ if ($space == "s") {
+ if (!in_array($name, $this->predef_types)) {
+ return "// type $type not found";
+ }
+ $p = $this->Param2PHPvalue($type, $max);
+ if ($max == "unbounded") {
+ return "array($p,$p,...)";
+ }
+ if ($max == 1) {
+ return $p;
+ }
+ $tmp = "array(";
+ for ($i = 0; $i < $max; $i++) {
+ $tmp .= $p . ",";
+ }
+ $tmp = $this->right($tmp, 1) . ")";
+ return ($tmp);
+ }
+ $resultado = "";
+ if ($space == "tns") {
+ foreach ($this->complextype as $key => $value) {
+ if ($name == $value["name"]) {
+
+ foreach ($value["elements"] as $key2 => $value2) {
+ $resultado .= "\$" . $value2["name"] . "=" .
+ $this->Param2PHPValue($value2["type"], $value2["maxOccurs"]) . $separator;
+ //$resultado.="'".$value2["name"]."'=>".$this->Param2PHP($value2["type"],$value2["maxOccurs"]).",";
+ }
+ $resultado = $this->right($resultado);
+ return ($resultado);
+ }
+ }
+ return "\\ complex type $type not defined";
+ }
+ return "";
+ }
+
+ /**
+ * @return string
+ */
+ protected function genphpclient() {
+
+ $r = "\n";
+ $r .= "include_once 'vendor\.php';\n";
+ $r .= $this->genphpast("Implementation");
+ $r .= "class " . $this->NAME_WS . "Client {\n";
+ $r .= "\tvar \$url='" . $this->FILE . "';\n";
+ $r .= "\tvar \$tempuri='" . $this->NAMESPACE . "';\n";
+ foreach ($this->operation as $key => $value) {
+ $functionname = $value["name"];
+ $param = "";
+ foreach ($value["in"] as $key2 => $value2) {
+ $param .= ($value2["byref"]) ? "&" : "";
+ $param .= "$" . $value2["name"] . ", ";
+
+ }
+ if ($param != "") {
+ $param = $this->right($param, 2);
+ }
+ $r .= "\n\t// " . @$value["description"] . " \n";
+ foreach ($value["in"] as $key2 => $value2) {
+ $varname = $value2["name"];
+ $r .= "\t// $varname = " . @$value2["description"] . " \n";
+ }
+ $r .= "\tfunction $functionname($param) {\n";
+ $r .= "\t\t\$_obj=new CloudKingClient();\n";
+ $r .= "\t\t\$_obj->tempuri=\$this->tempuri;\n";
+ $r .= "\t\t\$_obj->soap='" . ($this->soap11 ? "1.1" : "1.2") . "'\n";
+ $r .= "\t\t\$_param='';\n";
+ foreach ($value["in"] as $key2 => $value2) {
+ $varname = $value2["name"];
+ $r .= "\t\t\$_param.=\$_obj->array2xml(\$$varname,'ts:$varname',false,false);\n";
+ }
+ $r .= "\t\t\$resultado=\$_obj->loadurl(\$this->url,\$_param,'$functionname');\n";
+ foreach ($value["in"] as $key2 => $value2) {
+ if ($value2["byref"]) {
+ $r .= "\t\t\$" . $value2["name"] . "=@\$resultado['" . $value2["name"] . "'];\n";
+ }
+ }
+ $r .= "\t\treturn @\$resultado['" . $functionname . "Result'];\n";
+ $r .= "\t}\n";
+
+ }
+ $r .= "} // end " . $this->NAME_WS . "\n";
+ $r .= "?>\n";
+ return $r;
+ }
+
+ protected function genunitycsharp() {
+ $r = $this->genphpast("Implementation");
+
+ $r .= 'using UnityEngine;
+
+using System.IO;
+using System.Xml.Serialization;
+using System;
+using System.Text;
+using System.Collections;
+using System.Collections.Generic;
+
+public class ' . $this->NAME_WS . ' : MonoBehaviour
+{
+ // Use this for initialization
+ private string charset = "UTF-8";
+ private string url = "' . $this->FILE . '";
+ private string tempuri = "' . $this->NAMESPACE . '";
+ private string prefixns = "ts";
+ public string cookie="";
+ ';
+
+ foreach ($this->operation as $key => $value) {
+ $tmpname = $value["name"];
+ if (count($value["out"]) >= 1) {
+ $outtype = $this->fixtag($value["out"][0]["type"]);
+ $outtypereal = $this->type2csharp($outtype);
+ } else {
+ $outtypereal = "";
+ }
+ $r .= '
+ // ' . $tmpname . '
+ public Boolean is' . $tmpname . 'Running = false;
+ private WWW webservice' . $tmpname . ';
+ public string ' . $tmpname . 'Error="";
+
+ public ' . $outtypereal . ' ' . $tmpname . 'Result;
+ // End ' . $tmpname . '
+';
+ }
+ $r .= ' private void Start()
+ {
+ return;
+ }';
+ foreach ($this->operation as $key => $value) {
+ $tmpname = $value["name"];
+ $param = "";
+ foreach ($value["in"] as $key2 => $value2) {
+ $param .= $this->fixtag($value2["type"]) . " " . $value2["name"] . ",";
+ }
+ $param = $this->right($param, 1);
+ $r .= '
+ private void ' . $tmpname . 'Async(' . $param . ')
+ {
+ string namefunction = "' . $tmpname . '";
+ Single soapVersion=1.1f;
+ string ss2 = SoapHeader(namefunction,soapVersion);';
+
+ foreach ($value["in"] as $key2 => $value2) {
+ $name = $value2["name"];
+ $r .= '
+ ss2 += "<" + prefixns + ":' . $name . '>" + Obj2XML(' . $name . ',true) + "" + prefixns + ":' . $name . '>";
+ ';
+ }
+
+ if (count($value["out"]) >= 1) {
+ $outtype = $this->fixtag($value["out"][0]["type"]);
+ $outtypereal = $this->type2csharp($outtype);
+ $outinit = $this->csharp_init($outtype);
+ } else {
+ $outtype = "";
+ $outtypereal = "";
+ $outinit = '';
+ }
+
+
+ $r .= 'ss2 += SoapFooter(namefunction,soapVersion);
+ is' . $tmpname . 'Running = true;
+ StartCoroutine(' . $tmpname . 'Async2(ss2));
+ }
+ private IEnumerator ' . $tmpname . 'Async2(string ss2) {
+ string namefunction = "' . $tmpname . '";
+ Single soapVersion=1.1f;
+ byte[] bb = System.Text.Encoding.UTF8.GetBytes(ss2);
+ var headers = header(namefunction,soapVersion);
+ if (cookie!="") {
+ headers.Add("Set-Cookie",cookie);
+ }
+ webservice' . $tmpname . ' = new WWW(url, bb, headers);
+ while( !webservice' . $tmpname . '.isDone ) {
+ yield return new WaitForSeconds(0.5f);
+ }
+ is' . $tmpname . 'Running = false;
+ string other = cleanSOAPAnswer(webservice' . $tmpname . '.text, "' . $tmpname . '",ref ' . $tmpname . 'Error);
+ ';
+ if ($outtype != "") {
+ $r .= $tmpname . "Result=" . $outinit . ";\n";
+ $r .= ' ' . $tmpname . 'Result=(' . $outtypereal . ')XML2Obj(other,"' . $outtype . '",' .
+ $tmpname . 'Result.GetType());
+ ';
+ }
+ $r .= 'webservice' . $tmpname . '.responseHeaders.TryGetValue("SET-COOKIE",out cookie);
+ ';
+ $r .= $tmpname . 'AsyncDone();
+ }
+ public void ' . $tmpname . 'AsyncDone() {
+ // we do something...';
+ if ($outtype != "") {
+ $r .= '
+ // ' . $outtypereal . ' dnx=' . $tmpname . 'Result;';
+ }
+ $r .= '
+ }
+ ';
+ }
+
+ $r .= '
+ #region util_function
+ private Hashtable header(string nameFunction,Single soapVersion) {
+ var tmpheader=new Hashtable();
+ if (soapVersion>=1.2) {
+ tmpheader["Content-Type"] = "application/soap+xml;charset" + charset + ";action=\"" + url + "/" + nameFunction +"\"";
+ } else {
+ tmpheader["Content-Type"] = "text/xml;charset" + charset;
+ tmpheader["SOAPAction"]= "\""+ tempuri + "/" + nameFunction +"\"";
+ }
+ return tmpheader;
+ }
+
+
+ private string cleanSOAPAnswer(string text, string functionname,ref string last_error )
+ {
+ int p0, p1, pbody;
+ string tmp = functionname + "Result";
+ pbody = text.IndexOf("");
+ if (pbody<0) {
+ last_error="No soap found";
+ return "";
+ }
+ p0 = text.IndexOf("<" + tmp, pbody);
+ if (p0 <= 0)
+ {
+ return "";
+ }
+ p0 = text.IndexOf(">", p0) + 1;
+ p1 = text.IndexOf("" + tmp, p0);
+ if (p1 < p0)
+ {
+ tmp = "";
+ }
+ else
+ {
+ tmp = text.Substring(p0, p1 - p0);
+ }
+ return tmp;
+ }
+
+ private string SoapHeader(string nameFunction,Single soapVersion)
+ {
+ string ss2;
+ if (soapVersion>=1.2) {
+ ss2 = "";
+ ss2 += "";
+ } else {
+ ss2 = "";
+ ss2 += "";
+ }
+ ss2 += "<" + prefixns + ":" + nameFunction + ">";
+
+ return ss2;
+ }
+
+ private string SoapFooter(string nameFunction,Single soapVersion)
+ {
+ string ss2;
+ ss2 = "" + prefixns + ":" + nameFunction + ">";
+ if (soapVersion>=1.2f) {
+ ss2 += "";
+ } else {
+ ss2 += "";
+ }
+
+ return ss2;
+ }
+
+ private string Obj2XML(object obj)
+ {
+ return Obj2XML(obj, false, false);
+ }
+
+ private string Obj2XML(object obj, Boolean withns)
+ {
+ return Obj2XML(obj, withns, false);
+ }
+
+ private string Obj2XML(object obj, Boolean withns, Boolean full)
+ {
+ string myStr, types;
+
+ if (obj.GetType().Namespace == "System")
+ {
+ types = obj.GetType().Name.ToLower();
+ types = (withns) ? prefixns + ":" + types : types;
+ if (full)
+ {
+ myStr = "<" + types + ">" + obj.ToString() + "" + types + ">";
+ }
+ else
+ {
+ myStr = obj.ToString();
+ }
+ }
+ else
+ {
+ var mstream = new MemoryStream();
+ XmlSerializer SerializerObj = new XmlSerializer(obj.GetType(), tempuri);
+ if (withns)
+ {
+ var namespaces = new XmlSerializerNamespaces();
+ namespaces.Add(prefixns, tempuri);
+ SerializerObj.Serialize(mstream, obj, namespaces);
+ }
+ else
+ {
+ SerializerObj.Serialize(mstream, obj);
+ }
+
+ mstream.Position = 0;
+ var sreader = new StreamReader(mstream);
+ myStr = sreader.ReadToEnd();
+ // cut xml and first node element from the xml
+ if (!full)
+ {
+ var arr = myStr.Split(new char[] {' . "'" . '\n' . "'" . '}, StringSplitOptions.None);
+ //var arr2 = "";
+ int lim = arr.Length - 3;
+ var arr2 = String.Join("", arr, 2, lim);
+ myStr = arr2;
+ }
+ }
+
+ return myStr;
+ }
+ private object XML2Obj(string xmlstr, string typedesc, Type type) {
+ return XML2Obj( xmlstr, typedesc,type,false);
+ }
+ private object XML2Obj(string xmlstr, string typedesc, Type type,Boolean full)
+ {
+ if (!full)
+ {
+ xmlstr = "" + "<" + typedesc + ">" + xmlstr + "" + typedesc + ">";
+ }
+ var objdummy = new object();
+ var SerializerObj = new XmlSerializer(type);
+
+ byte[] byteArray = Encoding.ASCII.GetBytes(xmlstr);
+ objdummy = SerializerObj.Deserialize(new MemoryStream(byteArray));
+
+ return objdummy;
+ }
+ #endregion
+} // end class.
+ ';
+
+ $r .= "\n" . $this->genphpast("Complex Types (Classes)");
+ foreach ($this->complextype as $key => $value) {
+ $type = $this->fixtag($value2["type"]);
+
+
+ if (strlen($value["name"]) <= 7 || substr($value["name"], 0, 7) == "ArrayOf") {
+ $r .= "\npublic class " . $value["name"] . " {\n";
+ foreach ($value["elements"] as $key2 => $value2) {
+ $r .= "\tprivate " . $type . " _" . $value2["name"] . "; \n";
+ }
+ $r .= "\n";
+ foreach ($value["elements"] as $key2 => $value2) {
+ $r .= "\tpublic " . $type . " " . $value2["name"] . "\n";
+ $r .= "\t{\n";
+ $r .= "\t\tget { return _" . $value2["name"] . "; }\n";
+ $r .= "\t\tset { _" . $value2["name"] . " = value; }\n";
+ $r .= "\t}\n";
+ }
+
+ $r .= "}\n";
+ }
+ }
+
+
+ return ($r);
+ }
+
+ protected function type2csharp($type) {
+ // ArrayOfS
+ // 12345678
+ $l = strlen($type);
+
+ if ($l > 8 and substr($type, 0, 7) == "ArrayOf") {
+ $type = "List<" . substr($type, 7, $l - 7) . ">";
+ return $this->type2csharp($type);
+ } else {
+ return $type;
+ }
+ }
+
+ protected function csharp_init($type) {
+ // ArrayOfS
+ // 12345678
+ switch ($type) {
+ case "string":
+ case "String":
+ return '""';
+ break;
+ case "int":
+ case "long":
+ case "Single":
+ return '0';
+ break;
+ default:
+ return "new " . ($this->type2csharp($type)) . "()";
+ }
+ }
+
+ protected function source() {
+ $result = $this->html_header();
+ $result .= "
List of Operations
";
+ $result .= $this->html_footer();
+
+ return $result;
+ }
+
+ protected function html_header() {
+ $r = "";
+ $r .= "" . $this->NAME_WS . "\n";
+
+ $r .= "";
+ $r .= '';
+ $r .= "";
+ $r .= "\n";
+ $r .= '' . $this->NAME_WS . '
';
+ $r .= "
" . $this->description . "
";
+ return $r;
+ }
+
+ protected function html_footer($timer_init = 0) {
+ $r = "";
+ $t2 = ceil((microtime(true) - $timer_init) * 1000) / 1000;
+ //echo base64_encode("
Webserver powered by
CLOUDKING")."
";
+
+
+ $b1 =
+ base64_decode("PGhyPldlYnNlcnZlciBwb3dlcmVkIGJ5IDxhIGhyZWY9J2h0dHA6Ly93d3cuc291dGhwcm9qZWN0cy5jb20vY2xvdWRraW5nLw==");
+ $b1 .= "version.php?version=" . $this->version;
+ $b1 .= base64_decode("Jz5DTE9VREtJTkc8L2E+");
+ //echo $b1;
+ if (!$this->oem) {
+ $r .= "$b1 ";
+ if ($this->verbose >= 1) {
+ $r .= "Version " . $this->version . ". ";
+ }
+ }
+ if ($timer_init != 0) {
+ $r .= "Generated in $t2 seconds
";
+ }
+ $r .= $this->copyright . "
";
+ $r .= "
";
+ return $r;
+ }
+
+ protected function gen_description() {
+ $t1 = microtime(true);
+ $result = $this->html_header();
+
+ if ($this->verbose >= 2) {
+ $result .= "Name Web Service :" . $this->NAME_WS . "
";
+ $result .= "Namespace :" . $this->NAMESPACE . "";
+ $result .= "WSDL :WSDL description
";
+ $result .= "Protocols Supported :" . (($this->soap11) ? "SOAP 1.1, " : "") .
+ (($this->soap12) ? "SOAP 1.2 (2.0), " : "") . (($this->get) ? "HTTP GET, " : "") .
+ (($this->post) ? "HTTP POST, " : "") . "None
";
+ if (method_exists($this, 'source')) {
+ $result .= "Source :Source Generation
";
+ }
+ }
+ if ($this->verbose >= 1) {
+ $result .= "
List of Operations
";
+ $jsall = "";
+ $result .= $jsall;
+ $result .= "
List of Complex Types
";
+ $jsall = "";
+ $result .= $jsall;
+ }
+ // copyright
+ $result .= $this->html_footer($t1);
+ return $result;
+ }
+
+ private function gen_description_util($min, $max) {
+ $tmp = "";
+ $tmp1 = "";
+ if ($min != "0" && $min != "") {
+ $tmp1 = "required";
+ }
+ if (@$max > 1) {
+ $tmp = "Array(" . $min . " to " . $max . ")";
+ }
+ if (@$max == "unbounded") {
+ $tmp = "Array(" . $min . " to unlimited)";
+ }
+ return ($tmp . " " . $tmp1);
+ }
+
+ protected function var_is_defined($fullname) {
+ $x1 = explode(":", $fullname);
+ if (count($x1) != 2) {
+ return "$fullname";
+ }
+ $space = $x1[0];
+ $name = $x1[1];
+ if ($space == "s") {
+ if (!in_array($name, $this->predef_types)) {
+ return "$fullname";
+ }
+ return "$fullname";
+ }
+ if ($space == "tns") {
+ foreach ($this->complextype as $key => $value) {
+ if ($name == $value["name"]) {
+ return "$fullname";
+ }
+ }
+ return "$fullname";
+ }
+ return "??$fullname";
+ }
+
+ public function addfunction($namefunction, $arr_in, $arr_out, $description = "") {
+ return $this->_addfunction($namefunction, $arr_in, $arr_out, $description);
+ }
+
+ private function _addfunction($namefunction, $arr_in, $arr_out, $description = "") {
+ if (count($arr_out) > 1) {
+ trigger_error("output cannot exceed 1 value", E_USER_ERROR);
+ }
+ $description = ($description == "") ? "The function $namefunction" : $description;
+ foreach ($arr_in as $key => $value) {
+ if ($arr_in[$key]["name"] == "") {
+ trigger_error("name must be defined", E_USER_ERROR);
+ }
+ $arr_in[$key]["name"] = (@$arr_in[$key]["name"] == "") ? "undefined" : $arr_in[$key]["name"];
+ $arr_in[$key]["type"] = (@$arr_in[$key]["type"] == "") ? "s:string" : $arr_in[$key]["type"];
+ $arr_in[$key]["minOccurs"] = (@$arr_in[$key]["minOccurs"] == "") ? 0 : $arr_in[$key]["minOccurs"];
+ if (@$arr_in[$key]["maxOccurs"] > 1 or @$arr_in[$key]["maxOccurs"] == "unbounded") {
+ trigger_error("maxOccurs cannot be >1", E_USER_ERROR);
+ }
+ $arr_in[$key]["maxOccurs"] = (@$arr_in[$key]["maxOccurs"] == "") ? 1 : $arr_in[$key]["maxOccurs"];
+ $arr_in[$key]["extra"] = (@$arr_in[$key]["extra"] == "") ? "" : $arr_in[$key]["extra"];
+ $arr_in[$key]["byref"] = (@$arr_in[$key]["byref"] == "") ? false : $arr_in[$key]["byref"];
+ }
+ // it must be only one value (or zero).
+ foreach ($arr_out as $key => $value) {
+ $arr_out[$key]["type"] = (@$arr_out[$key]["type"] == "") ? "s:string" : $arr_out[$key]["type"];
+ $arr_out[$key]["minOccurs"] = (@$arr_out[$key]["minOccurs"] == "") ? 0 : $arr_out[$key]["minOccurs"];
+ $arr_out[$key]["maxOccurs"] = (@$arr_out[$key]["maxOccurs"] == "") ? 1 : $arr_out[$key]["maxOccurs"];
+ $arr_out[$key]["extra"] = (@$arr_out[$key]["extra"] == "") ? "" : $arr_out[$key]["extra"];
+ $arr_out[$key]["byref"] = (@$arr_out[$key]["byref"] == "") ? false : $arr_out[$key]["byref"];
+ }
+
+ $this->operation[] = array(
+ "name" => $namefunction,
+ "in" => $arr_in,
+ "out" => $arr_out,
+ "description" => $description
+ );
+
+ return true;
+ }
+
+ public function addtype($nametype, $arr_param) {
+ $this->_addtype($nametype, $arr_param);
+ }
+
+ private function _addtype($nametype, $arr_param) {
+ foreach ($arr_param as $key => $value) {
+ $arr_param[$key]["name"] = (@$arr_param[$key]["name"] == "") ? "undefined" : $arr_param[$key]["name"];
+ $arr_param[$key]["type"] = (@$arr_param[$key]["type"] == "") ? "s:string" : $arr_param[$key]["type"];
+ $arr_param[$key]["minOccurs"] = (@$arr_param[$key]["minOccurs"] == "") ? 0 : $arr_param[$key]["minOccurs"];
+ $arr_param[$key]["maxOccurs"] = (@$arr_param[$key]["maxOccurs"] == "") ? 1 : $arr_param[$key]["maxOccurs"];
+ $arr_param[$key]["extra"] = (@$arr_param[$key]["extra"] == "") ? "" : $arr_param[$key]["extra"];
+ $arr_param[$key]["byref"] = (@$arr_param[$key]["byref"] == "") ? false : $arr_param[$key]["byref"];
+ $arr_param[$key]["description"] =
+ (@$arr_param[$key]["description"] == "") ? "a value" : $arr_param[$key]["description"];
+ }
+ $this->complextype[] = array(
+ "name" => $nametype,
+ "elements" => $arr_param
+ );
+ }
+
+ private function _save_wsdl($filename) {
+ if (!$fp = fopen($filename, 'a')) {
+ return "file '$filename' can't be saved";
+ }
+ if (fwrite($fp, $this->genwsdl()) === false) {
+ return "information can't be saved";
+ }
+ @fclose($fp);
+ return "ok";
+ }
+
+ public function genwsdl() {
+ if ($this->custom_wsdl != $this->FILE . "?wsdl") {
+ // se usa un archivo customizado.
+ $handle = @fopen($this->custom_wsdl, "r");
+ if ($handle) {
+ $contents = fread($handle, filesize($this->custom_wsdl));
+ } else {
+ $contents = "file or url :" . $this->custom_wsdl . " can't be open
\n";
+ }
+ fclose($handle);
+ return $contents;
+ }
+ $cr = "\n";
+ $tab1 = "\t";
+ $wsdl = 'encoding . '" ?>' . $cr;
+ $wsdl .= 'soap12) {
+ $wsdl .= ' xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ';
+ }
+ $wsdl .= ' xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">' .
+ $cr;
+ if ($this->description) {
+ $wsdl .= '' . $this->description . '';
+ }
+ // types ***
+ $wsdl .= $tab1 . '' . $cr . '' . $cr;
+ // elementos in
+ foreach ($this->operation as $key => $value) {
+ $wsdl .= '
+
+
+ ';
+ foreach ($value["in"] as $key2 => $value2) {
+ $minOccurs = $value2["minOccurs"];
+ $maxOccurs = $value2["maxOccurs"];
+ $wsdl .= '';
+ //if (@$value2["description"]) {
+ //$wsdl.=''.$value2["description"].'';
+ //}
+ $wsdl .= '';
+ }
+ $wsdl .= '
+
+ ';
+ // out
+ $wsdl .= '
+
+
+ ';
+ foreach ($value["out"] as $key2 => $value2) {
+ $minOccurs = $value2["minOccurs"];
+ $maxOccurs = $value2["maxOccurs"];
+ $wsdl .= '';
+ //if (@$value2["description"]) {
+ //$wsdl.=''.$value2["description"].'';
+ //}
+ $wsdl .= '';
+ }
+ foreach ($value["in"] as $key2 => $value2) {
+ if (@$value2["byref"]) {
+ $minOccurs = $value2["minOccurs"];
+ $maxOccurs = $value2["maxOccurs"];
+ $wsdl .= '';
+ }
+ }
+
+ $wsdl .= '
+
+
+ ';
+ }
+ // complex types
+ foreach ($this->complextype as $key => $value) {
+ $wsdl .= '
+
+ ';
+ foreach ($value["elements"] as $key2 => $value2) {
+ $minOccurs = $value2["minOccurs"];
+ $maxOccurs = $value2["maxOccurs"];
+ $type = str_replace($this->NAMESPACE, "tns", $value2["type"]);
+ $wsdl .= ' ';
+ //if (@$value2["description"]) {
+ //$wsdl.=''.$value2["description"].'';
+ //}
+ $wsdl .= '';
+ }
+ $wsdl .= '
+
+ ';
+ }
+ // end types
+ $wsdl .= '
+
+ ';
+ // messages
+ foreach ($this->operation as $key => $value) {
+ $name = $value["name"];
+ $wsdl .= '
+
+
+ ';
+ $wsdl .= '
+
+
+ ';
+ if ($this->get) {
+ $wsdl .= '
+
+
+ ';
+ $wsdl .= '
+
+
+ ';
+ }
+
+ if ($this->post) {
+ $wsdl .= '
+
+
+ ';
+ $wsdl .= '
+
+
+ ';
+ }
+ }
+ // porttype
+ $wsdl .= '';
+ foreach ($this->operation as $key => $value) {
+ $name = $value["name"];
+ $wsdl .= '';
+ if (@$value["description"]) {
+ $wsdl .= '' . @$value["description"] . '';
+ }
+ $wsdl .= '';
+ }
+ $wsdl .= '';
+ if ($this->get) {
+ $wsdl .= '';
+ foreach ($this->operation as $key => $value) {
+ $name = $value["name"];
+ $wsdl .= '';
+ if (@$value["description"]) {
+ $wsdl .= '' . @$value["description"] . '';
+ }
+ $wsdl .= '';
+ }
+ $wsdl .= '';
+ }
+ if ($this->post) {
+ $wsdl .= '';
+ foreach ($this->operation as $key => $value) {
+ $name = $value["name"];
+ $wsdl .= '';
+ if (@$value["description"]) {
+ $wsdl .= '' . @$value["description"] . '';
+ }
+ $wsdl .= '';
+ }
+ $wsdl .= '';
+ }
+
+ // binding
+ if ($this->soap11) {
+ $wsdl .= '
+
+ ';
+ foreach ($this->operation as $key => $value) {
+ $name = $value["name"];
+ $wsdl .= '
+
+
+
+
+ ';
+ }
+ $wsdl .= '';
+ }
+ // binding12
+ if ($this->soap12) {
+ $wsdl .= '
+ ';
+ foreach ($this->operation as $key => $value) {
+ $name = $value["name"];
+ $wsdl .= '
+
+
+
+
+ ';
+ }
+ $wsdl .= '';
+ }
+ // binding12 (get)
+ if ($this->soap12 and $this->get) {
+ $wsdl .= '
+ ';
+ foreach ($this->operation as $key => $value) {
+ $name = $value["name"];
+ $wsdl .= '';
+ $wsdl .= '';
+ $wsdl .= '';
+ $wsdl .= '';
+ }
+ $wsdl .= '';
+ }
+
+
+ // binding12 (post)
+ if ($this->soap12 and $this->post) {
+ $wsdl .= '
+ ';
+ foreach ($this->operation as $key => $value) {
+ $name = $value["name"];
+ $wsdl .= '';
+ $wsdl .= '';
+ $wsdl .= '';
+ $wsdl .= '';
+ }
+ $wsdl .= '';
+ }
+ // service
+
+ $wsdl .= '';
+
+ if ($this->soap11) {
+ $wsdl .= '
+ ';
+ }
+ if ($this->soap12) {
+ $wsdl .= '
+ ';
+ if ($this->get) {
+ $wsdl .= '
+ ';
+ }
+ if ($this->post) {
+ $wsdl .= '
+ ';
+ }
+
+ }
+ $wsdl .= '';
+ return $wsdl;
+ }
+
+
+}
\ No newline at end of file
diff --git a/lib/CloudKingClient.php b/lib/CloudKingClient.php
new file mode 100644
index 0000000..13f42aa
--- /dev/null
+++ b/lib/CloudKingClient.php
@@ -0,0 +1,248 @@
+ /** @noinspection DuplicatedCode */
+
+/*
+CloudKing Client
+Version 2.3.4
+Copyright Jorge Castro Castillo
+License http://www.southprojects.com/product/cloudking/license1-1/
+*/
+
+namespace eftec\cloudking;
+
+class CloudKingClient
+{
+ var $user_agent = "CloudKing Client (2.3.4)";
+ var $charset = "UTF-8";
+ var $soap = 1.2; // or 1.1
+ var $tempuri = "http://tempuri.org";
+ var $prefixns = "ts";
+ var $cookie = "";
+ var $proxyusername = "";
+ var $proxypassword = "";
+ // var $proxyhost = "";
+ var $proxyport = "";
+
+ /**
+ * @param string $url
+ * @param string $xmlparam
+ * @param string $nameFunction
+ * @param int $timeout
+ * @return mixed
+ */
+ function loadurl($url, $xmlparam, $nameFunction, $timeout = 30) {
+ $_url = parse_url($url);
+ //$host=($this->proxyhost!="")?$this->proxyhost:((@$_url["host"])?$_url["host"]:"127.0.0.1");
+ $port = ($this->proxyport != "") ? $this->proxyport : ((@$_url["port"]) ? $_url["port"] : 80);
+ $raw = "";
+ $raw .= "POST $url HTTP/1.1\r\n";
+ $raw .= "Host: " . $_url["host"] . "\r\n";
+ $raw .= "User-Agent: " . $this->user_agent . "\r\n";
+ if ($this->cookie) {
+ $raw .= "Set-Cookie: " . $this->cookie . "\r\n";
+ }
+ $raw .= "Accept-Encoding: gzip,deflate\r\n";
+ if ($this->soap >= 1.2) {
+ $raw .= "Content-Type: application/soap+xml;charset=" . $this->charset . ";action=\"" . $this->tempuri .
+ $nameFunction . "\"\r\n";
+ $content =
+ "prefixns .
+ "=\"" . $this->tempuri . "/\">";
+ $content3 = "" . $this->prefixns . ":" . $nameFunction . ">";
+ $content3 .= "";
+ } else {
+ $raw .= "Content-Type: text/xml;charset" . $this->charset . "\r\n";
+ $raw .= "SOAPAction: \"" . $this->tempuri . "/" . $nameFunction . "\"\r\n";
+ $content = "prefixns . "=\"" . $this->tempuri . "/\">";
+ $content .= "";
+ $content3 = "" . $this->prefixns . ":" . $nameFunction . ">";
+ $content3 .= "";
+ }
+ $content .= "<" . $this->prefixns . ":" . $nameFunction . ">";
+ $content .= $xmlparam . $content3;
+ $raw .= ($this->proxyusername != "") ? "Proxy-Authorization: Basic " .
+ base64_encode($this->proxyusername . ':' . $this->proxypassword) . "\r\n" : "";
+ $raw .= "Content-Length: " . strlen($content) . "\r\n";
+ $raw .= "Connection: Close\r\n";
+ $raw .= "\r\n"; // <-- important.
+ $raw .= $content;
+ //echo $raw;
+ $fp = fsockopen("tcp://" . $_url["host"], $port, $errno, $errstr, $timeout);
+ fwrite($fp, $raw);
+ $rawresponse = "";
+ $a = 0;
+ while (!feof($fp)) {
+ $a++;
+ $rawresponse .= fgets($fp, 128);
+
+ }
+ fclose($fp);
+ $p0 = strpos($rawresponse, "", $p0);
+ $resultadoxml = substr($rawresponse, $p1 + 2);
+
+ // ["Envelope"]["Body"]
+ $g = $this->xml2array(@$resultadoxml);
+ return $g["Envelope"]["Body"][$nameFunction . "Response"];
+ }
+
+ function array2xml($array, $name = "root", $contenttype = true, $start = true, $keyx = "") {
+ if (!is_array($array)) {
+ $array = array($name => $array);
+ }
+ $xmlstr = "";
+ if ($start) {
+ if ($contenttype) {
+ @header("content-type:text/xml;charset=" . $this->charset);
+ }
+ $xmlstr .= 'charset . '"?>';
+ $xmlstr .= '<' . $name . '>';
+ }
+ foreach ($array as $key => $child) {
+ if (is_array($child)) {
+ if (is_string($key)) {
+ $xmlstr .= '<' . $key . '>';
+ } else {
+ $xmlstr .= '<' . $keyx . ">";
+ }
+ $xmlstr .= $this->array2xml($child, "", "", false, $key);
+ if (is_string($key)) {
+ $xmlstr .= '' . $key . '>';
+ } else {
+ $xmlstr .= '' . $keyx . ">";
+ }
+ } else {
+ $type = $this->array2xmltype($child);
+ $xmlstr .= '<' . (is_string($key) ? $key : $type) . '>' . $child . '' .
+ (is_string($key) ? $key : $type) . '>';
+ }
+ }
+ if ($start) {
+ $xmlstr .= '' . $name . '>';
+ }
+ return $xmlstr;
+ }
+
+ function array2xmltype($value) {
+ if (is_float($value)) {
+ return "float";
+ }
+ if (is_int($value)) {
+ return "int";
+ }
+ return "string";
+ }
+
+ public function xml2array($contents, $get_attributes = 0, $priority = 'tag') {
+ if (!$contents) {
+ return array();
+ }
+ if (!function_exists('xml_parser_create')) {
+ return array();
+ }
+ $parser = xml_parser_create('');
+ xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $this->charset);
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
+ xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
+ xml_parse_into_struct($parser, trim($contents), $xml_values);
+ xml_parser_free($parser);
+ if (!$xml_values) {
+ trigger_error('wrong xml value in xml2array',E_USER_ERROR);
+ }
+ $xml_array = array();
+ $current =& $xml_array;
+ $repeated_tag_index = array();
+ foreach ($xml_values as $data) {
+ unset($attributes, $value);
+ extract($data);
+ $result = array();
+ $attributes_data = array();
+ if (isset($value)) {
+ if ($priority == 'tag') {
+ $result = $value;
+ } else {
+ $result['value'] = $value;
+ }
+ }
+ if (isset($attributes) and $get_attributes) {
+ foreach ($attributes as $attr => $val) {
+ if ($priority == 'tag') {
+ $attributes_data[$attr] = $val;
+ } else {
+ $result['attr'][$attr] = $val;
+ }
+ }
+ }
+ $tag = $this->fixtag($tag);
+ if ($type == "open") {
+ $parent[$level - 1] =& $current;
+ if (!is_array($current) or (!in_array($tag, array_keys($current)))) {
+ $current[$tag] = $result;
+ if ($attributes_data) {
+ $current[$tag . '_attr'] = $attributes_data;
+ }
+ $repeated_tag_index[$tag . '_' . $level] = 1;
+ $current =& $current[$tag];
+ } else {
+ if (isset($current[$tag][0])) {
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
+ $repeated_tag_index[$tag . '_' . $level]++;
+ } else {
+ $current[$tag] = array(
+ $current[$tag],
+ $result
+ );
+ $repeated_tag_index[$tag . '_' . $level] = 2;
+ if (isset($current[$tag . '_attr'])) {
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
+ unset($current[$tag . '_attr']);
+ }
+ }
+ $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
+ $current =& $current[$tag][$last_item_index];
+ }
+ } elseif ($type == "complete") {
+ if (!isset($current[$tag])) {
+ $current[$tag] = $result;
+ $repeated_tag_index[$tag . '_' . $level] = 1;
+ if ($priority == 'tag' and $attributes_data) {
+ $current[$tag . '_attr'] = $attributes_data;
+ }
+ } else {
+ if (isset($current[$tag][0]) and is_array($current[$tag])) { //If it is already an array...
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
+ if ($priority == 'tag' and $get_attributes and $attributes_data) {
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
+ }
+ $repeated_tag_index[$tag . '_' . $level]++;
+ } else {
+ $tmp = $current[$tag];
+ @$current[$tag] = array(
+ $tmp,
+ $result
+ );
+ $repeated_tag_index[$tag . '_' . $level] = 1;
+ if ($priority == 'tag' and $get_attributes) {
+ if (isset($current[$tag . '_attr'])) {
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
+ unset($current[$tag . '_attr']);
+ }
+ if ($attributes_data) {
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
+ }
+ }
+ $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
+ }
+ }
+ } elseif ($type == 'close') {
+ $current =& $parent[$level - 1];
+ }
+ }
+ return ($xml_array);
+ }
+
+ public function fixtag($tag) {
+ $arr = explode(":", $tag);
+ return ($arr[count($arr) - 1]);
+ }
+}
diff --git a/wslib/ckclient.2.3.php b/wslib/ckclient.2.3.php
deleted file mode 100644
index a18b31a..0000000
--- a/wslib/ckclient.2.3.php
+++ /dev/null
@@ -1,230 +0,0 @@
-
-/*
-CloudKing Client
-Version 2.3.4
-Copyright Jorge Castro Castillo
-License http://www.southprojects.com/product/cloudking/license1-1/
-*/
-class CKClient {
- var $version="2.3.4";
- var $user_agent="CloudKing Client (2.3.4)";
- var $charset="UTF-8";
- var $soap=1.2; // or 1.1
- var $tempuri="http://tempuri.org";
- var $prefixns = "ts";
- var $cookie="";
- var $proxyusername="";
- var $proxypassword="";
- var $proxyhost="";
- var $proxyport="";
- function loadurl($url,$xmlparam,$nameFunction,$timeout=30) {
- $_url=parse_url($url);
- $host=($this->proxyhost!="")?$this->proxyhost:((@$_url["host"])?$_url["host"]:"127.0.0.1");
- $port=($this->proxyport!="")?$this->proxyport:((@$_url["port"])?$_url["port"]:80);
- $raw="";
- $raw.="POST $url HTTP/1.1\r\n";
- $raw.="Host: ".$_url["host"]."\r\n";
- $raw.="User-Agent: ".$this->user_agent."\r\n";
- if ($this->cookie) {
- $raw.="Set-Cookie: ".$this->cookie."\r\n";
- }
- $raw.= "Accept-Encoding: gzip,deflate\r\n";
- if ($this->soap>=1.2) {
- $raw.="Content-Type: application/soap+xml;charset=".$this->charset.";action=\"".$this->tempuri.$nameFunction."\"\r\n";
- $content="prefixns."=\"".$this->tempuri."/\">";
- $content3 = "".$this->prefixns.":".$nameFunction.">";
- $content3 .= "";
- } else {
- $raw.="Content-Type: text/xml;charset".$this->charset."\r\n";
- $raw.="SOAPAction: \"".$this->tempuri."/".$nameFunction."\"\r\n";
- $content="prefixns."=\"".$this->tempuri."/\">";
- $content.= "";
- $content3 = "".$this->prefixns.":".$nameFunction.">";
- $content3.= "";
- }
- $content.= "<".$this->prefixns.":".$nameFunction.">";
- $content.=$xmlparam.$content3;
- $raw.=($this->proxyusername!="")?"Proxy-Authorization: Basic ".base64_encode($this->proxyusername.':'.$this->proxypassword)."\r\n":"";
- $raw.="Content-Length: ".strlen($content)."\r\n";
- $raw.="Connection: Close\r\n";
- $raw.="\r\n"; // <-- important.
- $raw.=$content;
- echo $raw;
- $fp = fsockopen("tcp://".$_url["host"], $port, $errno, $errstr,$timeout);
- fwrite($fp, $raw);
- $rawresponse="";
- $a=0;
- while (!feof($fp)) {
- $a++;
- $rawresponse.= fgets($fp, 128);
-
- }
- fclose($fp);
- $p0=strpos($rawresponse,"",$p0);
- $resultadoxml=substr($rawresponse,$p1+2);
-
- // ["Envelope"]["Body"]
- $g=$this->xml2array(@$resultadoxml);
-
- return $g["Envelope"]["Body"][$nameFunction."Response"];
- }
- function fixarray2xml($string) {
- if (!is_array($string)) { return $string; }
- $arr=explode("\n", $string);
- $resultado="";
- for ($i=1; $i < count($arr); $i++) {
- $l=trim($arr[$i]);
- $lant=trim($arr[$i - 1]);
- if ($l != $lant) { $resultado.=$arr[$i - 1] . "\n"; }
- }
- return $resultado;
- }
- function array2xml($array, $name="root", $contenttype=TRUE, $start=TRUE, $keyx="") {
- if (!is_array($array)) { $array=array($name=>$array); }
- $xmlstr="";
- if ($start) {
- if ($contenttype) {
- @header("content-type:text/xml;charset=".$this->charset);
- }
- $xmlstr.='charset.'"?>' ;
- $xmlstr.='<'.$name.'>' ;
- }
- foreach ($array as $key => $child) {
- if (is_array($child)) {
- if (is_string($key)) { $xmlstr.= '<'.$key.'>';}
- else { $xmlstr.='<'.$keyx.">"; }
- $xmlstr.=$this->array2xml($child, "", "", FALSE, $key);
- if (is_string($key)) { $xmlstr.= ''.$key.'>';}
- else { $xmlstr.=''.$keyx.">"; }
- } else {
- $type=$this->array2xmltype($child);
- $xmlstr.= '<'.(is_string($key)?$key:$type).'>'.$child.''.(is_string($key)?$key:$type).'>';
- }
- }
- if ($start)
- $xmlstr.=''.$name.'>';
- return $xmlstr;
- }
- function array2xmltype($value) {
- if (is_float($value)) {
- return "float";
- }
- if (is_int($value)) {
- return "int";
- }
- return "string";
- }
- public function xml2array($contents, $get_attributes=0, $priority='tag') {
- if (!$contents)
- return array();
- if (!function_exists('xml_parser_create')) {
- return array(); }
- $parser=xml_parser_create('');
- xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING,
- $this->charset);
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- xml_parse_into_struct($parser, trim($contents), $xml_values);
- xml_parser_free($parser);
- if (!$xml_values)
- return;
- $xml_array=array();
- $parents=array();
- $opened_tags=array();
- $arr=array();
- $current=&$xml_array;
- $repeated_tag_index=array();
- foreach ($xml_values as $data) {
- unset($attributes, $value);
- extract($data);
- $result=array();
- $attributes_data=array();
- if (isset($value)) {
- if ($priority == 'tag')
- $result=$value;
- else
- $result['value']=$value;
- }
- if (isset($attributes) and $get_attributes) {
- foreach ($attributes as $attr => $val) {
- if ($priority == 'tag')
- $attributes_data[$attr]=$val;
- else
- $result['attr'][$attr]=$val;
- }
- }
- $tag=$this->fixtag($tag);
- if ($type == "open") {
- $parent[$level - 1]=&$current;
- if (!is_array($current) or (!in_array($tag, array_keys($current)))) {
- $current[$tag]=$result;
- if ($attributes_data)
- $current[$tag . '_attr']=$attributes_data;
- $repeated_tag_index[$tag . '_' . $level]=1;
- $current=&$current[$tag];
- } else {
- if (isset($current[$tag][0])) {
- $current[$tag][$repeated_tag_index[$tag . '_' . $level]]=$result;
- $repeated_tag_index[$tag . '_' . $level]++;
- } else
- {
- $current[$tag]=array
- (
- $current[$tag],
- $result
- );
- $repeated_tag_index[$tag . '_' . $level]=2;
- if (isset($current[$tag . '_attr']))
- {
- $current[$tag]['0_attr']=$current[$tag . '_attr'];
- unset($current[$tag . '_attr']);
- }
- }
- $last_item_index=$repeated_tag_index[$tag . '_' . $level] - 1;
- $current=&$current[$tag][$last_item_index];
- }
- } elseif ($type == "complete") {
- if (!isset($current[$tag])) {
- $current[$tag]=$result;
- $repeated_tag_index[$tag . '_' . $level]=1;
- if ($priority == 'tag' and $attributes_data)
- $current[$tag . '_attr']=$attributes_data;
- } else {
- if (isset($current[$tag][0]) and is_array($current[$tag])) { //If it is already an array...
- $current[$tag][$repeated_tag_index[$tag . '_' . $level]]=$result;
- if ($priority == 'tag' and $get_attributes and $attributes_data)
- { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr']=$attributes_data; }
- $repeated_tag_index[$tag . '_' . $level]++;
- } else {
- $tmp=$current[$tag];
- @$current[$tag]=array
- (
- $tmp,
- $result
- );
- $repeated_tag_index[$tag . '_' . $level]=1;
- if ($priority == 'tag' and $get_attributes) {
- if (isset($current[$tag . '_attr']))
- {
- $current[$tag]['0_attr']=$current[$tag . '_attr'];
- unset($current[$tag . '_attr']);
- }
- if ($attributes_data)
- { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr']=$attributes_data; }
- }
- $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
- }
- }
- }
- elseif ($type == 'close') {
- $current=&$parent[$level - 1]; }
- }
- return ($xml_array);
- }
- public function fixtag($tag) {
- $arr=explode(":", $tag);
- return ($arr[count($arr) - 1]);
- }
- }
-?>
\ No newline at end of file
diff --git a/wslib/cklib.2.3.php b/wslib/cklib.2.3.php
deleted file mode 100644
index 6bc592d..0000000
--- a/wslib/cklib.2.3.php
+++ /dev/null
@@ -1,2006 +0,0 @@
-
-/*
-CloudKing Server
-Version 2.4
-Copyright Jorge Castro Castillo
-License http://www.southprojects.com/product/cloudking/license1-1/
-
-
-
- * Link: http://www.southprojects.com/cloudking
- *
- * functions : * constructor CLOUDKING($FILE,$NAMESPACE,$NAME_WS);
- * $FILE = php url (eg. http://127.0.0.1/ws.php )
- * $NAMESPACE = Namespace (default is http://test-uri/ it must finish with trail slash);
- * $NAME_WS = Name of the service (default is WebService1);
- * Use :Create the soap engine object.
- * Return :Nothing.
- *
- * * addfunction($name,$array_in,$array_out,$description)
- * $name = name of the function (case sensitive).
- * $array_in = Array with the input parameter(s) (**).
- * $array_out = Array with the output parameter (**) (only a array of a single paramter).
- * Use :Add a new function.
- * Return :Nothing.
- *
- * * addtype($name,$array_member)
- * $name = Name of the complex type (without namespace).
- * $array_member = Array with the member value(s) (**).
- * Use :Add a new complex type.
- * Return :Nothing.
- *
- * * run()
- * Use :Execute the engine.
- * Return :true if executed correctly, otherwise false.
- *
- * * save_wsdl($filename)
- * $filename = Name of the filename (local).
- * Use :Save the wsdl into a file.
- * Return :Nothing.
- *
- * * $copyright = copyright description (string,optional)
- * * $description = description of the web service (string,optional)
- * * $verbose = 0 by default (string,optional)
- * * $allowed = array of ip or url of clients that are allowed (optional,"*" everyone by default)
- * * $disallowed = array of ip or url of clients that are not allowed (optional,"" nobody by default)
- * * $custom_wsdl = wsdl file used for the information(if we want to avoid auto generation)
- * (**) definition of arrays:
- * array(
- * array("name"=>*name of the variable* (required)
- * ,"type"=>*type of the variable (with namespace required, for example tns:customtype , s:predefinedtype)
- * ,"minOccurs"=>*min value* (optional)
- * ,"maxOccurs"=>*max value* (optional, it can be "unbounded")
- * ,"extra"=>*a extra parameter (optional, for example 'nillable="true"')
- * ), ....
- * );
- *
- * what's missing
- * * SOAP Authentication (text and digest).
- * what's new:
- * 2.4 fix param (null)
- * 2.3.4 add PHP Client generation
- * 2.3.1 description tag fix.
- * 2.3 Extra fix, Unity generation code.
- * 2.2.2 Array2Xml fix (speedup, self type generation).
- * 2.2.1 Small Javascript function (description screen)
- * 2.1 Fix done, forced input parameters (still, every parameter is considered as optional).
- * 2.1 POST & GET (SOAP & REST-Style)
- * 2.0 Parse json and post.
- * 1.95 Generate Unity c# code (class)
- * 1.9 Add class and object as a alternative to arrays
- * Generate PHP code (class).
- * 1.8 Add pre-defined format long.
- * Generate PHP code.
- * Header fix (text/xml for soap 1.1 and application/soap+xml for soap 1.2)
- * 1.7 Allow parameter by reference
- * 1.6 Security
- * 1.5 custom_wsdl
- * verbose added (changed from production flag).
- * bug fixed (array).
- * encapsulated field.
- * 1.4 service description fixed.
- * allowed and disallowed array.
- * bug fixed
- * 1.3 bug fixed.
- * service description include a self evaluation system (variables not defined).
- * 1.2 service description added
- * 1.1 bug fixed.
- * 1.0 bug fixed.
- * 0.9b first operative version.
- * 0.8b custom NUSOAP library dropped, massive incompatibilities with custom library.
-*/
-class CKLIB {
- protected $FILE;
- protected $NAMESPACE;
- protected $NAME_WS;
- protected $operation;
- protected $complextype;
- protected $version="2.4";
-
- protected $predef_types=array
- (
- "string",
- "long",
- "int",
- "integer",
- "boolean",
- "decimal",
- "float",
- "double",
- "duration",
- "dateTime",
- "time",
- "date",
- "gYearMonth",
- "gYear",
- "gMonthDay",
- "gDay",
- "gMonth",
- "hexBinary",
- "base64Binary",
- "anyURI",
- "QName",
- "NOTATION"
- );
- protected $predef_types_num=array
- (
- "long",
- "int",
- "integer",
- "boolean",
- "decimal",
- "float",
- "double",
- "duration"
- );
- var $soap11=true;
- var $soap12=true;
- var $get=true;
- var $post=true;
- var $allowed_input=array("json"=>true,"rest"=>true,"php"=>true,"xml"=>true,"none"=>true);
- var $oem=false;
-
- var $encoding="UTF-8"; // ISO-8859-1
- var $custom_wsdl="";
- var $copyright=""; //Copyright ©2009 - 2010, SouthProject www.southprojects.com";
- var $description="CLOUDKING Server is running in this machine";
- var $verbose=0;
- var $wsse_username="";
- var $wsse_password="";
- var $wsse_nonce="";
- var $wsse_created="";
- var $wsse_password_type="None";
- var $variable_type="array"; // array or object
- var $object_function=""; // nombre del objeto, if empty then it call a single function
- var $allowed=array("*");
- var $disallowed=array("");
-
-
- public function CKLIB($FILE, $NAMESPACE="http://test-uri/", $NAME_WS="CKService1") {
- return $this->_CKLIB($FILE, $NAMESPACE, $NAME_WS);
- }
- private function _CKLIB($FILE, $NAMESPACE, $NAME_WS) {
-
- if (@$_SERVER["HTTPS"]) {
- $FILE=str_replace("http://","https://",$FILE);
- }
- $this->FILE=$FILE;
-
-
- $this->NAMESPACE=($NAMESPACE!="")?$NAMESPACE:$FILE."/";
- $this->NAME_WS=($NAME_WS!="")?$NAME_WS:"CKService1";
- $this->operation=array();
- $this->complextype=array();
- $this->custom_wsdl=$this->FILE."?wsdl";
- }
- private function class2array($class,$classname)
- {
- if (is_object($class)) {
- $resultado= (array)$class;
-
- $idx=$this->findIdxComplexType($classname);
- foreach($this->complextype[$idx]["elements"] as &$value) {
- if (strpos($value["type"],"tns:",0)!==false) {
- $tmp=$this->class2array($resultado[$value["name"]],$this->fixtag($value["type"]));
- if ($tmp!="") {
- //$resultado[$value["name"]]=$tmp;
- }
- }
- }
- } else {
- $resultado[$classname]=$class;
- }
- return $resultado;
- }
- private function findIdxComplexType($complexname)
- {
-
- foreach ($this->complextype as $key => $value) {
- if ($value["name"]==$complexname) {
- return $key;
- }
- }
- return -1;
-
- }
- private function array2class($arr, $newclass)
- {
- if ($arr==null) {
- return null;
- }
- $object=(object)$arr;
- if( !class_exists($newclass) )
- {
- // We'll save unserialize the work of triggering an error if the class does not exist
- trigger_error('Class ' . $newclass . ' not found', E_USER_ERROR);
- return false;
- }
- $serialized_parts = explode(':', serialize($object));
- $serialized_parts[1] = strlen($newclass);
- $serialized_parts[2] = '"' . $newclass . '"';
- $result=unserialize(implode(':', $serialized_parts));
- // aqui recorremos los miembros
- $idx=$this->findIdxComplexType($newclass);
- if ($idx==-1) {
- trigger_error('Complex Type ' . $newclass . ' not found', E_USER_ERROR);
- return false;
- }
- foreach($this->complextype[$idx]["elements"] as &$value) {
- if (strpos($value["type"],"tns:",0)!==false) {
- $result->$value["name"]=$this->array2class($result->$value["name"],$this->fixtag($value["type"]));
- }
- }
-
- return $result;
- }
-
- public function set_copyright($copyright) {
- $this->copyright=$copyright;
- }
- public function save_wsdl($filename) {
- return $this->save_wsdl($filename);
- }
- private function _save_wsdl($filename) {
- if (!$fp=fopen($filename, 'a')) { return "file '$filename' can't be saved"; }
- if (fwrite($fp, $this->genwsdl()) === false) { return "information can't be saved"; }
- ;
- @fclose($fp);
- return "ok";
- }
- private function ws_security() {
- /*
- $password = "password";
- $created_time_stamp = date("Y-m-d\TH:i:s\Z");
- $nonce = uniqid(time());
- */
-
- }
- public function password_correct($password,$type="None") {
- if ($type!=$this->wsse_password_type) {
- return false; // method not equal
- }
- if ($this->wsse_password_type=="PasswordDigest") {
- $wsse_nonce=$this->wsse_nonce;
- $wsse_created=$this->wsse_created;
- $nonce = base64_decode($wsse_nonce);
- $password_digest = base64_encode(sha1($nonce.$wsse_created.$password, true));
- return ($ns->wsse_password==$password_digest);
- };
- if ($this->wsse_password_type=="PasswordText") {
- return ($ns->wsse_password==$password);
- };
- return true;
- }
- protected function right($string,$num_cut=1) {
- if (strlen($string)-$num_cut>=0) {
- return substr($string,0,strlen($string)-$num_cut);
- }
- return $string;
- }
-
- private function security() {
- $ip=$_SERVER['REMOTE_ADDR'];
- $hostname=gethostbyaddr($_SERVER['REMOTE_ADDR']);
- foreach ($this->disallowed as $value) {
- if ($value == $hostname or $value == $ip) { echo ("host $ip $hostname not allowed (blacklist)\n"); return false;}
- }
- foreach ($this->allowed as $value) {
- if ($value == "*" or $value == $hostname or $value == $ip) { return true; }
- }
- echo ("host $ip $hostname not allowed \n");
- return false;
- }
- public function run() {
- return $this->_run();
- }
- private function _run() {
- if (!$this->security()) {
- return false;
- }
- global $_REQUEST;
- $param=@$_SERVER['QUERY_STRING']."&=";
- $p=strpos($param,"&");
- $p1=strpos($param,"=");
- $paraminit=substr($param,0,min($p,$p1)); // ?{value}&other=aaa
-
-
- $HTTP_RAW_POST_DATA=@$GLOBALS['HTTP_RAW_POST_DATA'];
- $methodcalled="soap";
- $isget=false;
- $methodcalled=($paraminit=="")?"soap":$paraminit;
- $methoddefined=false;
- if (strlen($methodcalled)>=3) {
- if (substr($methodcalled,0,3)=="get" and $this->get) {
- $methodcalled= str_replace("get","",$methodcalled);
- $methodcalled=($methodcalled==""?"none":$methodcalled);
- $isget=true;
- $methoddefined=true;
- }
- }
- if (strlen($methodcalled)>=4) {
- if (substr($methodcalled,0,4)=="post" and $this->post) {
- $methodcalled= str_replace("post","",$methodcalled);
- $methodcalled=($methodcalled==""?"none":$methodcalled);
- $isget=false;
- $methoddefined=true;
- }
- }
- $info=explode("/",@$_SERVER["PATH_INFO"]);
- $function_name=(count($info)>=2)?$info[1]:"unknown_unknown";
- $function_out=(count($info)>=3)?$info[2]:$methodcalled;
-
- if (count($info)>=4 and $this->get) {
- // is passing more that the functionname and output type 0> is rest myphp?php/functionname/typeout/p1/p2....
- $isget=true;
- $methodcalled="rest";
- $methoddefined=true;
- }
- if ($this->soap12) {
- if (!$methoddefined and $HTTP_RAW_POST_DATA=="" and $function_name!="unknown_unknown" and $this->get) {
- // mypage.php/functioname?param1=......
- $methodcalled="none";
- $function_out="xml";
- $isget=true;
- $methoddefined=true;
- }
- if (!$methoddefined and $function_name!="unknown_unknown" and $this->post) {
- // mypage.php/functioname (it must be soap http post).
-
- $methodcalled="none";
- $function_out="xml";
- $HTTP_RAW_POST_DATA=" "; // only for evaluation.
- $isget=false;
- $methoddefined=true;
- }
- }
- if (!@$this->allowed_input[$methodcalled] and $methoddefined) {
-
- trigger_error("method $methodcalled not allowed", E_USER_ERROR);
- return false;
- }
-
-
-
- if ($HTTP_RAW_POST_DATA!="" or $isget) {
- // is trying to evaluate a function.
-
- // ejemplo :http://www.micodigo.com/webservice.php/functionname/xml?getjson&value1={json..}&value2={json}
- //info(0)=0
- //info(1)=functionname
- //info(2)=serialize return type (optional, by default is the same name as passed)
-
-
-
- $res=false;
- switch($methodcalled) {
- case "soap":
- case "wsdl":
- $res= $this->requestSOAP($HTTP_RAW_POST_DATA);
- break;
- case "json":
- case "rest":
- case "php":
- case "xml":
- case "none":
-
- $res= $this->requestNOSOAP($function_name,$function_out,$methodcalled,$isget,$info);
- break;
- }
- if ($res) {
- echo $res;
- return true;
- } else {
- return false;
- }
- } else {
- switch ($paraminit) {
- case "wsdl":
- header("content-type:text/xml;charset=".$this->encoding);
- echo $this->genwsdl();
- return true;
- break;
- case "source":
- if ($this->verbose>=2) {
- switch (@$_GET["source"]) {
- case "php":
-
- if (method_exists($this,'genphp')) {
- header("content-type:text/plain;charset=".$this->encoding);
- echo $this->genphp();
- } else {
- echo "not supported
";
- }
- break;
- case "phpclient":
-
- if (method_exists($this,'genphpclient')) {
- header("content-type:text/plain;charset=".$this->encoding);
- echo $this->genphpclient();
- } else {
- echo "Not supported
";
- }
- break;
- case "unity":
- if (method_exists($this,'genunitycsharp')) {
- header("content-type:text/plain;charset=".$this->encoding);
- echo $this->genunitycsharp();
- } else {
- echo "not supported
";
- }
- break;
- default:
- if (method_exists($this,'source')) {
- header("content-type:text/html");
- echo $this->source();
- } else {
- echo "not supported
";
- }
- break;
- }
- return true;
- }
- break;
- case "unitycsharp":
- if ($this->verbose>=2) {
- header("content-type:text/plain;charset=".$this->encoding);
- echo $this->genunitycsharp();
- return true;
- }
- break;
- }
-
- }
- if (method_exists($this,'gen_description')) {
- $this->gen_description();
- } else {
- echo $this->html_header();
- echo "Name Web Service :" . $this->NAME_WS . "
";
- echo $this->html_footer();
- }
- return true;
- }
- protected function html_footer($timer_init=0) {
- $r="";
- $t2=ceil((microtime(true)-$timer_init)*1000)/1000;
- //echo base64_encode("
Webserver powered by CLOUDKING")."
";
-
-
-
- $b1=base64_decode("PGhyPldlYnNlcnZlciBwb3dlcmVkIGJ5IDxhIGhyZWY9J2h0dHA6Ly93d3cuc291dGhwcm9qZWN0cy5jb20vY2xvdWRraW5nLw==");
- $b1.="version.php?version=".$this->version;
- $b1.=base64_decode("Jz5DTE9VREtJTkc8L2E+");
- //echo $b1;
- if (!$this->oem) {
- $r.= "$b1 ";
- if ($this->verbose>=1) {
- $r.= "Version " . $this->version.". ";
- }
- }
- if ($timer_init!=0) {
- $r.= "Generated in $t2 seconds
";
- }
- $r.= $this->copyright . "
";
- $r.= "
\n";
- $r.= '' . $this->NAME_WS . '
';
- $r.= "
" . $this->description . "
";
- return $r;
- }
- protected function var_is_defined($fullname) {
- $x1=explode(":", $fullname);
- if (count($x1) != 2) { return "
$fullname"; }
- $space=$x1[0];
- $name=$x1[1];
- if ($space == "s") {
- if (!in_array($name, $this->predef_types)) { return "
$fullname"; }
- return "
$fullname";
- }
- if ($space == "tns") {
- foreach ($this->complextype as $key => $value) {
- if ($name == $value["name"]) { return "
$fullname"; }
- }
- return "
$fullname";
- }
- return "
??$fullname";
- }
-
- public function addfunction($namefunction, $arr_in, $arr_out, $description="") {
- return $this->_addfunction($namefunction, $arr_in, $arr_out, $description);
- }
- private function _addfunction($namefunction, $arr_in, $arr_out, $description="") {
- if (count($arr_out) > 1) { trigger_error("output cannot exceed 1 value", E_USER_ERROR); }
- $description=($description == "") ? "The function $namefunction" : $description;
- foreach ($arr_in as $key => $value) {
- if ($arr_in[$key]["name"]=="") { trigger_error( "name must be defined",E_USER_ERROR); }
- $arr_in[$key]["name"]=(@$arr_in[$key]["name"]=="")?"undefined":$arr_in[$key]["name"];
- $arr_in[$key]["type"]=(@$arr_in[$key]["type"]=="")?"s:string":$arr_in[$key]["type"];
- $arr_in[$key]["minOccurs"]=(@$arr_in[$key]["minOccurs"]=="")?0:$arr_in[$key]["minOccurs"];
- if (@$arr_in[$key]["maxOccurs"]>1 or @$arr_in[$key]["maxOccurs"]=="unbounded") { trigger_error("maxOccurs cannot be >1",E_USER_ERROR); }
- $arr_in[$key]["maxOccurs"]=(@$arr_in[$key]["maxOccurs"]=="")?1:$arr_in[$key]["maxOccurs"];
- $arr_in[$key]["extra"]=(@$arr_in[$key]["extra"]=="")?"":$arr_in[$key]["extra"];
- $arr_in[$key]["byref"]=(@$arr_in[$key]["byref"]=="")?false:$arr_in[$key]["byref"];
- }
- // it must be only one value (or zero).
- foreach ($arr_out as $key => $value) {
- $arr_out[$key]["type"]=(@$arr_out[$key]["type"]=="")?"s:string":$arr_out[$key]["type"];
- $arr_out[$key]["minOccurs"]=(@$arr_out[$key]["minOccurs"]=="")?0:$arr_out[$key]["minOccurs"];
- $arr_out[$key]["maxOccurs"]=(@$arr_out[$key]["maxOccurs"]=="")?1:$arr_out[$key]["maxOccurs"];
- $arr_out[$key]["extra"]=(@$arr_out[$key]["extra"]=="")?"":$arr_out[$key]["extra"];
- $arr_out[$key]["byref"]=(@$arr_out[$key]["byref"]=="")?false:$arr_out[$key]["byref"];
- }
-
- $this->operation[]=array
- (
- "name" => $namefunction,
- "in" => $arr_in,
- "out" => $arr_out,
- "description" => $description
- );
-
- return true;
- }
- public function addtype($nametype, $arr_param) {
- return $this->_addtype($nametype, $arr_param);
- }
- private function _addtype($nametype, $arr_param) {
- foreach ($arr_param as $key => $value) {
- $arr_param[$key]["name"]=(@$arr_param[$key]["name"]=="")?"undefined":$arr_param[$key]["name"];
- $arr_param[$key]["type"]=(@$arr_param[$key]["type"]=="")?"s:string":$arr_param[$key]["type"];
- $arr_param[$key]["minOccurs"]=(@$arr_param[$key]["minOccurs"]=="")?0:$arr_param[$key]["minOccurs"];
- $arr_param[$key]["maxOccurs"]=(@$arr_param[$key]["maxOccurs"]=="")?1:$arr_param[$key]["maxOccurs"];
- $arr_param[$key]["extra"]=(@$arr_param[$key]["extra"]=="")?"":$arr_param[$key]["extra"];
- $arr_param[$key]["byref"]=(@$arr_param[$key]["byref"]=="")?false:$arr_param[$key]["byref"];
- $arr_param[$key]["description"]=(@$arr_param[$key]["description"]=="")?"a value":$arr_param[$key]["description"];
- }
- $this->complextype[]=array
- (
- "name" => $nametype,
- "elements" => $arr_param
- );
- }
- private function requestSOAP($HTTP_RAW_POST_DATA) {
- global $param, $r;
- $soapenv="";
- if (strpos($HTTP_RAW_POST_DATA, "http://schemas.xmlsoap.org/soap/envelope/")) {
- if ($this->soap11) {
- header("content-type:text/xml;charset=".$this->encoding);
- $soapenv="http://schemas.xmlsoap.org/soap/envelope/";
- }
- }
- if (strpos($HTTP_RAW_POST_DATA, "http://www.w3.org/2003/05/soap-envelope")) {
- if ($this->soap12) {
- header("content-type:application/soap+xml;charset=".$this->encoding);
- $soapenv="http://www.w3.org/2003/05/soap-envelope";
- }
- }
- if ($soapenv == "") { die("soap incorrect or not allowed"); }
- $arr=$this->xml2array($HTTP_RAW_POST_DATA,0);
- $HTTP_RAW_POST_DATA=""; // free mem.
- $this->wsse_username=@$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Username"];
- $this->wsse_password=@$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Password"];
- $this->wsse_nonce=@$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Nonce"];
- $this->wsse_created=@$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Created"];
- $tmp=@$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Password_attr"]["Type"];
-
- if (strpos($tmp,"#PasswordText")) {
- $this->wsse_password_type="PasswordText";
- } else {
- if (strpos($tmp,"#PasswordDigest")) {
- $this->wsse_password_type="PasswordDigest";
- } else {
- $this->wsse_password_type="None";
- }
- }
-
-
-
-
- $funcion=array_keys($arr["Envelope"]["Body"]);
- $function_name0=$funcion[0];
- $function_name=$this->fixtag($function_name0); // "tem:getSix" (deberia ser solo una funcion?)
- // pasar los parametros
- $param=array();
-
- $paramt=" ";
- $i=0;
- $indice_operation=-1;
- foreach ($this->operation as $key => $value) {
- if ($value["name"]==$function_name) {
- $indice_operation=$key;
- }
- }
- if ($indice_operation>=0) {
- $my_operation=$this->operation[$indice_operation];
- foreach($my_operation["in"] as $value) {
- $param[]=@$arr["Envelope"]["Body"][$function_name0][$value["name"]];
- if (empty($param[$i])) {
- $param[$i]="";
- }
- $paramt.='@$param[' . $i . '],';
- $i++;
- }
- if ($this->variable_type=="object") {
- // convert all parameters in classes.
- foreach($param as $key=>$value) {
- $classname=$my_operation["in"][$key]["type"];
-
- if (strpos($classname,"tns:",0)!==false) {
- $param[$key]=$this->array2class($value,$this->fixtag($classname));
-// var_dump($param[$key]);
- } else {
- // not touched.
- }
-
- }
- }
- $param_count=count($param);
- $paramt=substr($paramt, 0, strlen($paramt) - 1);
- $r="";
- if ($this->object_function=="") {
- $evalstr="\$r=$function_name($paramt);";
- } else {
- @eval("global \$".$this->object_function.";");
- $evalstr="\$r=\$".$this->object_function."->$function_name($paramt);";
- }
-
-
- $evalret=eval($evalstr);
- if ($this->variable_type=="object") {
-
- $ttype=$this->fixtag($my_operation["out"][0]["type"]);
- $r=$this->class2array($r,$this->fixtag($my_operation["out"][0]["type"]),false,false);
- //var_dump($r);
- //$r=@$r[$ttype];
-
-
- }
- } else {
- $evalret=array("soap:Fault"=>'Caught exception: function not defined');
- }
- //var_dump($r);
-
- //echo $this->array2xml($r,"array",false,false);
-
- if (is_array($r)) {
- $serial=$this->array2xml($r, "array", false, false);
- $serial=$this->fixarray2xml($serial);
- if (@$r["soap:Fault"]!="") {
- $evalret=false;
- }
- } else {
- $serial=$r;
- }
- // agregamos si tiene valor byref.
- $extrabyref="";
- $indice=0;
- $key=$indice_operation;
- $value=$this->operation[$indice_operation];
-
- foreach ($value["in"] as $key2 => $value2) {
- if (@$value2["byref"]) {
- $paramtmp=@$param[$indice];
- if (is_array($paramtmp)) {
- $tmp2=$this->array2xml($paramtmp, "array", false, false);
- $tmp2=$this->fixarray2xml($tmp2);
- } else {
- $tmp2=$paramtmp;
- }
- $extrabyref.="<".$value2["name"].">".$tmp2."".$value2["name"].">";
- }
- $indice++;
- }
-
-
-
-
-
- if ($evalret!==false) {
- $resultado='encoding.'"?>';
- $resultado.='
';
- $resultado.='<' . $function_name . 'Response xmlns="' . $this->NAMESPACE . '">';
- $resultado.='<' . $function_name . 'Result>' . $serial.'' . $function_name . 'Result>';
- $resultado.=$extrabyref;
- $resultado.='' . $function_name . 'Response>';
- $resultado.='';
- $resultado.='';
- } else {
- $resultado='
';
- $resultado.='soap:Sender'.$function_name.' failed to evaluate .'.@$r["soap:Fault"].'';
- $resultado.='';
- }
-
-
- return $resultado;
- }
- private function decodeNOSOAP($methodcalled,$tmpvalue) {
- // pass json/xml/php/raw --> return a array or value.
- $tmp="";
- switch ($methodcalled) {
- case "json":
- $tmp=json_decode($tmpvalue);
- break;
- case "xml":
- $this->xml2array($tmpvalue,1);
- break;
- case "php":
- $tmp=@unserialize($tmpvalue);
- break;
- case "none":
- /*if (is_array($tmpvalue)) {
- $tmpvalue=ex(",",$tmpvalue);
- }
- */
- $tmp=$tmpvalue; // urlencode is done
- break;
- }
- return $tmp;
- }
- private function encodeNOSOAP($methodcalled,$tmpvalue,$tmpname) {
- $tmp="";
- switch ($methodcalled) {
- case "json":
- $tmp=json_encode($tmpvalue);
- break;
- case "xml":
- if (!is_array($tmpvalue)) {
- @header("content-type:text/xml;charset=".$this->encoding);
- $tmp='<' . '?' . 'xml version="1.0" encoding="'.$this->encoding.'"' . '?' . '>' . "\n";
- $tmp.="<$tmpname>$tmpvalue$tmpname>";
- } else {
- $tmp=$this->array2xml($tmpvalue, "array", true, true);
- }
- $tmp=$this->fixarray2xml($tmp);
-
- break;
- case "php":
- $tmp=serialize($tmpvalue);
- break;
- case "none":
- if (is_array($tmpvalue)) {
- $tmp="";
- foreach($tmpvalue as $key=>$value) {
- $tmp.=$key."=".$value."&";
- }
- $tmpvalue=$tmp;
- $tmpvalue=substr($tmpvalue, 0, strlen($tmpvalue) - 1);
- }
- $tmp=$tmpvalue;
- break;
- }
- return $tmp;
- }
-
- private function requestNOSOAP($function_name,$function_out, $methodcalled,$isget,$info=array()) {
- global $param, $r;
- $evalret=false;
- $this->wsse_username=@$_POST["Username"];
- $this->wsse_password=@$_POST["Password"];
- $this->wsse_nonce=@$_POST["Nonce"];
- $this->wsse_created=@$_POST["Created"];
- $tmp=@$_POST["Type"];
-
- if (strpos($tmp,"#PasswordText")) {
- $this->wsse_password_type="PasswordText";
- } else {
- if (strpos($tmp,"#PasswordDigest")) {
- $this->wsse_password_type="PasswordDigest";
- } else {
- $this->wsse_password_type="None";
- }
- }
- // pasar los parametros
- $param=array();
-
- $paramt="";
-
- $indice_operation=-1;
- foreach ($this->operation as $key => $value) {
- if ($value["name"]==$function_name) {
- $indice_operation=$key;
- }
- }
- $operation=array("in"=>array());
- if ($indice_operation>=0) {
- $i=0;
- $operation=$this->operation[$indice_operation];
- foreach($operation["in"] as $key=>$value) {
- $tmpvalue=($isget)?@$_GET[$value["name"]]:@$_POST[$value["name"]];
- if ($methodcalled=="rest") {
- $param[]=@$info[$i+3];
- } else {
- $param[]=$this->decodeNOSOAP($methodcalled,$tmpvalue);
- }
- $paramt.='@$param[' . $i . '],';
- $i++;
- }
- if ($this->variable_type=="object") {
- // convert all parameters in classes.
- foreach($param as $key=>$value) {
- $classname=$operation["in"][$key]["type"];
- if (strpos($classname,"tns:",0)!==false) {
- $param[$key]=$this->array2class($value,$this->fixtag($classname));
- } else {
- // not touched.
- }
- }
- }
- $param_count=count($param);
- $paramt=substr($paramt, 0, strlen($paramt) - 1);
- $r="";
- if ($this->object_function=="") {
- $evalstr="\$r=$function_name($paramt);";
- } else {
- @eval("global \$".$this->object_function.";");
- $evalstr="\$r=\$".$this->object_function."->$function_name($paramt);";
-
- }
-
- $evalret=eval($evalstr);
-
- if ($this->variable_type=="object") {
-
- $r=$this->class2array($r,$this->fixtag($operation["out"][0]["type"]));
- }
- } else {
- $evalret=array("soap:Fault"=>'Caught exception: function not defined');
- }
-
- $max_result=array();
-
-
- $max_result[$function_name . 'Result']=$r;
-
- // agregamos si tiene valor byref.
- $extrabyref="";
- $indice=0;
-
- foreach ($operation["in"] as $key2 => $value2) {
- if (@$value2["byref"]) {
- $paramtmp=@$param[$indice];
- $max_result[$value2["name"]]=$paramtmp;
- $extrabyref.=$value2["name"]."=".$paramtmp."\n";
-
- }
- $indice++;
- }
-
- if (count($max_result)==1) {
-
- $max_result=$r; // if not byref then we returned as a single value
- }
-
- if ($evalret!==false) {
-
- $resultado=$max_result;
- } else {
- $resultado=$r;
- }
-
-
- $resultado=$this->encodeNOSOAP($function_out,$resultado,$function_name . 'Result');
- return $resultado;
- }
-
-
- private function xml2array($contents, $get_attributes=0, $priority='tag') {
- if (!$contents)
- return array();
- if (!function_exists('xml_parser_create')) {
- //print "'xml_parser_create()' function not found!";
- return array(); }
- //Get the XML parser of PHP - PHP must have this module for the parser to work
- $parser=xml_parser_create('');
- xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING,
- $this->encoding); # http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- xml_parse_into_struct($parser, trim($contents), $xml_values);
- xml_parser_free($parser);
- if (!$xml_values)
- return; //Hmm...
- //Initializations
- $xml_array=array();
- $parents=array();
- $opened_tags=array();
- $arr=array();
- $current=&$xml_array; //Refference
- //Go through the tags.
- $repeated_tag_index=array(); //Multiple tags with same name will be turned into an array
- foreach ($xml_values as $data) {
- unset($attributes, $value); //Remove existing values, or there will be trouble
- //This command will extract these variables into the foreach scope
- // tag(string), type(string), level(int), attributes(array).
- extract($data); //We could use the array by itself, but this cooler.
- $result=array();
- $attributes_data=array();
- if (isset($value)) {
- if ($priority == 'tag')
- $result=$value;
- else
- $result['value']=$value; //Put the value in a assoc array if we are in the 'Attribute' mode
- }
- //Set the attributes too.
- if (isset($attributes) and $get_attributes) {
- foreach ($attributes as $attr => $val) {
- if ($priority == 'tag')
- $attributes_data[$attr]=$val;
- else
- $result['attr'][$attr]=$val; //Set all the attributes in a array called 'attr'
- }
- }
- //See tag status and do the needed.
- $tag=$this->fixtag($tag);
- if ($type == "open") { //The starting of the tag '
'
- $parent[$level - 1]=&$current;
- if (!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
- $current[$tag]=$result;
- if ($attributes_data)
- $current[$tag . '_attr']=$attributes_data;
- $repeated_tag_index[$tag . '_' . $level]=1;
- $current=&$current[$tag];
- } else { //There was another element with the same tag name
- if (isset($current[$tag][0])) { //If there is a 0th element it is already an array
- $current[$tag][$repeated_tag_index[$tag . '_' . $level]]=$result;
- $repeated_tag_index[$tag . '_' . $level]++;
- } else
- { //This section will make the value an array if multiple tags with the same name appear together
- $current[$tag]=array
- (
- $current[$tag],
- $result
- ); //This will combine the existing item and the new item together to make an array
- $repeated_tag_index[$tag . '_' . $level]=2;
- if (isset($current[$tag . '_attr']))
- { //The attribute of the last(0th) tag must be moved as well
- $current[$tag]['0_attr']=$current[$tag . '_attr'];
- unset($current[$tag . '_attr']);
- }
- }
- $last_item_index=$repeated_tag_index[$tag . '_' . $level] - 1;
- $current=&$current[$tag][$last_item_index];
- }
- } elseif ($type == "complete") { //Tags that ends in 1 line ''
- //See if the key is already taken.
- if (!isset($current[$tag])) { //New Key
- $current[$tag]=$result;
- $repeated_tag_index[$tag . '_' . $level]=1;
- if ($priority == 'tag' and $attributes_data)
- $current[$tag . '_attr']=$attributes_data;
- } else { //If taken, put all things inside a list(array)
- if (isset($current[$tag][0]) and is_array($current[$tag])) { //If it is already an array...
- // ...push the new element into that array.
- $current[$tag][$repeated_tag_index[$tag . '_' . $level]]=$result;
- if ($priority == 'tag' and $get_attributes and $attributes_data)
- { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr']=$attributes_data; }
- $repeated_tag_index[$tag . '_' . $level]++;
- } else { //If it is not an array...
- $tmp=$current[$tag];
- //echo "tag = $tag result = $result current=$tmp
";
- //var_dump($current);
- @$current[$tag]=array
- (
- $tmp,
- $result
- ); //...Make it an array using using the existing value and the new value
- $repeated_tag_index[$tag . '_' . $level]=1;
- if ($priority == 'tag' and $get_attributes) {
- if (isset($current[$tag . '_attr']))
- { //The attribute of the last(0th) tag must be moved as well
- $current[$tag]['0_attr']=$current[$tag . '_attr'];
- unset($current[$tag . '_attr']);
- }
- if ($attributes_data)
- { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr']=$attributes_data; }
- }
- $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
- }
- }
- }
- elseif ($type == 'close') { //End of tag ''
- $current=&$parent[$level - 1]; }
- }
- return ($xml_array);
- }
- protected function fixtag($tag) {
- $arr=explode(":", $tag);
- return ($arr[count($arr) - 1]);
- }
- private function fixarray2xml($string) {
- if (!is_array($string)) { return $string; }
- $arr=explode("\n", $string);
- $resultado="";
- for ($i=1; $i < count($arr); $i++) {
- $l=trim($arr[$i]);
- $lant=trim($arr[$i - 1]);
- if ($l != $lant) { $resultado.=$arr[$i - 1] . "\n"; }
- }
- return $resultado;
- }
- function array2xml($array, $name="root", $contenttype=TRUE, $start=TRUE, $keyx="") {
- if (!is_array($array)) { return $array; }
- $xmlstr="";
- if ($start) {
- if ($contenttype) {
- @header("content-type:text/xml;charset=".$this->encoding);
- }
- $xmlstr.='encoding.'"?>' ;
- $xmlstr.='<'.$name.'>' ;
- }
- foreach ($array as $key => $child) {
- if (is_array($child)) {
- if (is_string($key)) { $xmlstr.= '<'.$key.'>';}
- else { $xmlstr.='<'.$keyx.">"; }
- $xmlstr.=$this->array2xml($child, "", "", FALSE, $key);
- if (is_string($key)) { $xmlstr.= ''.$key.'>';}
- else { $xmlstr.=''.$keyx.">"; }
- } else {
- $type=$this->array2xmltype($child);
-
-
- if ($this->variable_type=="object" and is_object($child)) {
- $xmlstr.="<$type>".$this->array2xml($this->class2array($child,$type),$type,false,false,$key)."$type>";
- } else {
- $xmlstr.= '<'.(is_string($key)?$key:$type).'>'.$child.''.(is_string($key)?$key:$type).'>';
- }
- }
- }
- if ($start)
- $xmlstr.=''.$name.'>';
- return $xmlstr;
- }
- function array2xmltype($value) {
- if (is_float($value)) {
- return "float";
- }
- if (is_int($value)) {
- return "int";
- }
- if (is_object($value)) {
- return get_class($value);
- }
- return "string";
- }
-}
-
-/* CLASS CKLIB WSDL ********************************************************************************************************* */
-
-class CKLIB_DESC extends CKLIB {
- private function gen_description_util($min, $max) {
- $tmp="";
- $tmp1="";
- if ($min != "0" && $min != "") { $tmp1="required"; }
- if (@$max > 1) { $tmp="Array(" . $min . " to " . $max . ")"; }
- if (@$max == "unbounded") { $tmp="Array(" . $min . " to unlimited)"; }
- return ($tmp . " " . $tmp1);
- }
-
- protected function gen_description() {
- $t1=microtime(true);
- echo $this->html_header();
-
- if ($this->verbose>=2) {
- echo "Name Web Service :" . $this->NAME_WS . "
";
- echo "Namespace :
" . $this->NAMESPACE . "";
- echo "WSDL :
WSDL description";
- echo "Protocols Supported :".(($this->soap11)?"SOAP 1.1, ":"").(($this->soap12)?"SOAP 1.2 (2.0), ":"").(($this->get)?"HTTP GET, ":"").(($this->post)?"HTTP POST, ":"")."None
";
- if (method_exists($this,'source')) {
- echo "Source :
Source Generation";
- }
- }
- if ($this->verbose>=1) {
- echo "
List of Operations
";
- $jsall="";
- echo $jsall;
- echo "
List of Complex Types
";
- $jsall="";
- echo $jsall;
- }
- // copyright
- echo $this->html_footer($t1);
- }
-
-}
-
-/* CLASS CKLIB WSDL ********************************************************************************************************* */
-
-class CKLIB_WSDL extends CKLIB_DESC {
- public function genwsdl() {
- if ($this->custom_wsdl!=$this->FILE."?wsdl") {
- // se usa un archivo customizado.
- $handle = @fopen($this->custom_wsdl, "r");
- if ($handle) {
- $contents = fread($handle, filesize($this->custom_wsdl));
- } else {
- $contents= "file or url :".$this->custom_wsdl." can't be open
\n";
- }
- fclose($handle);
- return $contents;
- }
- $cr="\n";
- $tab1="\t";
- $wsdl='encoding.'" ?>' . $cr;
- $wsdl.='soap12) {
- $wsdl.=' xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ';
- }
- $wsdl.=' xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">'
- . $cr;
- if ($this->description) {
- $wsdl.=''.$this->description.'';
- }
- // types ***
- $wsdl.=$tab1 . '' . $cr . '' . $cr;
- // elementos in
- foreach ($this->operation as $key => $value) {
- $wsdl.='
-
-
- ';
- foreach ($value["in"] as $key2 => $value2) {
- $minOccurs=$value2["minOccurs"];
- $maxOccurs=$value2["maxOccurs"];
- $wsdl.='';
- if (@$value2["description"]) {
- //$wsdl.=''.$value2["description"].'';
- }
- $wsdl.='';
- }
- $wsdl.='
-
- ';
- // out
- $wsdl.='
-
-
- ';
- foreach ($value["out"] as $key2 => $value2) {
- $minOccurs=$value2["minOccurs"];
- $maxOccurs=$value2["maxOccurs"];
- $wsdl.='';
- if (@$value2["description"]) {
- //$wsdl.=''.$value2["description"].'';
- }
- $wsdl.='';
- }
- foreach ($value["in"] as $key2 => $value2) {
- if (@$value2["byref"]) {
- $minOccurs=$value2["minOccurs"];
- $maxOccurs=$value2["maxOccurs"];
- $wsdl.='';
- }
- }
-
- $wsdl.='
-
-
- ';
- }
- // complex types
- foreach ($this->complextype as $key => $value) {
- $wsdl.='
-
- ';
- foreach ($value["elements"] as $key2 => $value2) {
- $minOccurs=$value2["minOccurs"];
- $maxOccurs=$value2["maxOccurs"];
- $type=str_replace($this->NAMESPACE, "tns", $value2["type"]);
- $wsdl.=' ';
- if (@$value2["description"]) {
- //$wsdl.=''.$value2["description"].'';
- }
- $wsdl.='';
- }
- $wsdl.='
-
- ';
- }
- // end types
- $wsdl.='
-
- ';
- // messages
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='
-
-
- ';
- $wsdl.='
-
-
- ';
- if ($this->get) {
- $wsdl.='
-
-
- ';
- $wsdl.='
-
-
- ';
- }
-
- if ($this->post) {
- $wsdl.='
-
-
- ';
- $wsdl.='
-
-
- ';
- }
- }
- // porttype
- $wsdl.='';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='';
- if (@$value["description"]) {
- $wsdl.=''.@$value["description"].'';
- }
- $wsdl.='';
- }
- $wsdl.='';
- if ($this->get) {
- $wsdl.='';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='';
- if (@$value["description"]) {
- $wsdl.=''.@$value["description"].'';
- }
- $wsdl.='';
- }
- $wsdl.='';
- }
- if ($this->post) {
- $wsdl.='';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='';
- if (@$value["description"]) {
- $wsdl.=''.@$value["description"].'';
- }
- $wsdl.='';
- }
- $wsdl.='';
- }
-
- // binding
- if ($this->soap11) {
- $wsdl.='
-
- ';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='
-
-
-
-
- ';
- }
- $wsdl.='';
- }
- // binding12
- if ($this->soap12) {
- $wsdl.='
- ';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='
-
-
-
-
- ';
- }
- $wsdl.='';
- }
- // binding12 (get)
- if ($this->soap12 and $this->get) {
- $wsdl.='
- ';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='';
- $wsdl.='';
- $wsdl.='';
- $wsdl.='';
- }
- $wsdl.='';
- }
-
-
-
- // binding12 (post)
- if ($this->soap12 and $this->post) {
- $wsdl.='
- ';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='';
- $wsdl.='';
- $wsdl.='';
- $wsdl.='';
- }
- $wsdl.='';
- }
- // service
-
- $wsdl.='';
-
- if ($this->soap11) {
- $wsdl.='
- ';
- }
- if ($this->soap12) {
- $wsdl.='
- ';
- if ($this->get) {
- $wsdl.='
- ';
- }
- if ($this->post) {
- $wsdl.='
- ';
- }
-
- }
- $wsdl.='';
- return $wsdl;
- }
-}
-
-
-/* CLASS CKLIB WSDL ********************************************************************************************************* */
-
-class CKLIB_SRC extends CKLIB_WSDL {
-
- protected function Param2PHPvalue($type,$max) {
- $x1=explode(":", $type);
- if (count($x1) != 2) { return "// type $type not defined "; }
- $space=$x1[0];
- $name=$x1[1];
- $p="";
- if ($space == "s") {
- if (!in_array($name, $this->predef_types)) {
- return "// type $type not found";
- }
- if (!in_array($name, $this->predef_types_num)) {
-
- $p="'value'";
- } else {
- $p="0";
- }
- }
- if ($space == "tns") {
- foreach ($this->complextype as $key => $value) {
- if ($name == $value["name"]) {
- $p= '$_'.$name;
- }
- }
- if ($p==="") {
- return "// complex type $type not found";
- }
- }
- if ($p!=="") {
- switch($max) {
- case "unbounded":
- return "array($p,$p,...)";
- break;
- case "1":
- return $p;
- break;
- default:
- $tmp="array(";
- for ($i=0;$i<$max;$i++) {
- $tmp.=$p.",";
- }
- $tmp=$this->right($tmp,1).")";
- return($tmp);
- break;
- }
- }
- return "\\ complex type $type not defined";
- }
- protected function Param2PHP($type,$max) {
- $x1=explode(":", $type);
- if (count($x1) != 2) { return "// type $type not defined "; }
- $space=$x1[0];
- $name=$x1[1];
- if ($space == "s") {
- if (!in_array($name, $this->predef_types)) {
- return "// type $type not found";
- }
- $p=$this->Param2PHPvalue($type,$max);
- if ($max=="unbounded") {
- return "array($p,$p,...)";
- }
- if ($max==1) {
- return $p;
- }
- $tmp="array(";
- for ($i=0;$i<$max;$i++) {
- $tmp.=$p.",";
- }
- $tmp=$this->right($tmp,1).")";
- return($tmp);
- }
- $resultado="";
- if ($space == "tns") {
- $ok=false;
- foreach ($this->complextype as $key => $value) {
- if ($name == $value["name"]) {
-
- foreach ($value["elements"] as $key2 => $value2) {
- $resultado.="\$_".$name."['".$value2["name"]."']=".$this->Param2PHPValue($value2["type"],$value2["maxOccurs"]).";\n";
- //$resultado.="'".$value2["name"]."'=>".$this->Param2PHP($value2["type"],$value2["maxOccurs"]).",";
- }
- $resultado=$this->right($resultado);
- return($resultado);
- }
- }
- return "\\ complex type $type not defined";
- }
- }
-
- protected function genphpast($text,$lenght=100) {
- $L=($lenght-6-strlen($text))/2;
- $L=($L<1)?1:$L;
- $ast=str_repeat("*",$L);
- $texto="/*".$ast." ".$text." ".$ast."*/\n";
- return $texto;
- }
- protected function genphp() {
- $r=$this->genphpast("Implementation");
- foreach ($this->operation as $key => $value) {
- $param="";
- foreach ($value["in"] as $key2 => $value2) {
- $param.=($value2["byref"])?"&":"";
- $param.="$".$value2["name"].", ";
-
- }
- if ($param!="") {
- $param=$this->right($param,2);
- }
- $r.="\n".$this->genphpast("Function ".$value["name"]." = ".$value["description"]);
- $r.="function ".$value["name"]."($param) {\n";
- $r.="\ttry {\n";
-
- $r.="\t\t// Input Values.... \n";
- $r.="\t\t/*\n";
- $param="";
- foreach ($value["in"] as $key2 => $value2) {
- $param.="\t\t\$_".$value2["name"]."=".$this->Param2PHPValue($value2["type"],$value2["maxOccurs"]).";\n";
- }
-
- $r.=$param;
- $r.="\t\t*/\n";
- $r.="\t\t// End Input Values \n";
- foreach ($value["out"] as $key2 => $value2) {
- $r.="\t\t\$_".$value["name"]."Result=".$this->Param2PHPValue($value2["type"],$value2["maxOccurs"]).";\n";
- }
- foreach ($value["out"] as $key2 => $value2) {
-
- $param.=$this->Param2PHPvalue($value2["type"],$value2["maxOccurs"]);
-
- }
- //$r.="\t\t \$result=\$_".$value["name"]."Result ".$param."; \n";
- $r.="\t\t return \$_".$value["name"]."Result; \n";
- $r.="\t} catch (Exception \$_exception) {\n";
- $r.="\t\treturn(array(\"soap:Fault\"=>'Caught exception: '. \$_exception->getMessage()));\n";
- $r.="\t}\n";
- $r.="}\n";
- }
- $r.="\n".$this->genphpast("Complex Types");
- foreach ($this->complextype as $key => $value) {
- $param="";
- $r.="\n".$this->genphpast("tns:".$value["name"]);
- $r.=$this->Param2PHP("tns:".$value["name"],@$value["maxOccurs"])."\n";
- }
- $r.="\n".$this->genphpast("Complex Types (Classes)");
- foreach ($this->complextype as $key => $value) {
- $param="";
- $r.="\nclass ".$value["name"]." {\n";
- foreach ($value["elements"] as $key2 => $value2) {
- $r.="\tvar ".$value2["name"]."; // ".$value2["type"]."\n";
- }
- $r.="}\n";
- }
- return $r;
- }
-
-
-
- protected function genphpclient($soapversion="1.2") {
-
- $r.= "\n";
- $r.= "include_once 'ckclient.php';\n";
- $r.=$this->genphpast("Implementation");
- $r.= "class ".$this->NAME_WS."Client {\n";
- $r.= "\tvar \$url='".$this->FILE."';\n";
- $r.= "\tvar \$tempuri='".$this->NAMESPACE."';\n";
- foreach ($this->operation as $key => $value) {
- $functionname=$value["name"];
- $param="";
- foreach ($value["in"] as $key2 => $value2) {
- $param.=($value2["byref"])?"&":"";
- $param.="$".$value2["name"].", ";
-
- }
- if ($param!="") {
- $param=$this->right($param,2);
- }
- $r.="\n\t// ".@$value["description"]." \n";
- foreach ($value["in"] as $key2 => $value2) {
- $varname=$value2["name"];
- $r.="\t// $varname = ".$value2["description"]." \n";
- }
- $r.="\tfunction $functionname($param) {\n";
- $r.="\t\t\$_obj=new CKClient();\n";
- $r.="\t\t\$_obj->tempuri=\$this->tempuri;\n";
- $r.="\t\t\$_param='';\n";
- foreach ($value["in"] as $key2 => $value2) {
- $varname=$value2["name"];
- $r.="\t\t\$_param.=\$_obj->array2xml(\$$varname,'ts:$varname',false,false);\n";
- }
- $r.="\t\t\$resultado=\$_obj->loadurl(\$this->url,\$_param,'$functionname');\n";
- foreach ($value["in"] as $key2 => $value2) {
- if ($value2["byref"]) {
- $r.="\t\t\$".$value2["name"]."=@\$resultado['".$value2["name"]."'];\n";
- }
- }
- $r.="\t\treturn @\$resultado['".$functionname."Result'];\n";
- $r.="\t}\n";
-
- }
- $r.="} // end ".$this->NAME_WS."\n";
- $r.="?>\n";
- return $r;
- }
-
- protected function genunitycsharp() {
- $r=$this->genphpast("Implementation");
-
- $r.='using UnityEngine;
-
-using System.IO;
-using System.Xml.Serialization;
-using System;
-using System.Text;
-using System.Collections;
-using System.Collections.Generic;
-
-public class '.$this->NAME_WS.' : MonoBehaviour
-{
- // Use this for initialization
- private string charset = "UTF-8";
- private string url = "'.$this->FILE.'";
- private string tempuri = "'.$this->NAMESPACE.'";
- private string prefixns = "ts";
- public string cookie="";
- ';
-
- foreach ($this->operation as $key => $value) {
- $tmpname=$value["name"];
- if (count($value["out"])>=1) {
- $outtype=$this->fixtag($value["out"][0]["type"]);
- $outtypereal=$this->type2csharp($outtype);
- } else {
- $outtype="";
- $outtypereal="";
- }
-$r.='
- // '.$tmpname.'
- public Boolean is'.$tmpname.'Running = false;
- private WWW webservice'.$tmpname.';
- public string '.$tmpname.'Error="";
-
- public '.$outtypereal.' '.$tmpname.'Result;
- // End '.$tmpname.'
-';
- }
- $r.=' private void Start()
- {
- return;
- }';
- foreach ($this->operation as $key => $value) {
- $tmpname=$value["name"];
- $param="";
- foreach ($value["in"] as $key2 => $value2) {
- $param.=$this->fixtag($value2["type"])." ".$value2["name"].",";
- }
- $param=$this->right($param,1);
- $r.='
- private void '.$tmpname.'Async('.$param.')
- {
- string namefunction = "'.$tmpname.'";
- Single soapVersion=1.1f;
- string ss2 = SoapHeader(namefunction,soapVersion);';
-
- foreach ($value["in"] as $key2 => $value2) {
- $name=$value2["name"];
- $r.='
- ss2 += "<" + prefixns + ":'.$name.'>" + Obj2XML('.$name.',true) + "" + prefixns + ":'.$name.'>";
- ';
- }
-
- if (count($value["out"])>=1) {
- $outtype=$this->fixtag($value["out"][0]["type"]);
- $outtypereal=$this->type2csharp($outtype);
- $outinit=$this->csharp_init($outtype);
- } else {
- $outtype="";
- $outtypereal="";
- }
-
-
- $r.='ss2 += SoapFooter(namefunction,soapVersion);
- is'.$tmpname.'Running = true;
- StartCoroutine('.$tmpname.'Async2(ss2));
- }
- private IEnumerator '.$tmpname.'Async2(string ss2) {
- string namefunction = "'.$tmpname.'";
- Single soapVersion=1.1f;
- byte[] bb = System.Text.Encoding.UTF8.GetBytes(ss2);
- var headers = header(namefunction,soapVersion);
- if (cookie!="") {
- headers.Add("Set-Cookie",cookie);
- }
- webservice'.$tmpname.' = new WWW(url, bb, headers);
- while( !webservice'.$tmpname.'.isDone ) {
- yield return new WaitForSeconds(0.5f);
- }
- is'.$tmpname.'Running = false;
- string other = cleanSOAPAnswer(webservice'.$tmpname.'.text, "'.$tmpname.'",ref '.$tmpname.'Error);
- ';
- if ($outtype!="") {
- $r.=$tmpname."Result=".$outinit.";\n";
- $r.=' '.$tmpname.'Result=('.$outtypereal.')XML2Obj(other,"'.$outtype.'",'.$tmpname.'Result.GetType());
- ';
- }
- $r.='webservice'.$tmpname.'.responseHeaders.TryGetValue("SET-COOKIE",out cookie);
- ';
- $r.=$tmpname.'AsyncDone();
- }
- public void '.$tmpname.'AsyncDone() {
- // we do something...';
- if ($outtype!="") {
- $r.='
- // '.$outtypereal.' dnx='.$tmpname.'Result;';
- }
- $r.='
- }
- ';
- }
-
- $r.='
- #region util_function
- private Hashtable header(string nameFunction,Single soapVersion) {
- var tmpheader=new Hashtable();
- if (soapVersion>=1.2) {
- tmpheader["Content-Type"] = "application/soap+xml;charset" + charset + ";action=\"" + url + "/" + nameFunction +"\"";
- } else {
- tmpheader["Content-Type"] = "text/xml;charset" + charset;
- tmpheader["SOAPAction"]= "\""+ tempuri + "/" + nameFunction +"\"";
- }
- return tmpheader;
- }
-
-
- private string cleanSOAPAnswer(string text, string functionname,ref string last_error )
- {
- int p0, p1, pbody;
- string tmp = functionname + "Result";
- pbody = text.IndexOf("");
- if (pbody<0) {
- last_error="No soap found";
- return "";
- }
- p0 = text.IndexOf("<" + tmp, pbody);
- if (p0 <= 0)
- {
- return "";
- }
- p0 = text.IndexOf(">", p0) + 1;
- p1 = text.IndexOf("" + tmp, p0);
- if (p1 < p0)
- {
- tmp = "";
- }
- else
- {
- tmp = text.Substring(p0, p1 - p0);
- }
- return tmp;
- }
-
- private string SoapHeader(string nameFunction,Single soapVersion)
- {
- string ss2;
- if (soapVersion>=1.2) {
- ss2 = "";
- ss2 += "";
- } else {
- ss2 = "";
- ss2 += "";
- }
- ss2 += "<" + prefixns + ":" + nameFunction + ">";
-
- return ss2;
- }
-
- private string SoapFooter(string nameFunction,Single soapVersion)
- {
- string ss2;
- ss2 = "" + prefixns + ":" + nameFunction + ">";
- if (soapVersion>=1.2f) {
- ss2 += "";
- } else {
- ss2 += "";
- }
-
- return ss2;
- }
-
- private string Obj2XML(object obj)
- {
- return Obj2XML(obj, false, false);
- }
-
- private string Obj2XML(object obj, Boolean withns)
- {
- return Obj2XML(obj, withns, false);
- }
-
- private string Obj2XML(object obj, Boolean withns, Boolean full)
- {
- string myStr, types;
-
- if (obj.GetType().Namespace == "System")
- {
- types = obj.GetType().Name.ToLower();
- types = (withns) ? prefixns + ":" + types : types;
- if (full)
- {
- myStr = "<" + types + ">" + obj.ToString() + "" + types + ">";
- }
- else
- {
- myStr = obj.ToString();
- }
- }
- else
- {
- var mstream = new MemoryStream();
- XmlSerializer SerializerObj = new XmlSerializer(obj.GetType(), tempuri);
- if (withns)
- {
- var namespaces = new XmlSerializerNamespaces();
- namespaces.Add(prefixns, tempuri);
- SerializerObj.Serialize(mstream, obj, namespaces);
- }
- else
- {
- SerializerObj.Serialize(mstream, obj);
- }
-
- mstream.Position = 0;
- var sreader = new StreamReader(mstream);
- myStr = sreader.ReadToEnd();
- // cut xml and first node element from the xml
- if (!full)
- {
- var arr = myStr.Split(new char[] {'."'".'\n'."'".'}, StringSplitOptions.None);
- //var arr2 = "";
- int lim = arr.Length - 3;
- var arr2 = String.Join("", arr, 2, lim);
- myStr = arr2;
- }
- }
-
- return myStr;
- }
- private object XML2Obj(string xmlstr, string typedesc, Type type) {
- return XML2Obj( xmlstr, typedesc,type,false);
- }
- private object XML2Obj(string xmlstr, string typedesc, Type type,Boolean full)
- {
- if (!full)
- {
- xmlstr = "" + "<" + typedesc + ">" + xmlstr + "" + typedesc + ">";
- }
- var objdummy = new object();
- var SerializerObj = new XmlSerializer(type);
-
- byte[] byteArray = Encoding.ASCII.GetBytes(xmlstr);
- objdummy = SerializerObj.Deserialize(new MemoryStream(byteArray));
-
- return objdummy;
- }
- #endregion
-} // end class.
- ';
-
- $r.="\n".$this->genphpast("Complex Types (Classes)");
- foreach ($this->complextype as $key => $value) {
- $param="";
- $type=$this->fixtag($value2["type"]);
-
-
- if (strlen($value["name"])>7 and substr($value["name"],0,7)=="ArrayOf") {
-
- } else {
- $r.="\npublic class ".$value["name"]." {\n";
- foreach ($value["elements"] as $key2 => $value2) {
- $r.="\tprivate ".$type." _".$value2["name"]."; \n";
- }
- $r.="\n";
- foreach ($value["elements"] as $key2 => $value2) {
- $r.="\tpublic ".$type." ".$value2["name"]."\n";
- $r.="\t{\n";
- $r.="\t\tget { return _".$value2["name"]."; }\n";
- $r.="\t\tset { _".$value2["name"]." = value; }\n";
- $r.="\t}\n";
- }
-
- $r.="}\n";
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- return($r);
- }
- protected function csharp_init($type) {
- // ArrayOfS
- // 12345678
- switch($type) {
- case "string":
- case "String":
- return '""';
- break;
- case "int":
- case "long":
- case "Single":
- return '0';
- break;
- default:
- return "new ".($this->type2csharp($type))."()";
- }
- }
- protected function type2csharp($type) {
- // ArrayOfS
- // 12345678
- $l=strlen($type);
-
- if ($l>8 and substr($type,0,7)=="ArrayOf") {
- $type="List<".substr($type,7,$l-7).">";
- return $this->type2csharp($type);
- } else {
- return $type;
- }
- }
- protected function source() {
- echo $this->html_header();
- echo "
List of Operations
";
- echo $this->html_footer();
-
- return "";
- }
-}
-
-
-
-
-?>
\ No newline at end of file
diff --git a/wslib/cklib.2.4.php b/wslib/cklib.2.4.php
deleted file mode 100644
index 3ddb77e..0000000
--- a/wslib/cklib.2.4.php
+++ /dev/null
@@ -1,2042 +0,0 @@
-
-/*
-CloudKing Server
-Version 2.4
-Copyright Jorge Castro Castillo
-License http://www.southprojects.com/product/cloudking/license1-1/
-
-
-
- * Link: http://www.southprojects.com/cloudking
- *
- * functions : * constructor CLOUDKING($FILE,$NAMESPACE,$NAME_WS);
- * $FILE = php url (eg. http://127.0.0.1/ws.php )
- * $NAMESPACE = Namespace (default is http://test-uri/ it must finish with trail slash);
- * $NAME_WS = Name of the service (default is WebService1);
- * Use :Create the soap engine object.
- * Return :Nothing.
- *
- * * addfunction($name,$array_in,$array_out,$description)
- * $name = name of the function (case sensitive).
- * $array_in = Array with the input parameter(s) (**).
- * $array_out = Array with the output parameter (**) (only a array of a single paramter).
- * Use :Add a new function.
- * Return :Nothing.
- *
- * * addtype($name,$array_member)
- * $name = Name of the complex type (without namespace).
- * $array_member = Array with the member value(s) (**).
- * Use :Add a new complex type.
- * Return :Nothing.
- *
- * * run()
- * Use :Execute the engine.
- * Return :true if executed correctly, otherwise false.
- *
- * * save_wsdl($filename)
- * $filename = Name of the filename (local).
- * Use :Save the wsdl into a file.
- * Return :Nothing.
- *
- * * $copyright = copyright description (string,optional)
- * * $description = description of the web service (string,optional)
- * * $verbose = 0 by default (string,optional)
- * * $allowed = array of ip or url of clients that are allowed (optional,"*" everyone by default)
- * * $disallowed = array of ip or url of clients that are not allowed (optional,"" nobody by default)
- * * $custom_wsdl = wsdl file used for the information(if we want to avoid auto generation)
- * (**) definition of arrays:
- * array(
- * array("name"=>*name of the variable* (required)
- * ,"type"=>*type of the variable (with namespace required, for example tns:customtype , s:predefinedtype)
- * ,"minOccurs"=>*min value* (optional)
- * ,"maxOccurs"=>*max value* (optional, it can be "unbounded")
- * ,"extra"=>*a extra parameter (optional, for example 'nillable="true"')
- * ), ....
- * );
- *
- * what's missing
- * * SOAP Authentication (text and digest).
- * what's new:
- * 2.4 fix param (null)
- * 2.3.4 add PHP Client generation
- * 2.3.1 description tag fix.
- * 2.3 Extra fix, Unity generation code.
- * 2.2.2 Array2Xml fix (speedup, self type generation).
- * 2.2.1 Small Javascript function (description screen)
- * 2.1 Fix done, forced input parameters (still, every parameter is considered as optional).
- * 2.1 POST & GET (SOAP & REST-Style)
- * 2.0 Parse json and post.
- * 1.95 Generate Unity c# code (class)
- * 1.9 Add class and object as a alternative to arrays
- * Generate PHP code (class).
- * 1.8 Add pre-defined format long.
- * Generate PHP code.
- * Header fix (text/xml for soap 1.1 and application/soap+xml for soap 1.2)
- * 1.7 Allow parameter by reference
- * 1.6 Security
- * 1.5 custom_wsdl
- * verbose added (changed from production flag).
- * bug fixed (array).
- * encapsulated field.
- * 1.4 service description fixed.
- * allowed and disallowed array.
- * bug fixed
- * 1.3 bug fixed.
- * service description include a self evaluation system (variables not defined).
- * 1.2 service description added
- * 1.1 bug fixed.
- * 1.0 bug fixed.
- * 0.9b first operative version.
- * 0.8b custom NUSOAP library dropped, massive incompatibilities with custom library.
-*/
-class CKLIB {
- protected $FILE;
- protected $NAMESPACE;
- protected $NAME_WS;
- protected $operation;
- protected $complextype;
- protected $version="2.4";
-
- protected $predef_types=array
- (
- "string",
- "long",
- "int",
- "integer",
- "boolean",
- "decimal",
- "float",
- "double",
- "duration",
- "dateTime",
- "time",
- "date",
- "gYearMonth",
- "gYear",
- "gMonthDay",
- "gDay",
- "gMonth",
- "hexBinary",
- "base64Binary",
- "anyURI",
- "QName",
- "NOTATION"
- );
- protected $predef_types_num=array
- (
- "long",
- "int",
- "integer",
- "boolean",
- "decimal",
- "float",
- "double",
- "duration"
- );
- var $soap11=true;
- var $soap12=true;
- var $get=true;
- var $post=true;
- var $allowed_input=array("json"=>true,"rest"=>true,"php"=>true,"xml"=>true,"none"=>true);
- var $oem=false;
-
- var $encoding="UTF-8"; // ISO-8859-1
- var $custom_wsdl="";
- var $copyright=""; //Copyright �2009 - 2010, SouthProject www.southprojects.com";
- var $description="CLOUDKING Server is running in this machine";
- var $verbose=0;
- var $wsse_username="";
- var $wsse_password="";
- var $wsse_nonce="";
- var $wsse_created="";
- var $wsse_password_type="None"; //None, PasswordDigest, PasswordText
- var $variable_type="array"; // array or object. it define if the implementation will use array (or primitives) or objects
- var $object_function=""; // nombre del objeto, if empty then it call a single function
- var $allowed=array("*");
- var $disallowed=array("");
-
-
- public function CKLIB($FILE, $NAMESPACE="http://test-uri/", $NAME_WS="CKService1") {
- return $this->_CKLIB($FILE, $NAMESPACE, $NAME_WS);
- }
- private function _CKLIB($FILE, $NAMESPACE, $NAME_WS) {
-
- if (@$_SERVER["HTTPS"]) {
- $FILE=str_replace("http://","https://",$FILE);
- }
- $this->FILE=$FILE;
-
-
- $this->NAMESPACE=($NAMESPACE!="")?$NAMESPACE:$FILE."/";
- $this->NAME_WS=($NAME_WS!="")?$NAME_WS:"CKService1";
- $this->operation=array();
- $this->complextype=array();
- $this->custom_wsdl=$this->FILE."?wsdl";
- }
- private function class2array($class,$classname)
- {
- if (is_object($class)) {
- $resultado= (array)$class;
-
- $idx=$this->findIdxComplexType($classname);
- foreach($this->complextype[$idx]["elements"] as &$value) {
- if (strpos($value["type"],"tns:",0)!==false) {
- $tmp=$this->class2array($resultado[$value["name"]],$this->fixtag($value["type"]));
- if ($tmp!="") {
- //$resultado[$value["name"]]=$tmp;
- }
- }
- }
- } else {
- $resultado[$classname]=$class;
- }
- return $resultado;
- }
- private function findIdxComplexType($complexname)
- {
-
- foreach ($this->complextype as $key => $value) {
- if ($value["name"]==$complexname) {
- return $key;
- }
- }
- return -1;
-
- }
- private function array2class($arr, $newclass)
- {
- if ($arr==null) {
- return null;
- }
- $object=(object)$arr;
- if( !class_exists($newclass) )
- {
- // We'll save unserialize the work of triggering an error if the class does not exist
- trigger_error('Class ' . $newclass . ' not found', E_USER_ERROR);
- return false;
- }
- $serialized_parts = explode(':', serialize($object));
- $serialized_parts[1] = strlen($newclass);
- $serialized_parts[2] = '"' . $newclass . '"';
- $result=unserialize(implode(':', $serialized_parts));
- // aqui recorremos los miembros
- $idx=$this->findIdxComplexType($newclass);
- if ($idx==-1) {
- trigger_error('Complex Type ' . $newclass . ' not found', E_USER_ERROR);
- return false;
- }
- foreach($this->complextype[$idx]["elements"] as &$value) {
- if (strpos($value["type"],"tns:",0)!==false) {
- $result->$value["name"]=$this->array2class($result->$value["name"],$this->fixtag($value["type"]));
- }
- }
-
- return $result;
- }
-
- public function set_copyright($copyright) {
- $this->copyright=$copyright;
- }
- public function save_wsdl($filename) {
- return $this->save_wsdl($filename);
- }
- private function _save_wsdl($filename) {
- if (!$fp=fopen($filename, 'a')) { return "file '$filename' can't be saved"; }
- if (fwrite($fp, $this->genwsdl()) === false) { return "information can't be saved"; }
- ;
- @fclose($fp);
- return "ok";
- }
- private function ws_security() {
- /*
- $password = "password";
- $created_time_stamp = date("Y-m-d\TH:i:s\Z");
- $nonce = uniqid(time());
- */
-
- }
- /*
- public function password_correct($password,$type="None") {
- if ($type!=$this->wsse_password_type) {
- return false; // method not equal
- }
- if ($this->wsse_password_type=="PasswordDigest") {
- $wsse_nonce=$this->wsse_nonce;
- $wsse_created=$this->wsse_created;
- $nonce = base64_decode($wsse_nonce);
- $password_digest = base64_encode(sha1($nonce.$wsse_created.$password, true));
- return ($ns->wsse_password==$password_digest);
- };
- if ($this->wsse_password_type=="PasswordText") {
- return ($ns->wsse_password==$password);
- };
- return true;
- }
- */
- protected function right($string,$num_cut=1) {
- if (strlen($string)-$num_cut>=0) {
- return substr($string,0,strlen($string)-$num_cut);
- }
- return $string;
- }
-
- private function security() {
- $ip=$_SERVER['REMOTE_ADDR'];
- $hostname=gethostbyaddr($_SERVER['REMOTE_ADDR']);
- foreach ($this->disallowed as $value) {
- if ($value == $hostname or $value == $ip) { echo ("host $ip $hostname not allowed (blacklist)\n"); return false;}
- }
- foreach ($this->allowed as $value) {
- if ($value == "*" or $value == $hostname or $value == $ip) { return true; }
- }
- echo ("host $ip $hostname not allowed \n");
- return false;
- }
- public function run() {
- return $this->_run();
- }
- private function _run() {
- if (!$this->security()) {
- return false;
- }
- global $_REQUEST;
- $param=@$_SERVER['QUERY_STRING']."&=";
- $p=strpos($param,"&");
- $p1=strpos($param,"=");
- $paraminit=substr($param,0,min($p,$p1)); // ?{value}&other=aaa
-
-
- $HTTP_RAW_POST_DATA=@$GLOBALS['HTTP_RAW_POST_DATA'];
- $methodcalled="soap";
- $isget=false;
- $methodcalled=($paraminit=="")?"soap":$paraminit;
- $methoddefined=false;
- if (strlen($methodcalled)>=3) {
- if (substr($methodcalled,0,3)=="get" and $this->get) {
- $methodcalled= str_replace("get","",$methodcalled);
- $methodcalled=($methodcalled==""?"none":$methodcalled);
- $isget=true;
- $methoddefined=true;
- }
- }
- if (strlen($methodcalled)>=4) {
- if (substr($methodcalled,0,4)=="post" and $this->post) {
- $methodcalled= str_replace("post","",$methodcalled);
- $methodcalled=($methodcalled==""?"none":$methodcalled);
- $isget=false;
- $methoddefined=true;
- }
- }
- $info=explode("/",@$_SERVER["PATH_INFO"]);
- $function_name=(count($info)>=2)?$info[1]:"unknown_unknown";
- $function_out=(count($info)>=3)?$info[2]:$methodcalled;
-
- if (count($info)>=4 and $this->get) {
- // is passing more that the functionname and output type 0> is rest myphp?php/functionname/typeout/p1/p2....
- $isget=true;
- $methodcalled="rest";
- $methoddefined=true;
- }
- if ($this->soap12) {
- if (!$methoddefined and $HTTP_RAW_POST_DATA=="" and $function_name!="unknown_unknown" and $this->get) {
- // mypage.php/functioname?param1=......
- $methodcalled="none";
- $function_out="xml";
- $isget=true;
- $methoddefined=true;
- }
- if (!$methoddefined and $function_name!="unknown_unknown" and $this->post) {
- // mypage.php/functioname (it must be soap http post).
-
- $methodcalled="none";
- $function_out="xml";
- $HTTP_RAW_POST_DATA=" "; // only for evaluation.
- $isget=false;
- $methoddefined=true;
- }
- }
- if (!@$this->allowed_input[$methodcalled] and $methoddefined) {
-
- trigger_error("method $methodcalled not allowed", E_USER_ERROR);
- return false;
- }
-
-
-
- if ($HTTP_RAW_POST_DATA!="" or $isget) {
- // is trying to evaluate a function.
-
- // ejemplo :http://www.micodigo.com/webservice.php/functionname/xml?getjson&value1={json..}&value2={json}
- //info(0)=0
- //info(1)=functionname
- //info(2)=serialize return type (optional, by default is the same name as passed)
-
-
-
- $res=false;
- switch($methodcalled) {
- case "soap":
- case "wsdl":
- $res= $this->requestSOAP($HTTP_RAW_POST_DATA);
- break;
- case "json":
- case "rest":
- case "php":
- case "xml":
- case "none":
-
- $res= $this->requestNOSOAP($function_name,$function_out,$methodcalled,$isget,$info);
- break;
- }
- if ($res) {
- echo $res;
- return true;
- } else {
- return false;
- }
- } else {
- switch ($paraminit) {
- case "wsdl":
- header("content-type:text/xml;charset=".$this->encoding);
- echo $this->genwsdl();
- return true;
- break;
- case "source":
- if ($this->verbose>=2) {
- switch (@$_GET["source"]) {
- case "php":
-
- if (method_exists($this,'genphp')) {
- header("content-type:text/plain;charset=".$this->encoding);
- echo $this->genphp();
- } else {
- echo "not supported
";
- }
- break;
- case "phpclient":
-
- if (method_exists($this,'genphpclient')) {
- header("content-type:text/plain;charset=".$this->encoding);
- echo $this->genphpclient();
- } else {
- echo "Not supported
";
- }
- break;
- case "unity":
- if (method_exists($this,'genunitycsharp')) {
- header("content-type:text/plain;charset=".$this->encoding);
- echo $this->genunitycsharp();
- } else {
- echo "not supported
";
- }
- break;
- default:
- if (method_exists($this,'source')) {
- header("content-type:text/html");
- echo $this->source();
- } else {
- echo "not supported
";
- }
- break;
- }
- return true;
- }
- break;
- case "unitycsharp":
- if ($this->verbose>=2) {
- header("content-type:text/plain;charset=".$this->encoding);
- echo $this->genunitycsharp();
- return true;
- }
- break;
- }
-
- }
- if (method_exists($this,'gen_description')) {
- $this->gen_description();
- } else {
- echo $this->html_header();
- echo "Name Web Service :" . $this->NAME_WS . "
";
- echo $this->html_footer();
- }
- return true;
- }
- protected function html_footer($timer_init=0) {
- $r="";
- $t2=ceil((microtime(true)-$timer_init)*1000)/1000;
- //echo base64_encode("
Webserver powered by CLOUDKING")."
";
-
-
-
- $b1=base64_decode("PGhyPldlYnNlcnZlciBwb3dlcmVkIGJ5IDxhIGhyZWY9J2h0dHA6Ly93d3cuc291dGhwcm9qZWN0cy5jb20vY2xvdWRraW5nLw==");
- $b1.="version.php?version=".$this->version;
- $b1.=base64_decode("Jz5DTE9VREtJTkc8L2E+");
- //echo $b1;
- if (!$this->oem) {
- $r.= "$b1 ";
- if ($this->verbose>=1) {
- $r.= "Version " . $this->version.". ";
- }
- }
- if ($timer_init!=0) {
- $r.= "Generated in $t2 seconds
";
- }
- $r.= $this->copyright . "
";
- $r.= "
\n";
- $r.= '' . $this->NAME_WS . '
';
- $r.= "
" . $this->description . "
";
- return $r;
- }
- protected function var_is_defined($fullname) {
- $x1=explode(":", $fullname);
- if (count($x1) != 2) { return "
$fullname"; }
- $space=$x1[0];
- $name=$x1[1];
- if ($space == "s") {
- if (!in_array($name, $this->predef_types)) { return "
$fullname"; }
- return "
$fullname";
- }
- if ($space == "tns") {
- foreach ($this->complextype as $key => $value) {
- if ($name == $value["name"]) { return "
$fullname"; }
- }
- return "
$fullname";
- }
- return "
??$fullname";
- }
-
- public function addfunction($namefunction, $arr_in, $arr_out, $description="") {
- return $this->_addfunction($namefunction, $arr_in, $arr_out, $description);
- }
- private function _addfunction($namefunction, $arr_in, $arr_out, $description="") {
- if (count($arr_out) > 1) { trigger_error("output cannot exceed 1 value", E_USER_ERROR); }
- $description=($description == "") ? "The function $namefunction" : $description;
- foreach ($arr_in as $key => $value) {
- if ($arr_in[$key]["name"]=="") { trigger_error( "name must be defined",E_USER_ERROR); }
- $arr_in[$key]["name"]=(@$arr_in[$key]["name"]=="")?"undefined":$arr_in[$key]["name"];
- $arr_in[$key]["type"]=(@$arr_in[$key]["type"]=="")?"s:string":$arr_in[$key]["type"];
- $arr_in[$key]["minOccurs"]=(@$arr_in[$key]["minOccurs"]=="")?0:$arr_in[$key]["minOccurs"];
- if (@$arr_in[$key]["maxOccurs"]>1 or @$arr_in[$key]["maxOccurs"]=="unbounded") { trigger_error("maxOccurs cannot be >1",E_USER_ERROR); }
- $arr_in[$key]["maxOccurs"]=(@$arr_in[$key]["maxOccurs"]=="")?1:$arr_in[$key]["maxOccurs"];
- $arr_in[$key]["extra"]=(@$arr_in[$key]["extra"]=="")?"":$arr_in[$key]["extra"];
- $arr_in[$key]["byref"]=(@$arr_in[$key]["byref"]=="")?false:$arr_in[$key]["byref"];
- }
- // it must be only one value (or zero).
- foreach ($arr_out as $key => $value) {
- $arr_out[$key]["type"]=(@$arr_out[$key]["type"]=="")?"s:string":$arr_out[$key]["type"];
- $arr_out[$key]["minOccurs"]=(@$arr_out[$key]["minOccurs"]=="")?0:$arr_out[$key]["minOccurs"];
- $arr_out[$key]["maxOccurs"]=(@$arr_out[$key]["maxOccurs"]=="")?1:$arr_out[$key]["maxOccurs"];
- $arr_out[$key]["extra"]=(@$arr_out[$key]["extra"]=="")?"":$arr_out[$key]["extra"];
- $arr_out[$key]["byref"]=(@$arr_out[$key]["byref"]=="")?false:$arr_out[$key]["byref"];
- }
-
- $this->operation[]=array
- (
- "name" => $namefunction,
- "in" => $arr_in,
- "out" => $arr_out,
- "description" => $description
- );
-
- return true;
- }
- public function addtype($nametype, $arr_param) {
- return $this->_addtype($nametype, $arr_param);
- }
- private function _addtype($nametype, $arr_param) {
- foreach ($arr_param as $key => $value) {
- $arr_param[$key]["name"]=(@$arr_param[$key]["name"]=="")?"undefined":$arr_param[$key]["name"];
- $arr_param[$key]["type"]=(@$arr_param[$key]["type"]=="")?"s:string":$arr_param[$key]["type"];
- $arr_param[$key]["minOccurs"]=(@$arr_param[$key]["minOccurs"]=="")?0:$arr_param[$key]["minOccurs"];
- $arr_param[$key]["maxOccurs"]=(@$arr_param[$key]["maxOccurs"]=="")?1:$arr_param[$key]["maxOccurs"];
- $arr_param[$key]["extra"]=(@$arr_param[$key]["extra"]=="")?"":$arr_param[$key]["extra"];
- $arr_param[$key]["byref"]=(@$arr_param[$key]["byref"]=="")?false:$arr_param[$key]["byref"];
- $arr_param[$key]["description"]=(@$arr_param[$key]["description"]=="")?"a value":$arr_param[$key]["description"];
- }
- $this->complextype[]=array
- (
- "name" => $nametype,
- "elements" => $arr_param
- );
- }
- private function requestSOAP($HTTP_RAW_POST_DATA) {
- global $param, $r;
- $soapenv="";
- if (strpos($HTTP_RAW_POST_DATA, "http://schemas.xmlsoap.org/soap/envelope/")) {
- if ($this->soap11) {
- header("content-type:text/xml;charset=".$this->encoding);
- $soapenv="http://schemas.xmlsoap.org/soap/envelope/";
- }
- }
- if (strpos($HTTP_RAW_POST_DATA, "http://www.w3.org/2003/05/soap-envelope")) {
- if ($this->soap12) {
- header("content-type:application/soap+xml;charset=".$this->encoding);
- $soapenv="http://www.w3.org/2003/05/soap-envelope";
- }
- }
- if ($soapenv == "") { die("soap incorrect or not allowed"); }
- $arr=$this->xml2array($HTTP_RAW_POST_DATA,0);
- $HTTP_RAW_POST_DATA=""; // free mem.
- $this->wsse_username=@$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Username"];
- $this->wsse_password=@$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Password"];
- $this->wsse_nonce=@$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Nonce"];
- $this->wsse_created=@$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Created"];
- $tmp=@$arr["Envelope"]["Header"]["Security"]["UsernameToken"]["Password_attr"]["Type"];
-
- if (strpos($tmp,"#PasswordText")) {
- $this->wsse_password_type="PasswordText";
- } else {
- if (strpos($tmp,"#PasswordDigest")) {
- $this->wsse_password_type="PasswordDigest";
- } else {
- $this->wsse_password_type="None";
- }
- }
-
-
-
-
- $funcion=array_keys($arr["Envelope"]["Body"]);
- $function_name0=$funcion[0];
- $function_name=$this->fixtag($function_name0); // "tem:getSix" (deberia ser solo una funcion?)
- // pasar los parametros
- $param=array();
-
- $paramt=" ";
- $i=0;
- $indice_operation=-1;
- foreach ($this->operation as $key => $value) {
- if ($value["name"]==$function_name) {
- $indice_operation=$key;
- }
- }
- if ($indice_operation>=0) {
- $my_operation=$this->operation[$indice_operation];
- foreach($my_operation["in"] as $value) {
- $param[]=@$arr["Envelope"]["Body"][$function_name0][$value["name"]];
- if (empty($param[$i])) {
- $param[$i]="";
- }
- $paramt.='@$param[' . $i . '],';
- $i++;
- }
-
- if ($this->variable_type=="object") {
- // convert all parameters in classes.
- foreach($param as $key=>$value) {
- $classname=$my_operation["in"][$key]["type"];
-
- if (strpos($classname,"tns:",0)!==false) {
-
- $param[$key]=$this->array2class($value,$this->fixtag($classname));
-// var_dump($param[$key]);
- } else {
- // not touched.
- }
-
- }
- }
-
- $param_count=count($param);
- $paramt=substr($paramt, 0, strlen($paramt) - 1);
- $r="";
- if ($this->object_function=="") {
- $evalstr="\$r=$function_name($paramt);";
- } else {
- @eval("global \$".$this->object_function.";");
- $evalstr="\$r=\$".$this->object_function."->$function_name($paramt);";
- }
-
-
- $evalret=eval($evalstr);
- if ($this->variable_type=="object") {
- $classname=$my_operation["out"][0]["type"];
- if (strpos($classname,"tns:",0)!==false) {
-
-
-
- $ttype=$this->fixtag($classname);
- $r=$this->class2array($r,$this->fixtag($classname),false,false);
-
-
- }
- //var_dump($r);
- //$r=@$r[$ttype];
-
-
- }
- } else {
- $evalret=array("soap:Fault"=>'Caught exception: function not defined');
- }
- //var_dump($r);
-
- //echo $this->array2xml($r,"array",false,false);
-
- if (is_array($r)) {
- $classname=$my_operation["out"][0]["type"];
-
-
- $serial=$this->array2xml($r, "array", false, false);
- //var_dump($serial);
- $l=strlen($serial);
- if ($l>2) {
- if (substr($serial,$l-1,1)=="\n") {
- $serial=substr($serial,0,$l-1);
- }
- }
-
-
- $serial=$this->fixarray2xml($serial);
- //var_dump($serial);
-
-
-
- if (@$r["soap:Fault"]!="") {
- $evalret=false;
- }
-
- } else {
- $serial=$r;
- }
- // agregamos si tiene valor byref.
- $extrabyref="";
- $indice=0;
- $key=$indice_operation;
- $value=$this->operation[$indice_operation];
-
- foreach ($value["in"] as $key2 => $value2) {
- if (@$value2["byref"]) {
- $paramtmp=@$param[$indice];
- if (is_array($paramtmp)) {
- $tmp2=$this->array2xml($paramtmp, "array", false, false);
- $tmp2=$this->fixarray2xml($tmp2);
- } else {
- $tmp2=$paramtmp;
- }
- $extrabyref.="<".$value2["name"].">".$tmp2."".$value2["name"].">";
- }
- $indice++;
- }
-
-
-
-
-
- if ($evalret!==false) {
- $resultado='encoding.'"?>';
- $resultado.='
';
- $resultado.='<' . $function_name . 'Response xmlns="' . $this->NAMESPACE . '">';
- $resultado.='<' . $function_name . 'Result>' . $serial.'' . $function_name . 'Result>';
- $resultado.=$extrabyref;
- $resultado.='' . $function_name . 'Response>';
- $resultado.='';
- $resultado.='';
- } else {
- $resultado='
';
- $resultado.='soap:Sender'.$function_name.' failed to evaluate .'.@$r["soap:Fault"].'';
- $resultado.='';
- }
-
-
- return $resultado;
- }
- private function decodeNOSOAP($methodcalled,$tmpvalue) {
- // pass json/xml/php/raw --> return a array or value.
- $tmp="";
- switch ($methodcalled) {
- case "json":
- $tmp=json_decode($tmpvalue);
- break;
- case "xml":
- $this->xml2array($tmpvalue,1);
- break;
- case "php":
- $tmp=@unserialize($tmpvalue);
- break;
- case "none":
- /*if (is_array($tmpvalue)) {
- $tmpvalue=ex(",",$tmpvalue);
- }
- */
- $tmp=$tmpvalue; // urlencode is done
- break;
- }
- return $tmp;
- }
- private function encodeNOSOAP($methodcalled,$tmpvalue,$tmpname) {
- $tmp="";
- switch ($methodcalled) {
- case "json":
- $tmp=json_encode($tmpvalue);
- break;
- case "xml":
- if (!is_array($tmpvalue)) {
- @header("content-type:text/xml;charset=".$this->encoding);
- $tmp='<' . '?' . 'xml version="1.0" encoding="'.$this->encoding.'"' . '?' . '>' . "\n";
- $tmp.="<$tmpname>$tmpvalue$tmpname>";
- } else {
- $tmp=$this->array2xml($tmpvalue, "array", true, true);
- }
- $tmp=$this->fixarray2xml($tmp);
-
- break;
- case "php":
- $tmp=serialize($tmpvalue);
- break;
- case "none":
- if (is_array($tmpvalue)) {
- $tmp="";
- foreach($tmpvalue as $key=>$value) {
- $tmp.=$key."=".$value."&";
- }
- $tmpvalue=$tmp;
- $tmpvalue=substr($tmpvalue, 0, strlen($tmpvalue) - 1);
- }
- $tmp=$tmpvalue;
- break;
- }
- return $tmp;
- }
-
- private function requestNOSOAP($function_name,$function_out, $methodcalled,$isget,$info=array()) {
- global $param, $r;
-
-
- $evalret=false;
- $this->wsse_username=@$_POST["Username"];
- $this->wsse_password=@$_POST["Password"];
- $this->wsse_nonce=@$_POST["Nonce"];
- $this->wsse_created=@$_POST["Created"];
- $tmp=@$_POST["Type"];
-
- if (strpos($tmp,"#PasswordText")) {
- $this->wsse_password_type="PasswordText";
- } else {
- if (strpos($tmp,"#PasswordDigest")) {
- $this->wsse_password_type="PasswordDigest";
- } else {
- $this->wsse_password_type="None";
- }
- }
- // pasar los parametros
- $param=array();
-
- $paramt="";
-
- $indice_operation=-1;
- foreach ($this->operation as $key => $value) {
- if ($value["name"]==$function_name) {
- $indice_operation=$key;
- }
- }
- $operation=array("in"=>array());
- if ($indice_operation>=0) {
- $i=0;
- $operation=$this->operation[$indice_operation];
- foreach($operation["in"] as $key=>$value) {
- $tmpvalue=($isget)?@$_GET[$value["name"]]:@$_POST[$value["name"]];
- if ($methodcalled=="rest") {
- $param[]=@$info[$i+3];
- } else {
- $param[]=$this->decodeNOSOAP($methodcalled,$tmpvalue);
- }
- $paramt.='@$param[' . $i . '],';
- $i++;
- }
- if ($this->variable_type=="object") {
- // convert all parameters in classes.
- foreach($param as $key=>$value) {
- $classname=$operation["in"][$key]["type"];
- if (strpos($classname,"tns:",0)!==false) {
- $param[$key]=$this->array2class($value,$this->fixtag($classname));
- } else {
- // not touched.
- }
- }
- }
- $param_count=count($param);
- $paramt=substr($paramt, 0, strlen($paramt) - 1);
- $r="";
- if ($this->object_function=="") {
- $evalstr="\$r=$function_name($paramt);";
- } else {
- @eval("global \$".$this->object_function.";");
- $evalstr="\$r=\$".$this->object_function."->$function_name($paramt);";
-
- }
-
- $evalret=eval($evalstr);
-
- if ($this->variable_type=="object") {
-
-
- $r=$this->class2array($r,$this->fixtag($operation["out"][0]["type"]));
-
- }
- } else {
- $evalret=array("soap:Fault"=>'Caught exception: function not defined');
- }
-
- $max_result=array();
-
-
- $max_result[$function_name . 'Result']=$r;
-
- // agregamos si tiene valor byref.
- $extrabyref="";
- $indice=0;
-
- foreach ($operation["in"] as $key2 => $value2) {
- if (@$value2["byref"]) {
- $paramtmp=@$param[$indice];
- $max_result[$value2["name"]]=$paramtmp;
- $extrabyref.=$value2["name"]."=".$paramtmp."\n";
-
- }
- $indice++;
- }
-
- if (count($max_result)==1) {
-
- $max_result=$r; // if not byref then we returned as a single value
- }
-
- if ($evalret!==false) {
-
- $resultado=$max_result;
- } else {
- $resultado=$r;
- }
-
-
- $resultado=$this->encodeNOSOAP($function_out,$resultado,$function_name . 'Result');
- return $resultado;
- }
-
-
- private function xml2array($contents, $get_attributes=0, $priority='tag') {
- if (!$contents)
- return array();
- if (!function_exists('xml_parser_create')) {
- //print "'xml_parser_create()' function not found!";
- return array(); }
- //Get the XML parser of PHP - PHP must have this module for the parser to work
- $parser=xml_parser_create('');
- xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING,
- $this->encoding); # http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
- xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
- xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
- xml_parse_into_struct($parser, trim($contents), $xml_values);
- xml_parser_free($parser);
- if (!$xml_values)
- return; //Hmm...
- //Initializations
- $xml_array=array();
- $parents=array();
- $opened_tags=array();
- $arr=array();
- $current=&$xml_array; //Refference
- //Go through the tags.
- $repeated_tag_index=array(); //Multiple tags with same name will be turned into an array
- foreach ($xml_values as $data) {
- unset($attributes, $value); //Remove existing values, or there will be trouble
- //This command will extract these variables into the foreach scope
- // tag(string), type(string), level(int), attributes(array).
- extract($data); //We could use the array by itself, but this cooler.
- $result=array();
- $attributes_data=array();
- if (isset($value)) {
- if ($priority == 'tag')
- $result=$value;
- else
- $result['value']=$value; //Put the value in a assoc array if we are in the 'Attribute' mode
- }
- //Set the attributes too.
- if (isset($attributes) and $get_attributes) {
- foreach ($attributes as $attr => $val) {
- if ($priority == 'tag')
- $attributes_data[$attr]=$val;
- else
- $result['attr'][$attr]=$val; //Set all the attributes in a array called 'attr'
- }
- }
- //See tag status and do the needed.
- $tag=$this->fixtag($tag);
- if ($type == "open") { //The starting of the tag '
'
- $parent[$level - 1]=&$current;
- if (!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
- $current[$tag]=$result;
- if ($attributes_data)
- $current[$tag . '_attr']=$attributes_data;
- $repeated_tag_index[$tag . '_' . $level]=1;
- $current=&$current[$tag];
- } else { //There was another element with the same tag name
- if (isset($current[$tag][0])) { //If there is a 0th element it is already an array
- $current[$tag][$repeated_tag_index[$tag . '_' . $level]]=$result;
- $repeated_tag_index[$tag . '_' . $level]++;
- } else
- { //This section will make the value an array if multiple tags with the same name appear together
- $current[$tag]=array
- (
- $current[$tag],
- $result
- ); //This will combine the existing item and the new item together to make an array
- $repeated_tag_index[$tag . '_' . $level]=2;
- if (isset($current[$tag . '_attr']))
- { //The attribute of the last(0th) tag must be moved as well
- $current[$tag]['0_attr']=$current[$tag . '_attr'];
- unset($current[$tag . '_attr']);
- }
- }
- $last_item_index=$repeated_tag_index[$tag . '_' . $level] - 1;
- $current=&$current[$tag][$last_item_index];
- }
- } elseif ($type == "complete") { //Tags that ends in 1 line ''
- //See if the key is already taken.
- if (!isset($current[$tag])) { //New Key
- $current[$tag]=$result;
- $repeated_tag_index[$tag . '_' . $level]=1;
- if ($priority == 'tag' and $attributes_data)
- $current[$tag . '_attr']=$attributes_data;
- } else { //If taken, put all things inside a list(array)
- if (isset($current[$tag][0]) and is_array($current[$tag])) { //If it is already an array...
- // ...push the new element into that array.
- $current[$tag][$repeated_tag_index[$tag . '_' . $level]]=$result;
- if ($priority == 'tag' and $get_attributes and $attributes_data)
- { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr']=$attributes_data; }
- $repeated_tag_index[$tag . '_' . $level]++;
- } else { //If it is not an array...
- $tmp=$current[$tag];
- //echo "tag = $tag result = $result current=$tmp
";
- //var_dump($current);
- @$current[$tag]=array
- (
- $tmp,
- $result
- ); //...Make it an array using using the existing value and the new value
- $repeated_tag_index[$tag . '_' . $level]=1;
- if ($priority == 'tag' and $get_attributes) {
- if (isset($current[$tag . '_attr']))
- { //The attribute of the last(0th) tag must be moved as well
- $current[$tag]['0_attr']=$current[$tag . '_attr'];
- unset($current[$tag . '_attr']);
- }
- if ($attributes_data)
- { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr']=$attributes_data; }
- }
- $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
- }
- }
- }
- elseif ($type == 'close') { //End of tag ''
- $current=&$parent[$level - 1]; }
- }
- return ($xml_array);
- }
- protected function fixtag($tag) {
- $arr=explode(":", $tag);
- return ($arr[count($arr) - 1]);
- }
- private function fixarray2xml($string) {
- //if (!is_array($string)) { return $string; }
- // we remove the first and last element of the xml file so.
-
- $arr=explode("\n", $string);
-
- $resultado="";
- for ($i=1; $i < count($arr)-1; $i++) {
- $l=trim($arr[$i]);
- $lant=trim($arr[$i - 1]);
- if ($l != $lant) { $resultado.=$arr[$i] . "\n"; }
- }
-
- return $resultado;
- }
- function array2xml($array, $name="root", $contenttype=TRUE, $start=TRUE, $keyx="") {
- // \n is important, you should not remove it.
- if (!is_array($array)) { return $array; }
- $xmlstr="";
- if ($start) {
- if ($contenttype) {
- @header("content-type:text/xml;charset=".$this->encoding);
- }
- $xmlstr.='encoding."\"?>\n" ;
- $xmlstr.='<'.$name.">\n" ;
- }
-
- foreach ($array as $key => $child) {
- if (is_array($child)) {
- $xmlstr.=(is_string($key))?"<".$key.">\n":"<".$keyx.">\n";
- $xmlstr.=$this->array2xml($child, "", "", FALSE, $key);
- $xmlstr.=(is_string($key))?"".$key.">\n":"".$keyx.">\n";
- } else {
- $type=$this->array2xmltype($child);
- if ($this->variable_type=="object" and is_object($child)) {
- $xmlstr.="<$type>".$this->array2xml($this->class2array($child,$type),$type,false,false,$key)."$type>\n";
- } else {
- $xmlstr.= '<'.(is_string($key)?$key:$type).'>'.$child.''.(is_string($key)?$key:$type).">\n";
- }
- }
- }
- if ($start) {
- $xmlstr.=''.$name.">\n";
- }
- return $xmlstr;
- }
- function array2xmltype($value) {
- if (is_float($value)) {
- return "float";
- }
- if (is_int($value)) {
- return "int";
- }
- if (is_object($value)) {
- return get_class($value);
- }
- return "string";
- }
-}
-
-/* CLASS CKLIB WSDL ********************************************************************************************************* */
-
-class CKLIB_DESC extends CKLIB {
- private function gen_description_util($min, $max) {
- $tmp="";
- $tmp1="";
- if ($min != "0" && $min != "") { $tmp1="required"; }
- if (@$max > 1) { $tmp="Array(" . $min . " to " . $max . ")"; }
- if (@$max == "unbounded") { $tmp="Array(" . $min . " to unlimited)"; }
- return ($tmp . " " . $tmp1);
- }
-
- protected function gen_description() {
- $t1=microtime(true);
- echo $this->html_header();
-
- if ($this->verbose>=2) {
- echo "Name Web Service :" . $this->NAME_WS . "
";
- echo "Namespace :
" . $this->NAMESPACE . "";
- echo "WSDL :
WSDL description";
- echo "Protocols Supported :".(($this->soap11)?"SOAP 1.1, ":"").(($this->soap12)?"SOAP 1.2 (2.0), ":"").(($this->get)?"HTTP GET, ":"").(($this->post)?"HTTP POST, ":"")."None
";
- if (method_exists($this,'source')) {
- echo "Source :
Source Generation";
- }
- }
- if ($this->verbose>=1) {
- echo "
List of Operations
";
- $jsall="";
- echo $jsall;
- echo "
List of Complex Types
";
- $jsall="";
- echo $jsall;
- }
- // copyright
- echo $this->html_footer($t1);
- }
-
-}
-
-/* CLASS CKLIB WSDL ********************************************************************************************************* */
-
-class CKLIB_WSDL extends CKLIB_DESC {
- public function genwsdl() {
- if ($this->custom_wsdl!=$this->FILE."?wsdl") {
- // se usa un archivo customizado.
- $handle = @fopen($this->custom_wsdl, "r");
- if ($handle) {
- $contents = fread($handle, filesize($this->custom_wsdl));
- } else {
- $contents= "file or url :".$this->custom_wsdl." can't be open
\n";
- }
- fclose($handle);
- return $contents;
- }
- $cr="\n";
- $tab1="\t";
- $wsdl='encoding.'" ?>' . $cr;
- $wsdl.='soap12) {
- $wsdl.=' xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" ';
- }
- $wsdl.=' xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">'
- . $cr;
- if ($this->description) {
- $wsdl.=''.$this->description.'';
- }
- // types ***
- $wsdl.=$tab1 . '' . $cr . '' . $cr;
- // elementos in
- foreach ($this->operation as $key => $value) {
- $wsdl.='
-
-
- ';
- foreach ($value["in"] as $key2 => $value2) {
- $minOccurs=$value2["minOccurs"];
- $maxOccurs=$value2["maxOccurs"];
- $wsdl.='';
- if (@$value2["description"]) {
- //$wsdl.=''.$value2["description"].'';
- }
- $wsdl.='';
- }
- $wsdl.='
-
- ';
- // out
- $wsdl.='
-
-
- ';
- foreach ($value["out"] as $key2 => $value2) {
- $minOccurs=$value2["minOccurs"];
- $maxOccurs=$value2["maxOccurs"];
- $wsdl.='';
- if (@$value2["description"]) {
- //$wsdl.=''.$value2["description"].'';
- }
- $wsdl.='';
- }
- foreach ($value["in"] as $key2 => $value2) {
- if (@$value2["byref"]) {
- $minOccurs=$value2["minOccurs"];
- $maxOccurs=$value2["maxOccurs"];
- $wsdl.='';
- }
- }
-
- $wsdl.='
-
-
- ';
- }
- // complex types
- foreach ($this->complextype as $key => $value) {
- $wsdl.='
-
- ';
- foreach ($value["elements"] as $key2 => $value2) {
- $minOccurs=$value2["minOccurs"];
- $maxOccurs=$value2["maxOccurs"];
- $type=str_replace($this->NAMESPACE, "tns", $value2["type"]);
- $wsdl.=' ';
- if (@$value2["description"]) {
- //$wsdl.=''.$value2["description"].'';
- }
- $wsdl.='';
- }
- $wsdl.='
-
- ';
- }
- // end types
- $wsdl.='
-
- ';
- // messages
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='
-
-
- ';
- $wsdl.='
-
-
- ';
- if ($this->get) {
- $wsdl.='
-
-
- ';
- $wsdl.='
-
-
- ';
- }
-
- if ($this->post) {
- $wsdl.='
-
-
- ';
- $wsdl.='
-
-
- ';
- }
- }
- // porttype
- $wsdl.='';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='';
- if (@$value["description"]) {
- $wsdl.=''.@$value["description"].'';
- }
- $wsdl.='';
- }
- $wsdl.='';
- if ($this->get) {
- $wsdl.='';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='';
- if (@$value["description"]) {
- $wsdl.=''.@$value["description"].'';
- }
- $wsdl.='';
- }
- $wsdl.='';
- }
- if ($this->post) {
- $wsdl.='';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='';
- if (@$value["description"]) {
- $wsdl.=''.@$value["description"].'';
- }
- $wsdl.='';
- }
- $wsdl.='';
- }
-
- // binding
- if ($this->soap11) {
- $wsdl.='
-
- ';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='
-
-
-
-
- ';
- }
- $wsdl.='';
- }
- // binding12
- if ($this->soap12) {
- $wsdl.='
- ';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='
-
-
-
-
- ';
- }
- $wsdl.='';
- }
- // binding12 (get)
- if ($this->soap12 and $this->get) {
- $wsdl.='
- ';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='';
- $wsdl.='';
- $wsdl.='';
- $wsdl.='';
- }
- $wsdl.='';
- }
-
-
-
- // binding12 (post)
- if ($this->soap12 and $this->post) {
- $wsdl.='
- ';
- foreach ($this->operation as $key => $value) {
- $name=$value["name"];
- $wsdl.='';
- $wsdl.='';
- $wsdl.='';
- $wsdl.='';
- }
- $wsdl.='';
- }
- // service
-
- $wsdl.='';
-
- if ($this->soap11) {
- $wsdl.='
- ';
- }
- if ($this->soap12) {
- $wsdl.='
- ';
- if ($this->get) {
- $wsdl.='
- ';
- }
- if ($this->post) {
- $wsdl.='
- ';
- }
-
- }
- $wsdl.='';
- return $wsdl;
- }
-}
-
-
-/* CLASS CKLIB WSDL ********************************************************************************************************* */
-
-class CKLIB_SRC extends CKLIB_WSDL {
-
- protected function Param2PHPvalue($type,$max) {
- $x1=explode(":", $type);
- if (count($x1) != 2) { return "// type $type not defined "; }
- $space=$x1[0];
- $name=$x1[1];
- $p="";
- if ($space == "s") {
- if (!in_array($name, $this->predef_types)) {
- return "// type $type not found";
- }
- if (!in_array($name, $this->predef_types_num)) {
-
- $p="'value'";
- } else {
- $p="0";
- }
- }
- if ($space == "tns") {
- foreach ($this->complextype as $key => $value) {
- if ($name == $value["name"]) {
- $p= '$_'.$name;
- }
- }
- if ($p==="") {
- return "// complex type $type not found";
- }
- }
- if ($p!=="") {
- switch($max) {
- case "unbounded":
- return "array($p,$p,...)";
- break;
- case "1":
- return $p;
- break;
- default:
- $tmp="array(";
- for ($i=0;$i<$max;$i++) {
- $tmp.=$p.",";
- }
- $tmp=$this->right($tmp,1).")";
- return($tmp);
- break;
- }
- }
- return "\\ complex type $type not defined";
- }
- protected function Param2PHP($type,$max) {
- $x1=explode(":", $type);
- if (count($x1) != 2) { return "// type $type not defined "; }
- $space=$x1[0];
- $name=$x1[1];
- if ($space == "s") {
- if (!in_array($name, $this->predef_types)) {
- return "// type $type not found";
- }
- $p=$this->Param2PHPvalue($type,$max);
- if ($max=="unbounded") {
- return "array($p,$p,...)";
- }
- if ($max==1) {
- return $p;
- }
- $tmp="array(";
- for ($i=0;$i<$max;$i++) {
- $tmp.=$p.",";
- }
- $tmp=$this->right($tmp,1).")";
- return($tmp);
- }
- $resultado="";
- if ($space == "tns") {
- $ok=false;
- foreach ($this->complextype as $key => $value) {
- if ($name == $value["name"]) {
-
- foreach ($value["elements"] as $key2 => $value2) {
- $resultado.="\$_".$name."['".$value2["name"]."']=".$this->Param2PHPValue($value2["type"],$value2["maxOccurs"]).";\n";
- //$resultado.="'".$value2["name"]."'=>".$this->Param2PHP($value2["type"],$value2["maxOccurs"]).",";
- }
- $resultado=$this->right($resultado);
- return($resultado);
- }
- }
- return "\\ complex type $type not defined";
- }
- }
-
- protected function genphpast($text,$lenght=100) {
- $L=($lenght-6-strlen($text))/2;
- $L=($L<1)?1:$L;
- $ast=str_repeat("*",$L);
- $texto="/*".$ast." ".$text." ".$ast."*/\n";
- return $texto;
- }
- protected function genphp() {
- $r=$this->genphpast("Implementation");
- foreach ($this->operation as $key => $value) {
- $param="";
- foreach ($value["in"] as $key2 => $value2) {
- $param.=($value2["byref"])?"&":"";
- $param.="$".$value2["name"].", ";
-
- }
- if ($param!="") {
- $param=$this->right($param,2);
- }
- $r.="\n".$this->genphpast("Function ".$value["name"]." = ".$value["description"]);
- $r.="function ".$value["name"]."($param) {\n";
- $r.="\ttry {\n";
-
- $r.="\t\t// Input Values.... \n";
- $r.="\t\t/*\n";
- $param="";
- foreach ($value["in"] as $key2 => $value2) {
- $param.="\t\t\$_".$value2["name"]."=".$this->Param2PHPValue($value2["type"],$value2["maxOccurs"]).";\n";
- }
-
- $r.=$param;
- $r.="\t\t*/\n";
- $r.="\t\t// End Input Values \n";
- foreach ($value["out"] as $key2 => $value2) {
- $r.="\t\t\$_".$value["name"]."Result=".$this->Param2PHPValue($value2["type"],$value2["maxOccurs"]).";\n";
- }
- foreach ($value["out"] as $key2 => $value2) {
-
- $param.=$this->Param2PHPvalue($value2["type"],$value2["maxOccurs"]);
-
- }
- //$r.="\t\t \$result=\$_".$value["name"]."Result ".$param."; \n";
- $r.="\t\t return \$_".$value["name"]."Result; \n";
- $r.="\t} catch (Exception \$_exception) {\n";
- $r.="\t\treturn(array(\"soap:Fault\"=>'Caught exception: '. \$_exception->getMessage()));\n";
- $r.="\t}\n";
- $r.="}\n";
- }
- $r.="\n".$this->genphpast("Complex Types");
- foreach ($this->complextype as $key => $value) {
- $param="";
- $r.="\n".$this->genphpast("tns:".$value["name"]);
- $r.=$this->Param2PHP("tns:".$value["name"],@$value["maxOccurs"])."\n";
- }
- $r.="\n".$this->genphpast("Complex Types (Classes)");
- foreach ($this->complextype as $key => $value) {
- $param="";
- $r.="\nclass ".$value["name"]." {\n";
- foreach ($value["elements"] as $key2 => $value2) {
- $r.="\tvar ".$value2["name"]."; // ".$value2["type"]."\n";
- }
- $r.="}\n";
- }
- return $r;
- }
-
-
-
- protected function genphpclient($soapversion="1.2") {
-
- $r= "\n";
- $r.= "include_once 'ckclient.php';\n";
- $r.=$this->genphpast("Implementation");
- $r.= "class ".$this->NAME_WS."Client {\n";
- $r.= "\tvar \$url='".$this->FILE."';\n";
- $r.= "\tvar \$tempuri='".$this->NAMESPACE."';\n";
- foreach ($this->operation as $key => $value) {
- $functionname=$value["name"];
- $param="";
- foreach ($value["in"] as $key2 => $value2) {
- $param.=($value2["byref"])?"&":"";
- $param.="$".$value2["name"].", ";
-
- }
- if ($param!="") {
- $param=$this->right($param,2);
- }
- $r.="\n\t// ".@$value["description"]." \n";
- foreach ($value["in"] as $key2 => $value2) {
- $varname=$value2["name"];
- $r.="\t// $varname = ".@$value2["description"]." \n";
- }
- $r.="\tfunction $functionname($param) {\n";
- $r.="\t\t\$_obj=new CKClient();\n";
- $r.="\t\t\$_obj->tempuri=\$this->tempuri;\n";
- $r.="\t\t\$_param='';\n";
- foreach ($value["in"] as $key2 => $value2) {
- $varname=$value2["name"];
- $r.="\t\t\$_param.=\$_obj->array2xml(\$$varname,'ts:$varname',false,false);\n";
- }
- $r.="\t\t\$resultado=\$_obj->loadurl(\$this->url,\$_param,'$functionname');\n";
- foreach ($value["in"] as $key2 => $value2) {
- if ($value2["byref"]) {
- $r.="\t\t\$".$value2["name"]."=@\$resultado['".$value2["name"]."'];\n";
- }
- }
- $r.="\t\treturn @\$resultado['".$functionname."Result'];\n";
- $r.="\t}\n";
-
- }
- $r.="} // end ".$this->NAME_WS."\n";
- $r.="?>\n";
- return $r;
- }
-
- protected function genunitycsharp() {
- $r=$this->genphpast("Implementation");
-
- $r.='using UnityEngine;
-
-using System.IO;
-using System.Xml.Serialization;
-using System;
-using System.Text;
-using System.Collections;
-using System.Collections.Generic;
-
-public class '.$this->NAME_WS.' : MonoBehaviour
-{
- // Use this for initialization
- private string charset = "UTF-8";
- private string url = "'.$this->FILE.'";
- private string tempuri = "'.$this->NAMESPACE.'";
- private string prefixns = "ts";
- public string cookie="";
- ';
-
- foreach ($this->operation as $key => $value) {
- $tmpname=$value["name"];
- if (count($value["out"])>=1) {
- $outtype=$this->fixtag($value["out"][0]["type"]);
- $outtypereal=$this->type2csharp($outtype);
- } else {
- $outtype="";
- $outtypereal="";
- }
-$r.='
- // '.$tmpname.'
- public Boolean is'.$tmpname.'Running = false;
- private WWW webservice'.$tmpname.';
- public string '.$tmpname.'Error="";
-
- public '.$outtypereal.' '.$tmpname.'Result;
- // End '.$tmpname.'
-';
- }
- $r.=' private void Start()
- {
- return;
- }';
- foreach ($this->operation as $key => $value) {
- $tmpname=$value["name"];
- $param="";
- foreach ($value["in"] as $key2 => $value2) {
- $param.=$this->fixtag($value2["type"])." ".$value2["name"].",";
- }
- $param=$this->right($param,1);
- $r.='
- private void '.$tmpname.'Async('.$param.')
- {
- string namefunction = "'.$tmpname.'";
- Single soapVersion=1.1f;
- string ss2 = SoapHeader(namefunction,soapVersion);';
-
- foreach ($value["in"] as $key2 => $value2) {
- $name=$value2["name"];
- $r.='
- ss2 += "<" + prefixns + ":'.$name.'>" + Obj2XML('.$name.',true) + "" + prefixns + ":'.$name.'>";
- ';
- }
-
- if (count($value["out"])>=1) {
- $outtype=$this->fixtag($value["out"][0]["type"]);
- $outtypereal=$this->type2csharp($outtype);
- $outinit=$this->csharp_init($outtype);
- } else {
- $outtype="";
- $outtypereal="";
- }
-
-
- $r.='ss2 += SoapFooter(namefunction,soapVersion);
- is'.$tmpname.'Running = true;
- StartCoroutine('.$tmpname.'Async2(ss2));
- }
- private IEnumerator '.$tmpname.'Async2(string ss2) {
- string namefunction = "'.$tmpname.'";
- Single soapVersion=1.1f;
- byte[] bb = System.Text.Encoding.UTF8.GetBytes(ss2);
- var headers = header(namefunction,soapVersion);
- if (cookie!="") {
- headers.Add("Set-Cookie",cookie);
- }
- webservice'.$tmpname.' = new WWW(url, bb, headers);
- while( !webservice'.$tmpname.'.isDone ) {
- yield return new WaitForSeconds(0.5f);
- }
- is'.$tmpname.'Running = false;
- string other = cleanSOAPAnswer(webservice'.$tmpname.'.text, "'.$tmpname.'",ref '.$tmpname.'Error);
- ';
- if ($outtype!="") {
- $r.=$tmpname."Result=".$outinit.";\n";
- $r.=' '.$tmpname.'Result=('.$outtypereal.')XML2Obj(other,"'.$outtype.'",'.$tmpname.'Result.GetType());
- ';
- }
- $r.='webservice'.$tmpname.'.responseHeaders.TryGetValue("SET-COOKIE",out cookie);
- ';
- $r.=$tmpname.'AsyncDone();
- }
- public void '.$tmpname.'AsyncDone() {
- // we do something...';
- if ($outtype!="") {
- $r.='
- // '.$outtypereal.' dnx='.$tmpname.'Result;';
- }
- $r.='
- }
- ';
- }
-
- $r.='
- #region util_function
- private Hashtable header(string nameFunction,Single soapVersion) {
- var tmpheader=new Hashtable();
- if (soapVersion>=1.2) {
- tmpheader["Content-Type"] = "application/soap+xml;charset" + charset + ";action=\"" + url + "/" + nameFunction +"\"";
- } else {
- tmpheader["Content-Type"] = "text/xml;charset" + charset;
- tmpheader["SOAPAction"]= "\""+ tempuri + "/" + nameFunction +"\"";
- }
- return tmpheader;
- }
-
-
- private string cleanSOAPAnswer(string text, string functionname,ref string last_error )
- {
- int p0, p1, pbody;
- string tmp = functionname + "Result";
- pbody = text.IndexOf("");
- if (pbody<0) {
- last_error="No soap found";
- return "";
- }
- p0 = text.IndexOf("<" + tmp, pbody);
- if (p0 <= 0)
- {
- return "";
- }
- p0 = text.IndexOf(">", p0) + 1;
- p1 = text.IndexOf("" + tmp, p0);
- if (p1 < p0)
- {
- tmp = "";
- }
- else
- {
- tmp = text.Substring(p0, p1 - p0);
- }
- return tmp;
- }
-
- private string SoapHeader(string nameFunction,Single soapVersion)
- {
- string ss2;
- if (soapVersion>=1.2) {
- ss2 = "";
- ss2 += "";
- } else {
- ss2 = "";
- ss2 += "";
- }
- ss2 += "<" + prefixns + ":" + nameFunction + ">";
-
- return ss2;
- }
-
- private string SoapFooter(string nameFunction,Single soapVersion)
- {
- string ss2;
- ss2 = "" + prefixns + ":" + nameFunction + ">";
- if (soapVersion>=1.2f) {
- ss2 += "";
- } else {
- ss2 += "";
- }
-
- return ss2;
- }
-
- private string Obj2XML(object obj)
- {
- return Obj2XML(obj, false, false);
- }
-
- private string Obj2XML(object obj, Boolean withns)
- {
- return Obj2XML(obj, withns, false);
- }
-
- private string Obj2XML(object obj, Boolean withns, Boolean full)
- {
- string myStr, types;
-
- if (obj.GetType().Namespace == "System")
- {
- types = obj.GetType().Name.ToLower();
- types = (withns) ? prefixns + ":" + types : types;
- if (full)
- {
- myStr = "<" + types + ">" + obj.ToString() + "" + types + ">";
- }
- else
- {
- myStr = obj.ToString();
- }
- }
- else
- {
- var mstream = new MemoryStream();
- XmlSerializer SerializerObj = new XmlSerializer(obj.GetType(), tempuri);
- if (withns)
- {
- var namespaces = new XmlSerializerNamespaces();
- namespaces.Add(prefixns, tempuri);
- SerializerObj.Serialize(mstream, obj, namespaces);
- }
- else
- {
- SerializerObj.Serialize(mstream, obj);
- }
-
- mstream.Position = 0;
- var sreader = new StreamReader(mstream);
- myStr = sreader.ReadToEnd();
- // cut xml and first node element from the xml
- if (!full)
- {
- var arr = myStr.Split(new char[] {'."'".'\n'."'".'}, StringSplitOptions.None);
- //var arr2 = "";
- int lim = arr.Length - 3;
- var arr2 = String.Join("", arr, 2, lim);
- myStr = arr2;
- }
- }
-
- return myStr;
- }
- private object XML2Obj(string xmlstr, string typedesc, Type type) {
- return XML2Obj( xmlstr, typedesc,type,false);
- }
- private object XML2Obj(string xmlstr, string typedesc, Type type,Boolean full)
- {
- if (!full)
- {
- xmlstr = "" + "<" + typedesc + ">" + xmlstr + "" + typedesc + ">";
- }
- var objdummy = new object();
- var SerializerObj = new XmlSerializer(type);
-
- byte[] byteArray = Encoding.ASCII.GetBytes(xmlstr);
- objdummy = SerializerObj.Deserialize(new MemoryStream(byteArray));
-
- return objdummy;
- }
- #endregion
-} // end class.
- ';
-
- $r.="\n".$this->genphpast("Complex Types (Classes)");
- foreach ($this->complextype as $key => $value) {
- $param="";
- $type=$this->fixtag($value2["type"]);
-
-
- if (strlen($value["name"])>7 and substr($value["name"],0,7)=="ArrayOf") {
-
- } else {
- $r.="\npublic class ".$value["name"]." {\n";
- foreach ($value["elements"] as $key2 => $value2) {
- $r.="\tprivate ".$type." _".$value2["name"]."; \n";
- }
- $r.="\n";
- foreach ($value["elements"] as $key2 => $value2) {
- $r.="\tpublic ".$type." ".$value2["name"]."\n";
- $r.="\t{\n";
- $r.="\t\tget { return _".$value2["name"]."; }\n";
- $r.="\t\tset { _".$value2["name"]." = value; }\n";
- $r.="\t}\n";
- }
-
- $r.="}\n";
- }
- }
-
-
-
-
-
-
-
-
-
-
-
- return($r);
- }
- protected function csharp_init($type) {
- // ArrayOfS
- // 12345678
- switch($type) {
- case "string":
- case "String":
- return '""';
- break;
- case "int":
- case "long":
- case "Single":
- return '0';
- break;
- default:
- return "new ".($this->type2csharp($type))."()";
- }
- }
- protected function type2csharp($type) {
- // ArrayOfS
- // 12345678
- $l=strlen($type);
-
- if ($l>8 and substr($type,0,7)=="ArrayOf") {
- $type="List<".substr($type,7,$l-7).">";
- return $this->type2csharp($type);
- } else {
- return $type;
- }
- }
- protected function source() {
- echo $this->html_header();
- echo "
List of Operations
";
- echo $this->html_footer();
-
- return "";
- }
-}
-
-
-
-
-?>
\ No newline at end of file