PostgreSQLStore.php

Go to the documentation of this file.
00001 <?php
00002 
00012 require_once "Auth/OpenID/SQLStore.php";
00013 
00019 class Auth_OpenID_PostgreSQLStore extends Auth_OpenID_SQLStore {
00023     function setSQL()
00024     {
00025         $this->sql['nonce_table'] =
00026             "CREATE TABLE %s (server_url VARCHAR(2047) NOT NULL, ".
00027                              "timestamp INTEGER NOT NULL, ".
00028                              "salt CHAR(40) NOT NULL, ".
00029                 "UNIQUE (server_url, timestamp, salt))";
00030 
00031         $this->sql['assoc_table'] =
00032             "CREATE TABLE %s (server_url VARCHAR(2047) NOT NULL, ". 
00033                              "handle VARCHAR(255) NOT NULL, ".
00034                              "secret BYTEA NOT NULL, ".
00035                              "issued INTEGER NOT NULL, ".
00036                              "lifetime INTEGER NOT NULL, ".
00037                              "assoc_type VARCHAR(64) NOT NULL, ".
00038             "PRIMARY KEY (server_url, handle), ".
00039             "CONSTRAINT secret_length_constraint CHECK ".
00040             "(LENGTH(secret) <= 128))";
00041 
00042         $this->sql['set_assoc'] =
00043             array(
00044                   'insert_assoc' => "INSERT INTO %s (server_url, handle, ".
00045                   "secret, issued, lifetime, assoc_type) VALUES ".
00046                   "(?, ?, '!', ?, ?, ?)",
00047                   'update_assoc' => "UPDATE %s SET secret = '!', issued = ?, ".
00048                   "lifetime = ?, assoc_type = ? WHERE server_url = ? AND ".
00049                   "handle = ?"
00050                   );
00051 
00052         $this->sql['get_assocs'] =
00053             "SELECT handle, secret, issued, lifetime, assoc_type FROM %s ".
00054             "WHERE server_url = ?";
00055 
00056         $this->sql['get_assoc'] =
00057             "SELECT handle, secret, issued, lifetime, assoc_type FROM %s ".
00058             "WHERE server_url = ? AND handle = ?";
00059 
00060         $this->sql['remove_assoc'] =
00061             "DELETE FROM %s WHERE server_url = ? AND handle = ?";
00062 
00063         $this->sql['add_nonce'] =
00064                   "INSERT INTO %s (server_url, timestamp, salt) VALUES ".
00065                   "(?, ?, ?)"
00066                   ;
00067 
00068         $this->sql['clean_nonce'] =
00069             "DELETE FROM %s WHERE timestamp < ?";
00070 
00071         $this->sql['clean_assoc'] =
00072             "DELETE FROM %s WHERE issued + lifetime < ?";
00073     }
00074 
00078     function _set_assoc($server_url, $handle, $secret, $issued, $lifetime,
00079                         $assoc_type)
00080     {
00081         $result = $this->_get_assoc($server_url, $handle);
00082         if ($result) {
00083             // Update the table since this associations already exists.
00084             $this->connection->query($this->sql['set_assoc']['update_assoc'],
00085                                      array($secret, $issued, $lifetime,
00086                                            $assoc_type, $server_url, $handle));
00087         } else {
00088             // Insert a new record because this association wasn't
00089             // found.
00090             $this->connection->query($this->sql['set_assoc']['insert_assoc'],
00091                                      array($server_url, $handle, $secret,
00092                                            $issued, $lifetime, $assoc_type));
00093         }
00094     }
00095 
00099     function blobEncode($blob)
00100     {
00101         return $this->_octify($blob);
00102     }
00103 
00107     function blobDecode($blob)
00108     {
00109         return $this->_unoctify($blob);
00110     }
00111 }
00112 
00113 ?>

Generated on Thu Feb 19 15:02:21 2009 for OXID eShop CE by  doxygen 1.5.5