16 require_once 
'MDB2.php';
 
   21 require_once 
'Auth/OpenID/Interface.php';
 
   26 require_once 
'Auth/OpenID.php';
 
   31 require_once 
'Auth/OpenID/Nonce.php';
 
   66                                   $associations_table = null,
 
   69         $this->associations_table_name = 
"oid_associations";
 
   70         $this->nonces_table_name = 
"oid_nonces";
 
   74         if (!is_object($connection) ||
 
   75             !is_subclass_of($connection, 
'mdb2_driver_common')) {
 
   76             trigger_error(
"Auth_OpenID_MDB2Store expected PEAR connection " .
 
   77                           "object (got ".get_class($connection).
")",
 
   82         $this->connection = $connection;
 
   88         if (
PEAR::isError($this->connection->loadModule(
'Extended'))) {
 
   89             trigger_error(
"Unable to load MDB2_Extended module", E_USER_ERROR);
 
   93         if ($associations_table) {
 
   94             $this->associations_table_name = $associations_table;
 
   98             $this->nonces_table_name = $nonces_table;
 
  101         $this->max_nonce_age = 6 * 60 * 60;
 
  107                                   sprintf(
"SELECT * FROM %s LIMIT 0",
 
  124         if (!$this->
tableExists($this->nonces_table_name)) {
 
  125             switch ($this->connection->phptype) {
 
  130                     $r = $this->connection->exec(
 
  131                         sprintf(
"CREATE TABLE %s (\n".
 
  132                                 "  server_url VARCHAR(2047) NOT NULL DEFAULT '',\n".
 
  133                                 "  timestamp INTEGER NOT NULL,\n".
 
  134                                 "  salt CHAR(40) NOT NULL,\n".
 
  135                                 "  UNIQUE (server_url(255), timestamp, salt)\n".
 
  137                                 $this->nonces_table_name));
 
  144                         $this->connection->loadModule(
'Manager'))) {
 
  148                         "server_url" => array(
 
  153                         "timestamp" => array(
 
  167                             "server_url" => 
true,
 
  173                     $r = $this->connection->createTable($this->nonces_table_name,
 
  179                     $r = $this->connection->createConstraint(
 
  180                         $this->nonces_table_name,
 
  181                         $this->nonces_table_name . 
"_constraint",
 
  194         if (!$this->
tableExists($this->associations_table_name)) {
 
  195             switch ($this->connection->phptype) {
 
  200                     $r = $this->connection->exec(
 
  201                         sprintf(
"CREATE TABLE %s(\n".
 
  202                                 "  server_url VARCHAR(2047) NOT NULL DEFAULT '',\n".
 
  203                                 "  handle VARCHAR(255) NOT NULL,\n".
 
  204                                 "  secret BLOB NOT NULL,\n".
 
  205                                 "  issued INTEGER NOT NULL,\n".
 
  206                                 "  lifetime INTEGER NOT NULL,\n".
 
  207                                 "  assoc_type VARCHAR(64) NOT NULL,\n".
 
  208                                 "  PRIMARY KEY (server_url(255), handle)\n".
 
  210                             $this->associations_table_name));
 
  217                         $this->connection->loadModule(
'Manager'))) {
 
  221                         "server_url" => array(
 
  244                         "assoc_type" => array(
 
  252                             "server_url" => 
true,
 
  257                     $r = $this->connection->createTable(
 
  258                         $this->associations_table_name,
 
  273             "server_url" => array(
 
  274                 "value" => $server_url,
 
  278                 "value" => $association->handle,
 
  282                 "value" => $association->secret,
 
  286                 "value" => $association->issued
 
  289                 "value" => $association->lifetime
 
  291             "assoc_type" => array(
 
  292                 "value" => $association->assoc_type
 
  297                                   $this->associations_table_name,
 
  306         return $this->connection->exec(
 
  307             sprintf(
"DELETE FROM %s WHERE timestamp < %d",
 
  308                     $this->nonces_table_name, $v));
 
  313         return $this->connection->exec(
 
  314             sprintf(
"DELETE FROM %s WHERE issued + lifetime < %d",
 
  315                     $this->associations_table_name, time()));
 
  329         if ($handle !== null) {
 
  330             $sql = sprintf(
"SELECT handle, secret, issued, lifetime, assoc_type " .
 
  331                            "FROM %s WHERE server_url = ? AND handle = ?",
 
  332                            $this->associations_table_name);
 
  333             $params = array($server_url, $handle);
 
  335             $sql = sprintf(
"SELECT handle, secret, issued, lifetime, assoc_type " .
 
  336                            "FROM %s WHERE server_url = ? ORDER BY issued DESC",
 
  337                            $this->associations_table_name);
 
  338             $params = array($server_url);
 
  341         $assoc = $this->connection->getRow($sql, $types, $params);
 
  351                                                        $assoc[
'assoc_type']);
 
  352             fclose($assoc[
'secret']);
 
  359         $r = $this->connection->execParam(
 
  360             sprintf(
"DELETE FROM %s WHERE server_url = ? AND handle = ?",
 
  361                     $this->associations_table_name),
 
  362             array($server_url, $handle));
 
  374         if (abs(
$timestamp - time()) > $Auth_OpenID_SKEW ) {
 
  383         if (!empty($server_url)) {
 
  384             $fields[
"server_url"] = $server_url;
 
  387         $r = $this->connection->autoExecute(
 
  388             $this->nonces_table_name,
 
  404         $this->connection->query(sprintf(
"DELETE FROM %s",
 
  405                                          $this->associations_table_name));
 
  407         $this->connection->query(sprintf(
"DELETE FROM %s",
 
  408                                          $this->nonces_table_name));