Index: captcha.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/captcha.module,v
retrieving revision 1.42.2.16
diff -u -b -B -u -p -r1.42.2.16 captcha.module
--- captcha.module	10 Aug 2007 13:54:26 -0000	1.42.2.16
+++ captcha.module	11 Aug 2007 18:47:09 -0000
@@ -7,20 +7,11 @@
  * adminstrators can add a captcha to desired forms that users without
  * the 'skip captcha' permission (typically anonymous visitors) have to solve.
  *
- * @todo move captcha configuration page to user management/user permissions?
- *
- * @todo shouldn't it be better to drop the GUI-option for captcha persistence
- * and make it required? Captchas are for making it hard for spambots to post
- * and disabling captcha persistence is making it easier.
- *
- * @todo work on the captcha_token stuff. Submitting several forms at the same
- * time does not work with current implementation
- *
- * @todo add option for randomly selecting a captcha challenge type when several
- * are available?
- *
  * @todo add localisation (po) files
  *
+ * @todo delete the API mismatch stuff in captcha_form_alter()
+ * when no known captcha modules still follow the old API
+ *
  * @bug
  * In some situations the placement of the captcha just above the submit button
  * fails.
@@ -91,6 +82,11 @@ function _captcha_available_challenge_ty
     if (isset($result)) { //&& is_array($result)) {
       foreach($result as $challenge) {
         $captcha_challenges["$module/$challenge"] = "$challenge ($module)";
+        // check captcha API
+        $result = call_user_func_array($module .'_captcha', array('generate', $challenge));
+        if (!isset($result['solution']) || !isset($result['form']['captcha_response'])) {
+          drupal_set_message(t('Captcha type %captcha of module %module is not guaranteed to work because it does not follow captcha API v3.', array('%captcha' => $challenge, '%module' => $module)), 'error');
+        }
       }
     }
   }
@@ -286,6 +282,29 @@ function captcha_form_alter($form_id, &$
       return;
     }
 
+    // TODO: delete this API mismatch stuff when no known captcha modules still follow the old API
+    // check if the invoked captcha hook follows the expected API (captcha v3.x API)
+    // and try to get the data through the old API if needed
+    if (!isset($captcha['solution'])) {
+      $captcha['solution'] = $captcha['value'];
+      $api_mismatch = TRUE;
+    }
+    if (!isset($captcha['form']['captcha_response'])) {
+      $captcha['form']['captcha_response'] = $captcha['form']['captcha_answer'];
+      unset($captcha['form']['captcha_answer']);
+      $api_mismatch = TRUE;
+    }
+    if ($api_mismatch) {
+      // warn about depricated API
+      if ($captcha['solution'] && $captcha['form']['captcha_response']) {
+        watchdog('captcha', t('The captcha hook of the module %module follows the old depricated captcha API. The mismatch has been resolved as best as possible. However, try to contact the module developer to resolve this issue.', array('%module' => $captcha_point->module)), WATCHDOG_WARNING);
+      }
+      else {
+        watchdog('captcha', t('The captcha hook of the module %module follows an unknown API.', array('%module' => $captcha_point->module)), WATCHDOG_ERROR);
+        return;
+      }
+    }
+
     // Add a captcha part to the form (depends on value of captcha_description)
     $captcha_description = _captcha_get_description();
     if ($captcha_description) {
@@ -313,7 +332,7 @@ function captcha_form_alter($form_id, &$
     // before validation and are the right place to store the solution in $_SESSION.
     $form['captcha']['captcha_solution'] = array (
       '#type' => 'value',
-      '#value' => $captcha['value'],
+      '#value' => $captcha['solution'],
     );
 
     // The captcha token is used to differentiate between different instances
@@ -384,7 +403,7 @@ function captcha_form_alter($form_id, &$
  */
 function captcha_validate($form_values) {
   // Get answer and preprocess if needed
-  $captcha_answer = $form_values['#post']['captcha_answer'];
+  $captcha_answer = $form_values['#post']['captcha_response'];
   $validationdata = $form_values['validationdata']['#value'];
   if ($validationdata['preprocess']) {
     $captcha_answer = module_invoke($validationdata['module'], 'captcha', 'process', $validationdata['type'], $captcha_answer);
@@ -400,7 +419,7 @@ function captcha_validate($form_values) 
     $_SESSION['captcha'][$form_id]['success'] = TRUE;
   }
   else {
-    form_set_error('captcha_answer', t('The answer you entered to the captcha challenge is not correct.'));
+    form_set_error('captcha_response', t('The answer you entered for the captcha challenge was not correct.'));
   }
 
   // Unset the solution to prevent reuse of the same captcha solution
@@ -426,8 +445,8 @@ function captcha_pre_render($form_id, &$
   $captcha_token = $form['captcha']['captcha_token']['#value'];
   $_SESSION['captcha'][$form_id][$captcha_token] = $form['captcha']['captcha_solution']['#value'];
   $_SESSION['captcha'][$form_id]['success'] = FALSE;
-  // empty the value of the captcha_answer form item before rendering
-  $form['captcha']['captcha_answer']['#value'] = '';
+  // empty the value of the captcha_response form item before rendering
+  $form['captcha']['captcha_response']['#value'] = '';
 }
 
 /**
@@ -461,11 +480,11 @@ function captcha_captcha($op, $captcha_t
     case 'generate':
       if ($captcha_type == 'Math') {
         $result = array();
-        $answer = mt_rand(1, 20);
-        $x = mt_rand(1, $answer);
-        $y = $answer - $x;
-        $result['value'] = "$answer";
-        $result['form']['captcha_answer'] = array (
+        $solution = mt_rand(1, 20);
+        $x = mt_rand(1, $solution);
+        $y = $solution - $x;
+        $result['solution'] = "$solution";
+        $result['form']['captcha_response'] = array (
           '#type' => 'textfield',
           '#title' => t('Math Question: What is %problem?', array('%problem' => "$x + $y")),
           '#description' => t('Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.'),
Index: captcha_api.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/Attic/captcha_api.txt,v
retrieving revision 1.1.4.4
diff -u -b -B -u -p -r1.1.4.4 captcha_api.txt
--- captcha_api.txt	19 Jul 2007 21:54:55 -0000	1.1.4.4
+++ captcha_api.txt	11 Aug 2007 18:47:09 -0000
@@ -20,9 +20,9 @@ Functionality depends on the first argum
     You should return an array that offers form elements and the solution
     of your captcha challenge, defined by the second argument $captcha_type.
     The returned array $result should have the following items:
-    $result['value']: this is the solution of your captcha challenge
+    $result['solution']: this is the solution of your captcha challenge
     $result['form']: an array of the form elements you want to add to the form.
-      There should be a key 'captcha_answer' in this array, which points to
+      There should be a key 'captcha_response' in this array, which points to
       the form element where the user enters his answer.
 
 To make this more clear: a simple example. The captcha challenge is called
@@ -41,7 +41,7 @@ function foo_captcha_captcha($op, $captc
       if ($captcha_type == "Foo captcha") {
         $result = array();
         $result['solution'] = 'foo';
-        $result['form']['captcha_answer'] = array (
+        $result['form']['captcha_response'] = array (
           '#type' => 'textfield',
           '#title' => t('Enter "foo"'),
           '#required' => TRUE,
Index: image_captcha/image_captcha.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/Attic/image_captcha.module,v
retrieving revision 1.1.4.6
diff -u -b -B -u -p -r1.1.4.6 image_captcha.module
--- image_captcha/image_captcha.module	3 Aug 2007 18:18:37 -0000	1.1.4.6
+++ image_captcha/image_captcha.module	11 Aug 2007 18:47:09 -0000
@@ -165,13 +165,13 @@ function image_captcha_captcha($op, $cap
         $_SESSION['image_captcha'][$seed] = $code;
         // build the result to return
         $result = array();
-        $result['value'] = $code;
+        $result['solution'] = $code;
         $result['form']['captcha_image'] = array(
           '#type' => 'markup',
           '#value' => '<img src="'. check_url(url("image_captcha/$seed")) .'" />',
           '#weight' => -2,
         );
-        $result['form']['captcha_answer'] = array(
+        $result['form']['captcha_response'] = array(
           '#type' => 'textfield',
           '#title' => t('What code is in the image?'),
           '#description' => t('Copy the characters (respecting upper/lower case) from the image.'),
Index: text_captcha/text_captcha.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/text_captcha/Attic/text_captcha.module,v
retrieving revision 1.1.4.6
diff -u -b -B -u -p -r1.1.4.6 text_captcha.module
--- text_captcha/text_captcha.module	19 Jul 2007 22:05:05 -0000	1.1.4.6
+++ text_captcha/text_captcha.module	11 Aug 2007 18:47:09 -0000
@@ -168,8 +168,8 @@ function text_captcha_captcha($op, $capt
         $answer = $words[$key];
         // store the answer and build the form elements
         $result = array();
-        $result['value'] = $answer;
-        $result['form']['captcha_answer'] = array (
+        $result['solution'] = $answer;
+        $result['form']['captcha_response'] = array (
           '#type' => 'textfield',
           '#title' => t('What is the @nth word in the captcha phrase "@words"?', array('@nth' => _text_captcha_ordinal($key+1), '@words' => implode(' ', $words))),
           '#weight' => 0,
