Skip to content
Commits on Source (21)
// $Id$
Goals
==============
......
<?php
// $Id$
/**
* @file
......@@ -53,9 +52,14 @@ function services_keyauth_admin_keys_form() {
$key_kid = isset($key->kid) ? $key->kid : '';
$key_title = isset($key->title) ? $key->title : '';
$domain = isset($key->domain) ? $key->domain : '';
$form['kid'] = array(
'#type' => 'hidden',
'#default_value' => $key_kid,
'#type' => 'value',
'#value' => $key_kid,
);
$form['previous_domain'] = array(
'#type' => 'value',
'#value' => $domain,
);
$accessible_methods = array();
......@@ -80,7 +84,7 @@ function services_keyauth_admin_keys_form() {
$form['domain'] = array(
'#title' => t('Allowed domain'),
'#type' => 'textfield',
'#default_value' => isset($key->domain) ? $key->domain : '',
'#default_value' => $domain,
'#description' => t('External domain allowed to use this key.'),
'#required' => TRUE,
);
......@@ -106,6 +110,19 @@ function services_keyauth_admin_keys_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().
*/
......
<?php
// $Id$
/**
* @file
......@@ -69,18 +68,21 @@ function _services_keyauth_alter_methods(&$methods) {
'name' => 'sessid',
'type' => 'string',
'description' => t('A valid sessid.'),
'source' => array('param' => 'sessid'),
);
$arg_domain_time_stamp = array(
'name' => 'domain_time_stamp',
'type' => 'string',
'description' => t('Time stamp used to hash key.'),
'source' => array('param' => 'domain_time_stamp'),
);
$arg_nonce = array(
'name' => 'nonce',
'type' => 'string',
'description' => t('One-time-use nonce also used to hash key.'),
'source' => array('param' => 'nonce'),
);
// domain arg
......@@ -88,6 +90,7 @@ function _services_keyauth_alter_methods(&$methods) {
'name' => 'domain_name',
'type' => 'string',
'description' => t('A valid domain for the API key.'),
'source' => array('param' => 'domain_name'),
);
// api_key arg
......@@ -95,6 +98,7 @@ function _services_keyauth_alter_methods(&$methods) {
'name' => 'hash',
'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.'),
'source' => array('param' => 'hash'),
);
foreach ($methods as $key => &$method) {
......@@ -166,7 +170,7 @@ function _services_keyauth_alter_browse_form(&$form, $method) {
break;
case 'nonce':
$form['arg'][$key]['#title'] = t('Nonce');
$form['arg'][$key]['#default_value'] = user_password();
$form['arg'][$key]['#value'] = user_password();
break;
}
}
......@@ -226,7 +230,7 @@ function _services_keyauth_authenticate_call($method, $method_name, &$args) {
if ($method['auth'] && variable_get('services_use_sessid', TRUE)) {
$sessid = array_shift($args);
if (empty($sessid)) {
return t('Invalid sessid.');
return services_error(t('Invalid sessid.'), 401);
}
$session_backup = services_session_load($sessid);
}
......
; $Id$
name = Key Authentication
description = Provides key authentication for the services module
package = Services - authentication
......
<?php
// $Id$
/**
* @file
* Provides a key based validation system.
......@@ -113,7 +112,7 @@ function services_keyauth_menu() {
function services_get_hash($timestamp, $domain, $nonce, $method, $args) {
$hash_parameters = array($timestamp, $domain, $nonce, $method['method']);
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_array($args[$key]) || is_object($args[$key])) {
$hash_parameters[] = serialize($args[$key]);
......
; $Id$
name = XMLRPC Server
description = Provides an XMLRPC server.
package = Services - servers
......
<?php
// $Id$
/**
* @file
* Enable XML-RPC for services module.
......@@ -54,25 +53,34 @@ function xmlrpc_server_call_wrapper() {
/**
* Implementation of hook_server_error().
*
* 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()
*/
function xmlrpc_server_server_error($message) {
function xmlrpc_server_server_error($message, $code = 0) {
if (!is_array($message)) {
$message = (array)$message;
}
$message = implode(' ', $message);
$matches = array();
if (preg_match("/\#(\d+)/", $message, $matches)) {
$code = $matches[1];
}
else {
$code = 1;
if ($code === 0) {
$matches = array();
if (preg_match("/\#(\d+)/", $message, $matches)) {
$code = $matches[1];
}
else {
$code = 1;
}
}
return xmlrpc_error($code, strip_tags($message));
}
\ No newline at end of file
}
/* $Id$ */
#service-browser-arguments .type {
width: 40px;
......
; $Id$
name = Services
description = Provide an API for creating web services.
package = Services
......
<?php
// $Id$
/**
* @file
......
<?php
// $Id$
/**
* @file
......@@ -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
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'])) {
$method = $method_name;
}
......@@ -393,13 +400,17 @@ function services_method_call($method_name, $args = array(), $browsing = FALSE)
// Check for missing args
$hash_parameters = array();
$missing_parameters = array();
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])) {
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
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)
drupal_set_message(t('Authentication failed: !message', array('!message' => $auth_error)), 'error');
}
else {
return services_error($auth_error, 401);
return $auth_error;
}
}
......@@ -854,7 +865,7 @@ function services_session_load($sessid) {
sess_read($sessid);
// 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);
return NULL;
}
......
; $Id$
name = Comment Service
description = Provides a comment service.
package = Services - services
......
; $Id$
core = "6.x"
dependencies[] = services
description = "Provides a file service."
......
<?php
// $Id$
/**
* @file
* Link general file functionalities to services module.
......
<?php
// $Id$
/**
* @file
* Adds a service type for a menu
......@@ -16,8 +15,8 @@
* An array of fields to be returned, for use in limiting the
* size of data returned to only that which is necessary.
* @param $language
* The language code of the menu to return. Optional if site
* has only one language (or i18n is not installed <- verify)
* The language code of the menu to return. Optional if site
* has only one language (or i18n is not installed)
*
* @return
* 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 = '') {
if (sizeof($fields) === 0) {
$fields = FALSE;
}
$languages = language_list();
if (isset($languages[$language])) {
$GLOBALS['language'] = $languages[$language];
}
$data = menu_tree_all_data($menu_id);
return menu_service_process($data, $fields, $language);
}
......