cms/drupal/modules/openid/openid.install
changeset 541 e756a8c72c3d
equal deleted inserted replaced
540:07239de796bb 541:e756a8c72c3d
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * @file
       
     5  * Install, update and uninstall functions for the openid module.
       
     6  */
       
     7 
       
     8 /**
       
     9  * Implements hook_schema().
       
    10  */
       
    11 function openid_schema() {
       
    12   $schema['openid_association'] = array(
       
    13     'description' => 'Stores temporary shared key association information for OpenID authentication.',
       
    14     'fields' => array(
       
    15       'idp_endpoint_uri' => array(
       
    16         'type' => 'varchar',
       
    17         'length' => 255,
       
    18         'not null' => TRUE,
       
    19         'description' => 'Primary Key: URI of the OpenID Provider endpoint.',
       
    20       ),
       
    21       'assoc_handle' => array(
       
    22         'type' => 'varchar',
       
    23         'length' => 255,
       
    24         'not null' => TRUE,
       
    25         'description' => 'Used to refer to this association in subsequent messages.',
       
    26       ),
       
    27       'assoc_type' => array(
       
    28         'type' => 'varchar',
       
    29         'length' => 32,
       
    30         'description' => 'The signature algorithm used: one of HMAC-SHA1 or HMAC-SHA256.',
       
    31       ),
       
    32       'session_type' => array(
       
    33         'type' => 'varchar',
       
    34         'length' => 32,
       
    35         'description' => 'Valid association session types: "no-encryption", "DH-SHA1", and "DH-SHA256".',
       
    36       ),
       
    37       'mac_key' => array(
       
    38         'type' => 'varchar',
       
    39         'length' => 255,
       
    40         'description' => 'The MAC key (shared secret) for this association.',
       
    41       ),
       
    42       'created' => array(
       
    43         'type' => 'int',
       
    44         'not null' => TRUE,
       
    45         'default' => 0,
       
    46         'description' => 'UNIX timestamp for when the association was created.',
       
    47       ),
       
    48       'expires_in' => array(
       
    49         'type' => 'int',
       
    50         'not null' => TRUE,
       
    51         'default' => 0,
       
    52         'description' => 'The lifetime, in seconds, of this association.',
       
    53       ),
       
    54     ),
       
    55     'primary key' => array('idp_endpoint_uri'),
       
    56     'unique keys' => array(
       
    57       'assoc_handle' => array('assoc_handle'),
       
    58     ),
       
    59   );
       
    60 
       
    61   $schema['openid_nonce'] = array(
       
    62     'description' => 'Stores received openid.response_nonce per OpenID endpoint URL to prevent replay attacks.',
       
    63     'fields' => array(
       
    64       'idp_endpoint_uri' => array(
       
    65         'type' => 'varchar',
       
    66         'length' => 255,
       
    67         'description' => 'URI of the OpenID Provider endpoint.',
       
    68       ),
       
    69       'nonce' => array(
       
    70         'type' => 'varchar',
       
    71         'length' => 255,
       
    72         'description' => 'The value of openid.response_nonce.',
       
    73       ),
       
    74       'expires' => array(
       
    75         'type' => 'int',
       
    76         'not null' => TRUE,
       
    77         'default' => 0,
       
    78         'description' => 'A Unix timestamp indicating when the entry should expire.',
       
    79       ),
       
    80     ),
       
    81     'indexes' => array(
       
    82       'nonce' => array('nonce'),
       
    83       'expires' => array('expires'),
       
    84     ),
       
    85   );
       
    86 
       
    87   return $schema;
       
    88 }
       
    89 
       
    90 /**
       
    91  * Implements hook_requirements().
       
    92  */
       
    93 function openid_requirements($phase) {
       
    94   $requirements = array();
       
    95 
       
    96   if ($phase == 'runtime') {
       
    97     // Check for the PHP BC Math library.
       
    98     if (!function_exists('bcadd') && !function_exists('gmp_add')) {
       
    99       $requirements['openid_math'] = array(
       
   100         'value' => t('Not installed'),
       
   101         'severity' => REQUIREMENT_ERROR,
       
   102         'description' => t('OpenID suggests the use of either the <a href="@gmp">GMP Math</a> (recommended for performance) or <a href="@bc">BC Math</a> libraries to enable OpenID associations.', array('@gmp' => 'http://php.net/manual/en/book.gmp.php', '@bc' => 'http://www.php.net/manual/en/book.bc.php')),
       
   103       );
       
   104     }
       
   105     elseif (!function_exists('gmp_add')) {
       
   106       $requirements['openid_math'] = array(
       
   107         'value' => t('Not optimized'),
       
   108         'severity' => REQUIREMENT_WARNING,
       
   109         'description' => t('OpenID suggests the use of the GMP Math library for PHP for optimal performance. Check the <a href="@url">GMP Math Library documentation</a> for installation instructions.', array('@url' => 'http://www.php.net/manual/en/book.gmp.php')),
       
   110       );
       
   111     }
       
   112     else {
       
   113       $requirements['openid_math'] = array(
       
   114         'value' => t('Installed'),
       
   115         'severity' => REQUIREMENT_OK,
       
   116       );
       
   117     }
       
   118     $requirements['openid_math']['title'] = t('OpenID Math library');
       
   119   }
       
   120 
       
   121   return $requirements;
       
   122 }
       
   123 
       
   124 /**
       
   125  * @addtogroup updates-6.x-to-7.x
       
   126  * @{
       
   127  */
       
   128 
       
   129 /**
       
   130  * Add a table to store nonces.
       
   131  */
       
   132 function openid_update_6000() {
       
   133   $schema['openid_nonce'] = array(
       
   134     'description' => 'Stores received openid.response_nonce per OpenID endpoint URL to prevent replay attacks.',
       
   135     'fields' => array(
       
   136       'idp_endpoint_uri' => array(
       
   137         'type' => 'varchar',
       
   138         'length' => 255,
       
   139         'description' => 'URI of the OpenID Provider endpoint.',
       
   140       ),
       
   141       'nonce' => array(
       
   142         'type' => 'varchar',
       
   143         'length' => 255,
       
   144         'description' => 'The value of openid.response_nonce'
       
   145         ),
       
   146       'expires' => array(
       
   147         'type' => 'int',
       
   148         'not null' => TRUE,
       
   149         'default' => 0,
       
   150         'description' => 'A Unix timestamp indicating when the entry should expire.',
       
   151         ),
       
   152       ),
       
   153     'indexes' => array(
       
   154       'nonce' => array('nonce'),
       
   155       'expires' => array('expires'),
       
   156     ),
       
   157   );
       
   158 
       
   159   db_create_table('openid_nonce', $schema['openid_nonce']);
       
   160 }
       
   161 
       
   162 /**
       
   163  * @} End of "addtogroup updates-6.x-to-7.x".
       
   164  */
       
   165 
       
   166 /**
       
   167  * @addtogroup updates-7.x-extra
       
   168  * @{
       
   169  */
       
   170 
       
   171 /**
       
   172  * Bind associations to their providers.
       
   173  */
       
   174 function openid_update_7000() {
       
   175   db_drop_table('openid_association');
       
   176 
       
   177   $schema = array(
       
   178     'description' => 'Stores temporary shared key association information for OpenID authentication.',
       
   179     'fields' => array(
       
   180       'idp_endpoint_uri' => array(
       
   181         'type' => 'varchar',
       
   182         'length' => 255,
       
   183         'not null' => TRUE,
       
   184         'description' => 'Primary Key: URI of the OpenID Provider endpoint.',
       
   185       ),
       
   186       'assoc_handle' => array(
       
   187         'type' => 'varchar',
       
   188         'length' => 255,
       
   189         'not null' => TRUE,
       
   190         'description' => 'Used to refer to this association in subsequent messages.',
       
   191       ),
       
   192       'assoc_type' => array(
       
   193         'type' => 'varchar',
       
   194         'length' => 32,
       
   195         'description' => 'The signature algorithm used: one of HMAC-SHA1 or HMAC-SHA256.',
       
   196       ),
       
   197       'session_type' => array(
       
   198         'type' => 'varchar',
       
   199         'length' => 32,
       
   200         'description' => 'Valid association session types: "no-encryption", "DH-SHA1", and "DH-SHA256".',
       
   201       ),
       
   202       'mac_key' => array(
       
   203         'type' => 'varchar',
       
   204         'length' => 255,
       
   205         'description' => 'The MAC key (shared secret) for this association.',
       
   206       ),
       
   207       'created' => array(
       
   208         'type' => 'int',
       
   209         'not null' => TRUE,
       
   210         'default' => 0,
       
   211         'description' => 'UNIX timestamp for when the association was created.',
       
   212       ),
       
   213       'expires_in' => array(
       
   214         'type' => 'int',
       
   215         'not null' => TRUE,
       
   216         'default' => 0,
       
   217         'description' => 'The lifetime, in seconds, of this association.',
       
   218       ),
       
   219     ),
       
   220     'primary key' => array('idp_endpoint_uri'),
       
   221     'unique keys' => array(
       
   222       'assoc_handle' => array('assoc_handle'),
       
   223     ),
       
   224   );
       
   225   db_create_table('openid_association', $schema);
       
   226 }
       
   227 
       
   228 /**
       
   229  * @} End of "addtogroup updates-7.x-extra".
       
   230  */