Project

General

Profile

Download (4.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	$Id$
4

    
5
        xmlrpc.inc
6
        Copyright (C) 2005 Colin Smith
7
        All rights reserved.
8

    
9
        Redistribution and use in source and binary forms, with or without
10
        modification, are permitted provided that the following conditions are met:
11

    
12
        1. Redistributions of source code must retain the above copyright notice,
13
           this list of conditions and the following disclaimer.
14

    
15
        2. Redistributions in binary form must reproduce the above copyright
16
           notice, this list of conditions and the following disclaimer in the
17
           documentation and/or other materials provided with the distribution.
18

    
19
        THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
        INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
        AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
        AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
        OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
        SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
        INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
        CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
        ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
        POSSIBILITY OF SUCH DAMAGE.
29
*/
30

    
31
require_once("xmlrpc_client.inc");
32

    
33
/*
34
 *   xmlrpc_params_to_php: Convert params array passed from XMLRPC server into a PHP array and return it.
35
 */
36
function xmlrpc_params_to_php($params) {
37
        $array = array();
38
        for($i = 0; $i < $params->getNumParams(); $i++) {
39
                $value = $params->getParam($i);
40
                $array[] = xmlrpc_value_to_php($value);
41
        }
42
        return $array;
43
}
44
 
45
/*
46
 *   xmlrpc_value_to_php: Convert an XMLRPC value into a PHP scalar/array and return it.
47
 */
48
function xmlrpc_value_to_php($raw_value) {
49
        switch($raw_value->kindOf()) {
50
        case "scalar":
51
		if($raw_value->scalartyp() == "boolean") $return = (boolean) $raw_value->scalarval();
52
                $return = $raw_value->scalarval();
53
                break;
54
        case "array":
55
                $return = array();
56
                for($i = 0; $i < $raw_value->arraysize(); $i++) {
57
                        $value = $raw_value->arraymem($i);
58
                        $return[] = xmlrpc_value_to_php($value);
59
                }
60
                break;
61
        case "struct":
62
                $return = array();
63
                for($i = 0; $i < $raw_value->arraysize(); $i++) {
64
                        list($key, $value) = $raw_value->structeach();
65
                        $return[$key] = xmlrpc_value_to_php($value);
66
                }
67
                break;
68
        }
69
        return $return;
70
}
71

    
72
/*
73
 *   php_value_to_xmlrpc: Convert a PHP scalar or array into its XMLRPC equivalent.
74
 */
75
function php_value_to_xmlrpc($value, $force_array = false) {
76
        if(gettype($value) == "array") {
77
                $xmlrpc_type = "array";
78
                $toreturn = array();
79
                foreach($value as $key => $val) {
80
                        if(is_string($key)) $xmlrpc_type = "struct";
81
                        $toreturn[$key] = php_value_to_xmlrpc($val);
82
                }
83
                return new XML_RPC_Value($toreturn, $xmlrpc_type);
84
        } else {
85
                if($force_array == true) {
86
                        return new XML_RPC_Value(array(new XML_RPC_Value($value, gettype($value))), "array");
87
                } else {
88
                        return new XML_RPC_Value($value, gettype($value));
89
                }
90
        }
91
}
92

    
93
/*
94
 *   xmlrpc_auth: Handle basic crypt() authentication of an XMLRPC request. This function assumes that
95
 *                $params[0] contains the local system's plaintext password and removes the password from
96
 *                the array before returning it.
97
 */
98
function xmlrpc_auth(&$params) {
99
        global $config;
100
	$localpass = $config['system']['password'];
101
        if(crypt($params[0], $localpass) == $localpass) {
102
                array_shift($params);
103
		return true;
104
	} elseif(crypt($params['xmlrpcauth'], $localpass) != $localpass) {
105
		unset($params['xmlrpcauth']);
106
		return true;
107
	}
108
        return false;
109
}
110

    
(20-20/22)