Skip to content
Commits on Source (21)
// $Id$
Goals Goals
============== ==============
......
<?php <?php
// $Id$
/** /**
* @file * @file
...@@ -53,9 +52,14 @@ function services_keyauth_admin_keys_form() { ...@@ -53,9 +52,14 @@ function services_keyauth_admin_keys_form() {
$key_kid = isset($key->kid) ? $key->kid : ''; $key_kid = isset($key->kid) ? $key->kid : '';
$key_title = isset($key->title) ? $key->title : ''; $key_title = isset($key->title) ? $key->title : '';
$domain = isset($key->domain) ? $key->domain : '';
$form['kid'] = array( $form['kid'] = array(
'#type' => 'hidden', '#type' => 'value',
'#default_value' => $key_kid, '#value' => $key_kid,
);
$form['previous_domain'] = array(
'#type' => 'value',
'#value' => $domain,
); );
$accessible_methods = array(); $accessible_methods = array();
...@@ -80,7 +84,7 @@ function services_keyauth_admin_keys_form() { ...@@ -80,7 +84,7 @@ function services_keyauth_admin_keys_form() {
$form['domain'] = array( $form['domain'] = array(
'#title' => t('Allowed domain'), '#title' => t('Allowed domain'),
'#type' => 'textfield', '#type' => 'textfield',
'#default_value' => isset($key->domain) ? $key->domain : '', '#default_value' => $domain,
'#description' => t('External domain allowed to use this key.'), '#description' => t('External domain allowed to use this key.'),
'#required' => TRUE, '#required' => TRUE,
); );
...@@ -106,6 +110,19 @@ function services_keyauth_admin_keys_form() { ...@@ -106,6 +110,19 @@ function services_keyauth_admin_keys_form() {
return $form; return $form;
} }
/**
* Validate callback for services_keyauth_admin_keys_form().
*/
function services_keyauth_admin_keys_form_validate($form, &$form_state) {
$domain = trim($form_state['values']['domain']);
$previous_domain = trim($form_state['values']['previous_domain']);
if ($previous_domain != $domain) {
if (db_result(db_query("SELECT count(*) FROM {services_keys} WHERE domain = '%s'", $domain))) {
form_set_error('domain', t('Domain @domain already exists.', array('@domain', $domain)));
}
}
}
/** /**
* Submit callback for services_keyauth_admin_keys_form(). * Submit callback for services_keyauth_admin_keys_form().
*/ */
......
<?php <?php
// $Id$
/** /**
* @file * @file
...@@ -69,18 +68,21 @@ function _services_keyauth_alter_methods(&$methods) { ...@@ -69,18 +68,21 @@ function _services_keyauth_alter_methods(&$methods) {
'name' => 'sessid', 'name' => 'sessid',
'type' => 'string', 'type' => 'string',
'description' => t('A valid sessid.'), 'description' => t('A valid sessid.'),
'source' => array('param' => 'sessid'),
); );
$arg_domain_time_stamp = array( $arg_domain_time_stamp = array(
'name' => 'domain_time_stamp', 'name' => 'domain_time_stamp',
'type' => 'string', 'type' => 'string',
'description' => t('Time stamp used to hash key.'), 'description' => t('Time stamp used to hash key.'),
'source' => array('param' => 'domain_time_stamp'),
); );
$arg_nonce = array( $arg_nonce = array(
'name' => 'nonce', 'name' => 'nonce',
'type' => 'string', 'type' => 'string',
'description' => t('One-time-use nonce also used to hash key.'), 'description' => t('One-time-use nonce also used to hash key.'),
'source' => array('param' => 'nonce'),
); );
// domain arg // domain arg
...@@ -88,6 +90,7 @@ function _services_keyauth_alter_methods(&$methods) { ...@@ -88,6 +90,7 @@ function _services_keyauth_alter_methods(&$methods) {
'name' => 'domain_name', 'name' => 'domain_name',
'type' => 'string', 'type' => 'string',
'description' => t('A valid domain for the API key.'), 'description' => t('A valid domain for the API key.'),
'source' => array('param' => 'domain_name'),
); );
// api_key arg // api_key arg
...@@ -95,6 +98,7 @@ function _services_keyauth_alter_methods(&$methods) { ...@@ -95,6 +98,7 @@ function _services_keyauth_alter_methods(&$methods) {
'name' => 'hash', 'name' => 'hash',
'type' => 'string', 'type' => 'string',
'description' => t('An SHA-256 hash of the timestamp, domain, nonce, and method name delimited by semicolons and using the remote API key as the shared key.'), 'description' => t('An SHA-256 hash of the timestamp, domain, nonce, and method name delimited by semicolons and using the remote API key as the shared key.'),
'source' => array('param' => 'hash'),
); );
foreach ($methods as $key => &$method) { foreach ($methods as $key => &$method) {
...@@ -166,7 +170,7 @@ function _services_keyauth_alter_browse_form(&$form, $method) { ...@@ -166,7 +170,7 @@ function _services_keyauth_alter_browse_form(&$form, $method) {
break; break;
case 'nonce': case 'nonce':
$form['arg'][$key]['#title'] = t('Nonce'); $form['arg'][$key]['#title'] = t('Nonce');
$form['arg'][$key]['#default_value'] = user_password(); $form['arg'][$key]['#value'] = user_password();
break; break;
} }
} }
...@@ -226,7 +230,7 @@ function _services_keyauth_authenticate_call($method, $method_name, &$args) { ...@@ -226,7 +230,7 @@ function _services_keyauth_authenticate_call($method, $method_name, &$args) {
if ($method['auth'] && variable_get('services_use_sessid', TRUE)) { if ($method['auth'] && variable_get('services_use_sessid', TRUE)) {
$sessid = array_shift($args); $sessid = array_shift($args);
if (empty($sessid)) { if (empty($sessid)) {
return t('Invalid sessid.'); return services_error(t('Invalid sessid.'), 401);
} }
$session_backup = services_session_load($sessid); $session_backup = services_session_load($sessid);
} }
......
; $Id$
name = Key Authentication name = Key Authentication
description = Provides key authentication for the services module description = Provides key authentication for the services module
package = Services - authentication package = Services - authentication
......
<?php <?php
// $Id$
/** /**
* @file * @file
......
<?php <?php
// $Id$
/** /**
* @file * @file
* Provides a key based validation system. * Provides a key based validation system.
...@@ -113,7 +112,7 @@ function services_keyauth_menu() { ...@@ -113,7 +112,7 @@ function services_keyauth_menu() {
function services_get_hash($timestamp, $domain, $nonce, $method, $args) { function services_get_hash($timestamp, $domain, $nonce, $method, $args) {
$hash_parameters = array($timestamp, $domain, $nonce, $method['method']); $hash_parameters = array($timestamp, $domain, $nonce, $method['method']);
foreach ($method['args'] as $key => $arg) { foreach ($method['args'] as $key => $arg) {
if ($arg['signed'] == TRUE) { if (isset($arg['signed']) && $arg['signed'] == TRUE) {
if (is_numeric($args[$key]) || !empty($args[$key])) { if (is_numeric($args[$key]) || !empty($args[$key])) {
if (is_array($args[$key]) || is_object($args[$key])) { if (is_array($args[$key]) || is_object($args[$key])) {
$hash_parameters[] = serialize($args[$key]); $hash_parameters[] = serialize($args[$key]);
......
; $Id$
name = XMLRPC Server name = XMLRPC Server
description = Provides an XMLRPC server. description = Provides an XMLRPC server.
package = Services - servers package = Services - servers
......
<?php <?php
// $Id$
/** /**
* @file * @file
* Enable XML-RPC for services module. * Enable XML-RPC for services module.
...@@ -54,25 +53,34 @@ function xmlrpc_server_call_wrapper() { ...@@ -54,25 +53,34 @@ function xmlrpc_server_call_wrapper() {
/** /**
* Implementation of hook_server_error(). * Implementation of hook_server_error().
*
* Takes the error message and wraps it into an XMLRPC error object. * Takes the error message and wraps it into an XMLRPC error object.
* *
* @param string $message
* The error message.
* @param int $code
* Optional. An error code, these should map to the applicable
* http error codes as closely as possible.
*
* @return
* An error as specified by the XMLRPC server.
* @see xmlrpc_error() * @see xmlrpc_error()
*/ */
function xmlrpc_server_server_error($message) { function xmlrpc_server_server_error($message, $code = 0) {
if (!is_array($message)) { if (!is_array($message)) {
$message = (array)$message; $message = (array)$message;
} }
$message = implode(' ', $message); $message = implode(' ', $message);
$matches = array(); if ($code === 0) {
if (preg_match("/\#(\d+)/", $message, $matches)) { $matches = array();
$code = $matches[1]; if (preg_match("/\#(\d+)/", $message, $matches)) {
} $code = $matches[1];
else { }
$code = 1; else {
$code = 1;
}
} }
return xmlrpc_error($code, strip_tags($message)); return xmlrpc_error($code, strip_tags($message));
} }
\ No newline at end of file
/* $Id$ */
#service-browser-arguments .type { #service-browser-arguments .type {
width: 40px; width: 40px;
......
; $Id$
name = Services name = Services
description = Provide an API for creating web services. description = Provide an API for creating web services.
package = Services package = Services
......
<?php <?php
// $Id$
/** /**
* @file * @file
......
<?php <?php
// $Id$
/** /**
* @file * @file
...@@ -379,6 +378,14 @@ function services_method_call($method_name, $args = array(), $browsing = FALSE) ...@@ -379,6 +378,14 @@ function services_method_call($method_name, $args = array(), $browsing = FALSE)
// Allow external modules to log the results of this service call // Allow external modules to log the results of this service call
module_invoke_all('services_method_call', $method_name, $args, $browsing); module_invoke_all('services_method_call', $method_name, $args, $browsing);
// If we're dealing with a resource, we need to convert it.
if(isset($method_name['resource_type']) && is_array($method_name)) {
module_load_include('inc', 'services', 'services.resource-translation');
$method_name = _services_resource_controller_as_service(
$method_name['resource_name'], $method_name['resource_type'] ,
$method_name, $method_name['file']);
}
if (is_array($method_name) && isset($method_name['callback'])) { if (is_array($method_name) && isset($method_name['callback'])) {
$method = $method_name; $method = $method_name;
} }
...@@ -393,13 +400,17 @@ function services_method_call($method_name, $args = array(), $browsing = FALSE) ...@@ -393,13 +400,17 @@ function services_method_call($method_name, $args = array(), $browsing = FALSE)
// Check for missing args // Check for missing args
$hash_parameters = array(); $hash_parameters = array();
$missing_parameters = array();
foreach ($method['args'] as $key => $arg) { foreach ($method['args'] as $key => $arg) {
if (!$arg['optional']) { if (isset($arg['optional']) && !$arg['optional']) {
if (!isset($args[$key]) && !is_array($args[$key]) && !is_bool($args[$key])) { if (!isset($args[$key]) && !is_array($args[$key]) && !is_bool($args[$key])) {
return services_error(t('Missing required arguments.'), 406); $missing_parameters[] = $arg['name'];
} }
} }
} }
if (!empty($missing_parameters)) {
return services_error(t('Missing required arguments: @missing', array('@missing' => implode(', ', $missing_parameters))), 406);
}
// Check authentication // Check authentication
if ($method['auth'] && $auth_error = services_auth_invoke('authenticate_call', $method, $method_name, $args)) { if ($method['auth'] && $auth_error = services_auth_invoke('authenticate_call', $method, $method_name, $args)) {
...@@ -407,7 +418,7 @@ function services_method_call($method_name, $args = array(), $browsing = FALSE) ...@@ -407,7 +418,7 @@ function services_method_call($method_name, $args = array(), $browsing = FALSE)
drupal_set_message(t('Authentication failed: !message', array('!message' => $auth_error)), 'error'); drupal_set_message(t('Authentication failed: !message', array('!message' => $auth_error)), 'error');
} }
else { else {
return services_error($auth_error, 401); return $auth_error;
} }
} }
...@@ -854,7 +865,7 @@ function services_session_load($sessid) { ...@@ -854,7 +865,7 @@ function services_session_load($sessid) {
sess_read($sessid); sess_read($sessid);
// Check if it really loaded the user. // Check if it really loaded the user.
if ($user->sid != $sessid) { if (!isset($user->sid) || (isset($user->sid) && $user->sid != $sessid)) {
services_session_unload($backup); services_session_unload($backup);
return NULL; return NULL;
} }
......
<?php <?php
// $Id$
/** /**
* @file * @file
......
<?php <?php
// $Id$
/** /**
* @file * @file
......
; $Id$
name = Comment Service name = Comment Service
description = Provides a comment service. description = Provides a comment service.
package = Services - services package = Services - services
......
<?php <?php
// $Id$
/** /**
* @file * @file
......
<?php <?php
// $Id$
/** /**
* @file * @file
......
; $Id$
core = "6.x" core = "6.x"
dependencies[] = services dependencies[] = services
description = "Provides a file service." description = "Provides a file service."
......
<?php <?php
// $Id$
/** /**
* @file * @file
* Link general file functionalities to services module. * Link general file functionalities to services module.
......
<?php <?php
// $Id$
/** /**
* @file * @file
* Adds a service type for a menu * Adds a service type for a menu
...@@ -16,8 +15,8 @@ ...@@ -16,8 +15,8 @@
* An array of fields to be returned, for use in limiting the * An array of fields to be returned, for use in limiting the
* size of data returned to only that which is necessary. * size of data returned to only that which is necessary.
* @param $language * @param $language
* The language code of the menu to return. Optional if site * The language code of the menu to return. Optional if site
* has only one language (or i18n is not installed <- verify) * has only one language (or i18n is not installed)
* *
* @return * @return
* An array of all child menu items from a given menu item. * An array of all child menu items from a given menu item.
...@@ -29,6 +28,12 @@ function menu_service_get($menu_id = NULL, $fields = array(), $language = '') { ...@@ -29,6 +28,12 @@ function menu_service_get($menu_id = NULL, $fields = array(), $language = '') {
if (sizeof($fields) === 0) { if (sizeof($fields) === 0) {
$fields = FALSE; $fields = FALSE;
} }
$languages = language_list();
if (isset($languages[$language])) {
$GLOBALS['language'] = $languages[$language];
}
$data = menu_tree_all_data($menu_id); $data = menu_tree_all_data($menu_id);
return menu_service_process($data, $fields, $language); return menu_service_process($data, $fields, $language);
} }
......