Project

General

Profile

Download (4.32 KB) Statistics
| Branch: | Tag: | Revision:
1 207abd84 Colin Smith
<?php
2
/*
3
	$Id$
4
5
        xmlrpc.inc
6 0e16b9ca Scott Ullrich
        Copyright (C) 2005-2006 Colin Smith
7 207abd84 Colin Smith
        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 13657e92 Colin Smith
                $array[] = XML_RPC_decode($value);
41 207abd84 Colin Smith
        }
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 13657e92 Colin Smith
	/*
50 207abd84 Colin Smith
        switch($raw_value->kindOf()) {
51
        case "scalar":
52 5c6d0f65 Colin Smith
		if($raw_value->scalartyp() == "boolean") $return = (boolean) $raw_value->scalarval();
53 207abd84 Colin Smith
                $return = $raw_value->scalarval();
54
                break;
55
        case "array":
56
                $return = array();
57
                for($i = 0; $i < $raw_value->arraysize(); $i++) {
58
                        $value = $raw_value->arraymem($i);
59 970095a1 Colin Smith
                        $return[] = xmlrpc_value_to_php($value);
60 207abd84 Colin Smith
                }
61
                break;
62
        case "struct":
63
                $return = array();
64
                for($i = 0; $i < $raw_value->arraysize(); $i++) {
65
                        list($key, $value) = $raw_value->structeach();
66
                        $return[$key] = xmlrpc_value_to_php($value);
67
                }
68
                break;
69
        }
70 13657e92 Colin Smith
	*/
71 597398c0 Colin Smith
        return XML_RPC_decode($raw_value);
72 207abd84 Colin Smith
}
73
74
/*
75
 *   php_value_to_xmlrpc: Convert a PHP scalar or array into its XMLRPC equivalent.
76
 */
77
function php_value_to_xmlrpc($value, $force_array = false) {
78 13657e92 Colin Smith
	$toreturn = XML_RPC_encode($value);
79
	return $force_array ? array($toreturn) : $toreturn;
80
	/*
81 207abd84 Colin Smith
        if(gettype($value) == "array") {
82
                $xmlrpc_type = "array";
83
                $toreturn = array();
84
                foreach($value as $key => $val) {
85
                        if(is_string($key)) $xmlrpc_type = "struct";
86
                        $toreturn[$key] = php_value_to_xmlrpc($val);
87
                }
88
                return new XML_RPC_Value($toreturn, $xmlrpc_type);
89
        } else {
90
                if($force_array == true) {
91
                        return new XML_RPC_Value(array(new XML_RPC_Value($value, gettype($value))), "array");
92
                } else {
93
                        return new XML_RPC_Value($value, gettype($value));
94
                }
95
        }
96 13657e92 Colin Smith
	*/
97 207abd84 Colin Smith
}
98
99
/*
100
 *   xmlrpc_auth: Handle basic crypt() authentication of an XMLRPC request. This function assumes that
101
 *                $params[0] contains the local system's plaintext password and removes the password from
102
 *                the array before returning it.
103
 */
104
function xmlrpc_auth(&$params) {
105 01ee0278 Scott Ullrich
	global $config;
106 207abd84 Colin Smith
	$localpass = $config['system']['password'];
107 01ee0278 Scott Ullrich
	if(crypt($params[0], $localpass) == $localpass) {
108
		array_shift($params);
109 207abd84 Colin Smith
		return true;
110 01ee0278 Scott Ullrich
	} else if(crypt($params['xmlrpcauth'],  $localpass)  !=  $localpass)  {
111 207abd84 Colin Smith
		unset($params['xmlrpcauth']);
112 01ee0278 Scott Ullrich
		return false;
113 207abd84 Colin Smith
	}
114 66752f24 Scott Ullrich
	unset($params['xmlrpcauth']);
115
	return false;
116 207abd84 Colin Smith
}
117
118 01ee0278 Scott Ullrich
?>