bug #2042032 Cannot detect PmaAbsoluteUri correctly on Windows
[phpmyadmin/madhuracj.git] / libraries / sqlvalidator.class.php
blobc2baaad10611f4a2f8753e0e4b9107823ecba346
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * PHP interface to MimerSQL Validator
6 * Copyright 2002, 2003 Robin Johnson <robbat2@users.sourceforge.net>
7 * http://www.orbis-terrarum.net/?l=people.robbat2
9 * All data is transported over HTTP-SOAP
10 * And uses the PEAR SOAP Module
12 * Install instructions for PEAR SOAP
13 * Make sure you have a really recent PHP with PEAR support
14 * run this: "pear install Mail_Mime Net_DIME SOAP"
16 * If you got this file from somewhere other than phpMyAdmin
17 * please be aware that the latest copy will always be in the
18 * phpMyAdmin subversion tree as
19 * $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyAdmin/libraries/sqlvalidator.class.php $
21 * This code that also used to depend on the PHP overload module, but that has been
22 * removed now.
24 * @access public
26 * @author Robin Johnson <robbat2@users.sourceforge.net>
28 * @version $Id$
29 * @package phpMyAdmin
31 if (! defined('PHPMYADMIN')) {
32 exit;
35 /**
36 * Load SOAP client.
38 @include_once 'SOAP/Client.php';
40 if (!function_exists('class_exists') || !class_exists('SOAP_Client')) {
41 $GLOBALS['sqlvalidator_error'] = TRUE;
42 } else {
43 // Ok, we have SOAP Support, so let's use it!
45 /**
46 * @package phpMyAdmin
48 class PMA_SQLValidator {
50 var $url;
51 var $service_name;
52 var $wsdl;
53 var $output_type;
55 var $username;
56 var $password;
57 var $calling_program;
58 var $calling_program_version;
59 var $target_dbms;
60 var $target_dbms_version;
61 var $connectionTechnology;
62 var $connection_technology_version;
63 var $interactive;
65 var $service_link = null;
66 var $session_data = null;
69 /**
70 * Private functions - You don't need to mess with these
73 /**
74 * Service opening
76 * @param string URL of Mimer SQL Validator WSDL file
78 * @return object Object to use
80 * @access private
82 function _openService($url)
84 $obj = new SOAP_Client($url, TRUE);
85 return $obj;
86 } // end of the "openService()" function
89 /**
90 * Service initializer to connect to server
92 * @param object Service object
93 * @param string Username
94 * @param string Password
95 * @param string Name of calling program
96 * @param string Version of calling program
97 * @param string Target DBMS
98 * @param string Version of target DBMS
99 * @param string Connection Technology
100 * @param string version of Connection Technology
101 * @param integer boolean of 1/0 to specify if we are an interactive system
103 * @return object stdClass return object with data
105 * @access private
107 function _openSession($obj, $username, $password,
108 $calling_program, $calling_program_version,
109 $target_dbms, $target_dbms_version,
110 $connection_technology, $connection_technology_version,
111 $interactive)
113 $use_array = array("a_userName" => $username, "a_password" => $password, "a_callingProgram" => $calling_program, "a_callingProgramVersion" => $calling_program_version, "a_targetDbms" => $target_dbms, "a_targetDbmsVersion" => $target_dbms_version, "a_connectionTechnology" => $connection_technology, "a_connectionTechnologyVersion" => $connection_technology_version, "a_interactive" => $interactive);
114 $ret = $obj->call("openSession", $use_array);
116 // This is the old version that needed the overload extension
117 /* $ret = $obj->openSession($username, $password,
118 $calling_program, $calling_program_version,
119 $target_dbms, $target_dbms_version,
120 $connection_technology, $connection_technology_version,
121 $interactive); */
123 return $ret;
124 } // end of the "_openSession()" function
128 * Validator sytem call
130 * @param object Service object
131 * @param object Session object
132 * @param string SQL Query to validate
133 * @param string Data return type
135 * @return object stClass return with data
137 * @access private
139 function _validateSQL($obj, $session, $sql, $method)
141 $use_array = array("a_sessionId" => $session->sessionId, "a_sessionKey" => $session->sessionKey, "a_SQL" => $sql, "a_resultType" => $this->output_type);
142 $res = $obj->call("validateSQL", $use_array);
144 // This is the old version that needed the overload extension
145 // $res = $obj->validateSQL($session->sessionId, $session->sessionKey, $sql, $this->output_type);
146 return $res;
147 } // end of the "validateSQL()" function
151 * Validator sytem call
153 * @param string SQL Query to validate
155 * @return object stdClass return with data
157 * @access private
159 * @see validateSQL()
161 function _validate($sql)
163 $ret = $this->_validateSQL($this->service_link, $this->session_data,
164 $sql, $this->output_type);
165 return $ret;
166 } // end of the "validate()" function
170 * Public functions
174 * Constructor
176 * @access public
178 function __construct()
180 $this->url = 'http://sqlvalidator.mimer.com/v1/services';
181 $this->service_name = 'SQL99Validator';
182 $this->wsdl = '?wsdl';
184 $this->output_type = 'html';
186 $this->username = 'anonymous';
187 $this->password = '';
188 $this->calling_program = 'PHP_SQLValidator';
189 $this->calling_program_version = '$Revision$';
190 $this->target_dbms = 'N/A';
191 $this->target_dbms_version = 'N/A';
192 $this->connection_technology = 'PHP';
193 $this->connection_technology_version = phpversion();
194 $this->interactive = 1;
196 $this->service_link = null;
197 $this->session_data = null;
198 } // end of the "PMA_SQLValidator()" function
202 * Sets credentials
204 * @param string the username
205 * @param string the password
207 * @access public
209 function setCredentials($username, $password)
211 $this->username = $username;
212 $this->password = $password;
213 } // end of the "setCredentials()" function
217 * Sets the calling program
219 * @param string the calling program name
220 * @param string the calling program revision
222 * @access public
224 function setCallingProgram($calling_program, $calling_program_version)
226 $this->calling_program = $calling_program;
227 $this->calling_program_version = $calling_program_version;
228 } // end of the "setCallingProgram()" function
232 * Appends the calling program
234 * @param string the calling program name
235 * @param string the calling program revision
237 * @access public
239 function appendCallingProgram($calling_program, $calling_program_version)
241 $this->calling_program .= ' - ' . $calling_program;
242 $this->calling_program_version .= ' - ' . $calling_program_version;
243 } // end of the "appendCallingProgram()" function
247 * Sets the target DBMS
249 * @param string the target DBMS name
250 * @param string the target DBMS revision
252 * @access public
254 function setTargetDbms($target_dbms, $target_dbms_version)
256 $this->target_dbms = $target_dbms;
257 $this->target_dbms_version = $target_dbms_version;
258 } // end of the "setTargetDbms()" function
262 * Appends the target DBMS
264 * @param string the target DBMS name
265 * @param string the target DBMS revision
267 * @access public
269 function appendTargetDbms($target_dbms, $target_dbms_version)
271 $this->target_dbms .= ' - ' . $target_dbms;
272 $this->target_dbms_version .= ' - ' . $target_dbms_version;
273 } // end of the "appendTargetDbms()" function
277 * Sets the connection technology used
279 * @param string the connection technology name
280 * @param string the connection technology revision
282 * @access public
284 function setConnectionTechnology($connection_technology, $connection_technology_version)
286 $this->connection_technology = $connection_technology;
287 $this->connection_technology_version = $connection_technology_version;
288 } // end of the "setConnectionTechnology()" function
292 * Appends the connection technology used
294 * @param string the connection technology name
295 * @param string the connection technology revision
297 * @access public
299 function appendConnectionTechnology($connection_technology, $connection_technology_version)
301 $this->connection_technology .= ' - ' . $connection_technology;
302 $this->connection_technology_version .= ' - ' . $connection_technology_version;
303 } // end of the "appendConnectionTechnology()" function
307 * Sets whether interactive mode should be used or not
309 * @param integer whether interactive mode should be used or not
311 * @access public
313 function setInteractive($interactive)
315 $this->interactive = $interactive;
316 } // end of the "setInteractive()" function
320 * Sets the output type to use
322 * @param string the output type to use
324 * @access public
326 function setOutputType($output_type)
328 $this->output_type = $output_type;
329 } // end of the "setOutputType()" function
333 * Starts service
335 * @access public
337 function startService()
340 $this->service_link = $this->_openService($this->url . '/' . $this->service_name . $this->wsdl);
342 } // end of the "startService()" function
346 * Starts session
348 * @access public
350 function startSession()
352 $this->session_data = $this->_openSession($this->service_link, $this->username, $this->password,
353 $this->calling_program, $this->calling_program_version,
354 $this->target_dbms, $this->target_dbms_version,
355 $this->connection_technology, $this->connection_technology_version,
356 $this->interactive);
358 if (isset($this->session_data) && ($this->session_data != null)
359 && ($this->session_data->target != $this->url)) {
360 // Reopens the service on the new URL that was provided
361 $url = $this->session_data->target;
362 $this->startService();
364 } // end of the "startSession()" function
368 * Do start service and session
370 * @access public
372 function start()
374 $this->startService();
375 $this->startSession();
376 } // end of the "start()" function
380 * Call to determine just if a query is valid or not.
382 * @param string SQL statement to validate
384 * @return string Validator string from Mimer
386 * @see _validate
388 function isValid($sql)
390 $res = $this->_validate($sql);
391 return $res->standard;
392 } // end of the "isValid()" function
396 * Call for complete validator response
398 * @param string SQL statement to validate
400 * @return string Validator string from Mimer
402 * @see _validate
404 function validationString($sql)
406 $res = $this->_validate($sql);
407 return $res->data;
409 } // end of the "validationString()" function
410 } // end class PMA_SQLValidator
412 //add an extra check to ensure that the class was defined without errors
413 if (!class_exists('PMA_SQLValidator')) {
414 $GLOBALS['sqlvalidator_error'] = TRUE;
417 } // end else