PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/lib/Auth/OpenID/SQLiteStore.php

https://bitbucket.org/yoander/mtrack
PHP | 71 lines | 35 code | 13 blank | 23 comment | 0 complexity | 4855020fe55f579df8f99247977bd1d1 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  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. }
  58. ?>