1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Horde_Rpc_Phpgw extends Horde_Rpc
15: {
16: 17: 18: 19: 20:
21: var $_server;
22:
23: 24: 25:
26: function __construct($request, $params = array())
27: {
28: parent::__construct($request, $params);
29:
30: $this->_server = xmlrpc_server_create();
31:
32:
33: foreach ($GLOBALS['registry']->listMethods('phpgw') as $method) {
34: $methods = explode('/', $method);
35: array_shift($methods);
36: $method = implode('.', $methods);
37: xmlrpc_server_register_method($this->_server, $method, array('Horde_Rpc_Phpgw', '_dispatcher'));
38: }
39: }
40:
41: 42: 43:
44: function authorize()
45: {
46: return true;
47: }
48:
49: 50: 51: 52: 53: 54: 55:
56: function getResponse($request)
57: {
58: $response = null;
59: return xmlrpc_server_call_method($this->_server, $request, $response);
60: }
61:
62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73:
74: function _dispatcher($method, $params, $data)
75: {
76: global $registry;
77: $method = str_replace('.', '/', 'phpgw.' . $method);
78:
79: if (!$registry->hasMethod($method)) {
80: Horde::logMessage(sprintf(Horde_Rpc_Translation::t("Method \"%s\" is not defined"), $method), 'NOTICE');
81: return sprintf(Horde_Rpc_Translation::t("Method \"%s\" is not defined"), $method);
82: }
83:
84:
85: if (isset($params[0]['kp3']) && $params[0]["kp3"] == session_name() && session_id() != $params[0]["sessionid"]) {
86: Horde::logMessage("manually reload session ".$params[0]["sessionid"], 'NOTICE');
87: session_regenerate_id();
88: session_unset();
89: session_id($params[0]["sessionid"]);
90: }
91:
92:
93: $authenticated = $registry->isAuthenticated() || $method== "phpgw/system/login";
94:
95: if ($authenticated) {
96: Horde::logMessage("rpc call $method allowed", 'NOTICE');
97: return $registry->call($method, $params);
98: } else {
99: return PEAR::raiseError(Horde_Rpc_Translation::t("You did not authenticate."), 'horde.error');
100:
101:
102: }
103: }
104:
105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119:
120: public static function request($url, $method, $client, $params = null)
121: {
122: $options['method'] = 'POST';
123: $headers = array(
124: 'User-Agent' => 'Horde RPC client',
125: 'Content-Type', 'text/xml');
126: try {
127: $result = $client->post($url, xmlrpc_encode_request($method, $params), $headers);
128: } catch (Horde_Http_Client_Exception $e) {
129: throw new Horde_Rpc_Exception($result);
130: }
131: if ($result->code != 200) {
132: throw new Horde_Rpc_Exception(Horde_Rpc_Translation::t("Request couldn't be answered. Returned errorcode: ") . $result->code);
133: } elseif (strpos($result->getBody(), '<?xml') === false) {
134: throw new Horde_Rpc_Exception(Horde_Rpc_Translation::t("No valid XML data returned:") . "\n" . $result->getBody());
135: } else {
136: $response = @xmlrpc_decode(substr($result->getBody(), strpos($result->getBody(), '<?xml')));
137: if (is_array($response) && isset($response['faultString'])) {
138: throw new Horde_Rpc_Exception($response['faultString']);
139: } elseif (is_array($response) && isset($response[0]) &&
140: is_array($response[0]) && isset($response[0]['faultString'])) {
141: throw new Horde_Rpc_Exception($response[0]['faultString']);
142: }
143: return $response;
144: }
145: }
146:
147: }
148: