SQLiteStore.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * An SQLite store.
  4. *
  5. * @package OpenID
  6. */
  7. /**
  8. * Require the base class file.
  9. */
  10. require_once "Auth/OpenID/SQLStore.php";
  11. /**
  12. * An SQL store that uses SQLite as its backend.
  13. *
  14. * @package OpenID
  15. */
  16. class Auth_OpenID_SQLiteStore extends Auth_OpenID_SQLStore {
  17. function setSQL()
  18. {
  19. $this->sql['nonce_table'] =
  20. "CREATE TABLE %s (server_url VARCHAR(2047), timestamp INTEGER, ".
  21. "salt CHAR(40), UNIQUE (server_url, timestamp, salt))";
  22. $this->sql['assoc_table'] =
  23. "CREATE TABLE %s (server_url VARCHAR(2047), handle VARCHAR(255), ".
  24. "secret BLOB(128), issued INTEGER, lifetime INTEGER, ".
  25. "assoc_type VARCHAR(64), PRIMARY KEY (server_url, handle))";
  26. $this->sql['set_assoc'] =
  27. "INSERT OR REPLACE INTO %s VALUES (?, ?, ?, ?, ?, ?)";
  28. $this->sql['get_assocs'] =
  29. "SELECT handle, secret, issued, lifetime, assoc_type FROM %s ".
  30. "WHERE server_url = ?";
  31. $this->sql['get_assoc'] =
  32. "SELECT handle, secret, issued, lifetime, assoc_type FROM %s ".
  33. "WHERE server_url = ? AND handle = ?";
  34. $this->sql['remove_assoc'] =
  35. "DELETE FROM %s WHERE server_url = ? AND handle = ?";
  36. $this->sql['add_nonce'] =
  37. "INSERT INTO %s (server_url, timestamp, salt) VALUES (?, ?, ?)";
  38. $this->sql['clean_nonce'] =
  39. "DELETE FROM %s WHERE timestamp < ?";
  40. $this->sql['clean_assoc'] =
  41. "DELETE FROM %s WHERE issued + lifetime < ?";
  42. }
  43. /**
  44. * @access private
  45. */
  46. function _add_nonce($server_url, $timestamp, $salt)
  47. {
  48. // PECL SQLite extensions 1.0.3 and older (1.0.3 is the
  49. // current release at the time of this writing) have a broken
  50. // sqlite_escape_string function that breaks when passed the
  51. // empty string. Prefixing all strings with one character
  52. // keeps them unique and avoids this bug. The nonce table is
  53. // write-only, so we don't have to worry about updating other
  54. // functions with this same bad hack.
  55. return parent::_add_nonce('x' . $server_url, $timestamp, $salt);
  56. }
  57. }