add support for setting ssl version to use
[plcapi.git] / test / parse_args.php
1 <?php
2 /**
3  * Common parameter parsing for benchmarks and tests scripts
4  *
5  * @param integer DEBUG
6  * @param string  LOCALSERVER
7  * @param string  URI
8  * @param string  HTTPSSERVER
9  * @param string  HTTPSSURI
10  * @param string  PROXY
11  *
12  * @copyright (C) 2007-20013 G. Giunta
13  * @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
14  **/
15
16         require_once('xmlrpc.inc');
17         require_once('xmlrpcs.inc');
18
19         // play nice to older PHP versions that miss superglobals
20         if(!isset($_SERVER))
21         {
22                 $_SERVER = $HTTP_SERVER_VARS;
23                 $_GET = isset($HTTP_GET_VARS) ? $HTTP_GET_VARS : array();
24                 $_POST = isset($HTTP_POST_VARS) ? $HTTP_POST_VARS : array();
25         }
26
27         // check for command line vs web page input params
28         if(!isset($_SERVER['REQUEST_METHOD']))
29         {
30                 if(isset($argv))
31                 {
32                         foreach($argv as $param)
33                         {
34                                 $param = explode('=', $param);
35                                 if(count($param) > 1)
36                                 {
37                                         $pname = $param[0];
38                                         $$pname = $param[1];
39                                 }
40                         }
41                 }
42         }
43         elseif(!ini_get('register_globals'))
44         {
45                 // play nice to 'safe' PHP installations with register globals OFF
46                 // NB: we might as well consider using $_GET stuff later on...
47                 extract($_GET);
48                 extract($_POST);
49         }
50
51         if(!isset($DEBUG))
52         {
53                 $DEBUG = 0;
54         }
55         else
56         {
57                 $DEBUG = intval($DEBUG);
58         }
59
60         if(!isset($LOCALSERVER))
61         {
62                 if(isset($HTTP_HOST))
63                 {
64                         $LOCALSERVER = $HTTP_HOST;
65                 }
66                 elseif(isset($_SERVER['HTTP_HOST']))
67                 {
68                         $LOCALSERVER = $_SERVER['HTTP_HOST'];
69                 }
70                 else
71                 {
72                         $LOCALSERVER = 'localhost';
73                 }
74         }
75         if(!isset($HTTPSSERVER))
76         {
77                 $HTTPSSERVER = 'xmlrpc.usefulinc.com';
78         }
79         if(!isset($HTTPSURI))
80         {
81                 $HTTPSURI = '/server.php';
82         }
83         if(!isset($HTTPSIGNOREPEER))
84         {
85                 $HTTPSIGNOREPEER = false;
86         }
87         if(!isset($HTTPSVERIFYHOST))
88         {
89                 $HTTPSVERIFYHOST = 2;
90         }
91         if(!isset($SSLVERSION))
92         {
93                 $SSLVERSION = 0;
94         }
95         if(!isset($PROXY))
96         {
97                 $PROXYSERVER = null;
98         }
99         else
100         {
101                 $arr = explode(':',$PROXY);
102                 $PROXYSERVER = $arr[0];
103                 if(count($arr) > 1)
104                 {
105                         $PROXYPORT = $arr[1];
106                 }
107                 else
108                 {
109                         $PROXYPORT = 8080;
110                 }
111         }
112     // used to silence testsuite warnings about proxy code not being tested
113     if(!isset($NOPROXY))
114     {
115         $NOPROXY = false;
116     }
117         if(!isset($URI))
118         {
119                 // GUESTIMATE the url of local demo server
120                 // play nice to php 3 and 4-5 in retrieving URL of server.php
121                 /// @todo filter out query string from REQUEST_URI
122                 if(isset($REQUEST_URI))
123                 {
124                         $URI = str_replace('/test/testsuite.php', '/demo/server/server.php', $REQUEST_URI);
125                         $URI = str_replace('/testsuite.php', '/server.php', $URI);
126                         $URI = str_replace('/test/benchmark.php', '/demo/server/server.php', $URI);
127                         $URI = str_replace('/benchmark.php', '/server.php', $URI);
128                 }
129                 elseif(isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD']))
130                 {
131                         $URI = str_replace('/test/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']);
132                         $URI = str_replace('/testsuite.php', '/server.php', $URI);
133                         $URI = str_replace('/test/benchmark.php', '/demo/server/server.php', $URI);
134                         $URI = str_replace('/benchmark.php', '/server.php', $URI);
135                 }
136                 else
137                 {
138                         $URI = '/demo/server/server.php';
139                 }
140         }
141         if($URI[0] != '/')
142         {
143                 $URI = '/'.$URI;
144         }
145         if(!isset($LOCALPATH))
146         {
147                 $LOCALPATH = dirname(__FILE__);
148         }
149 ?>