final move of files
[web.mtrack] / Auth / OpenID / MySQLStore.php
1 <?php
2
3 /**
4  * A MySQL store.
5  *
6  * @package OpenID
7  */
8
9 /**
10  * Require the base class file.
11  */
12 require_once "Auth/OpenID/SQLStore.php";
13
14 /**
15  * An SQL store that uses MySQL as its backend.
16  *
17  * @package OpenID
18  */
19 class Auth_OpenID_MySQLStore extends Auth_OpenID_SQLStore {
20     /**
21      * @access private
22      */
23     function setSQL()
24     {
25         $this->sql['nonce_table'] =
26             "CREATE TABLE %s (\n".
27             "  server_url VARCHAR(2047) NOT NULL,\n".
28             "  timestamp INTEGER NOT NULL,\n".
29             "  salt CHAR(40) NOT NULL,\n".
30             "  UNIQUE (server_url(255), timestamp, salt)\n".
31             ") ENGINE=InnoDB";
32
33         $this->sql['assoc_table'] =
34             "CREATE TABLE %s (\n".
35             "  server_url BLOB NOT NULL,\n".
36             "  handle VARCHAR(255) NOT NULL,\n".
37             "  secret BLOB NOT NULL,\n".
38             "  issued INTEGER NOT NULL,\n".
39             "  lifetime INTEGER NOT NULL,\n".
40             "  assoc_type VARCHAR(64) NOT NULL,\n".
41             "  PRIMARY KEY (server_url(255), handle)\n".
42             ") ENGINE=InnoDB";
43
44         $this->sql['set_assoc'] =
45             "REPLACE INTO %s (server_url, handle, secret, issued,\n".
46             "  lifetime, assoc_type) VALUES (?, ?, !, ?, ?, ?)";
47
48         $this->sql['get_assocs'] =
49             "SELECT handle, secret, issued, lifetime, assoc_type FROM %s ".
50             "WHERE server_url = ?";
51
52         $this->sql['get_assoc'] =
53             "SELECT handle, secret, issued, lifetime, assoc_type FROM %s ".
54             "WHERE server_url = ? AND handle = ?";
55
56         $this->sql['remove_assoc'] =
57             "DELETE FROM %s WHERE server_url = ? AND handle = ?";
58
59         $this->sql['add_nonce'] =
60             "INSERT INTO %s (server_url, timestamp, salt) VALUES (?, ?, ?)";
61
62         $this->sql['clean_nonce'] =
63             "DELETE FROM %s WHERE timestamp < ?";
64
65         $this->sql['clean_assoc'] =
66             "DELETE FROM %s WHERE issued + lifetime < ?";
67     }
68
69     /**
70      * @access private
71      */
72     function blobEncode($blob)
73     {
74         return "0x" . bin2hex($blob);
75     }
76 }
77
78 ?>