Hi,

Today when working on services (7.x-3.0-rc5) to establish user login between Java client and Drupal7 I found something I belive is a bug.

The file: xmlrpc_server.module
function: xmlrpc_server_call_wrapper

Fix1:
if($arg['optional'] && isset($arg['default value']) ) {
$args[$index] = $arg['default value'];
} else {
if($arg['optional'] == FALSE && !isset($args[$index])) {
return services_error(t('Missing required argument @arg', array(
'@arg' => $arg['name'],
)), 401);
}
}

Should be:
if($arg['optional'] && isset($arg['default value']) && !isset($args[$index])) {
$args[$index] = $arg['default value'];
} else {
if($arg['optional'] == FALSE && !isset($args[$index])) {
return services_error(t('Missing required argument @arg', array(
'@arg' => $arg['name'],
)), 401);
}
}

Rational: when argument does not have default value and is not optional, we still need to check if value exist before we call and call "services_error(,,,) for missing argument.

Fix2:

if(is_array($controller['args'])) {
foreach($controller['args'] as $index => $arg) {
...
}
}

Should be:
if(isset($controller['args']) && is_array($controller['args'])) {
foreach($controller['args'] as $index => $arg) {
...
}
}

Rational: In some cases the args are not define in the resource. for example user.logout. So either empty args are defined or that we need to add this condition.

I still have a problem with "user.logout" since the $user->uid is not defined when executing function "_user_resource_logout" in file "user_resource.inc" but I still didn't find the resolution for this problem.
I added some "watchdog" message in the "session.inc" file which is where user populated from session, but it looks like the method of populating the user from session is invoked after "_user_resource_logout" is invoked. I made this conclusion because the message from "session.inc" always appear after the messages I added into "_user_resource_logout" function.

Yet, I am not understanding yet the full request cycle to explain why is this happen this way. Maybe you can give a hint.
Anyway, user.logout service call always fail with error: "User is not logged in"
Then when I check the loaded user from within "session.inc" (function: _drupal_session_read) the user is loaded from session with the correct uid. So my current suspicion is about something wring in the service call request cycle. But again it is only a guess.

Beside that user.create is now working for me after the fixes I did.

Regards,
Gilad.

Comments

kylebrowning’s picture

Status:Active» Closed (duplicate)