📄 sqlstore.php
字号:
} function blobDecode($blob) { return $blob; } function blobEncode($str) { return $str; } function createTables() { $this->connection->autoCommit(true); $n = $this->create_nonce_table(); $a = $this->create_assoc_table(); $this->connection->autoCommit(false); if ($n && $a) { return true; } else { return false; } } function create_nonce_table() { if (!$this->tableExists($this->nonces_table_name)) { $r = $this->connection->query($this->sql['nonce_table']); return $this->resultToBool($r); } return true; } function create_assoc_table() { if (!$this->tableExists($this->associations_table_name)) { $r = $this->connection->query($this->sql['assoc_table']); return $this->resultToBool($r); } return true; } /** * @access private */ function _set_assoc($server_url, $handle, $secret, $issued, $lifetime, $assoc_type) { return $this->connection->query($this->sql['set_assoc'], array( $server_url, $handle, $secret, $issued, $lifetime, $assoc_type)); } function storeAssociation($server_url, $association) { if ($this->resultToBool($this->_set_assoc( $server_url, $association->handle, $this->blobEncode( $association->secret), $association->issued, $association->lifetime, $association->assoc_type ))) { $this->connection->commit(); } else { $this->connection->rollback(); } } /** * @access private */ function _get_assoc($server_url, $handle) { $result = $this->connection->getRow($this->sql['get_assoc'], array($server_url, $handle)); if ($this->isError($result)) { return null; } else { return $result; } } /** * @access private */ function _get_assocs($server_url) { $result = $this->connection->getAll($this->sql['get_assocs'], array($server_url)); if ($this->isError($result)) { return array(); } else { return $result; } } function removeAssociation($server_url, $handle) { if ($this->_get_assoc($server_url, $handle) == null) { return false; } if ($this->resultToBool($this->connection->query( $this->sql['remove_assoc'], array($server_url, $handle)))) { $this->connection->commit(); } else { $this->connection->rollback(); } return true; } function getAssociation($server_url, $handle = null) { if ($handle !== null) { $assoc = $this->_get_assoc($server_url, $handle); $assocs = array(); if ($assoc) { $assocs[] = $assoc; } } else { $assocs = $this->_get_assocs($server_url); } if (!$assocs || (count($assocs) == 0)) { return null; } else { $associations = array(); foreach ($assocs as $assoc_row) { $assoc = new Auth_OpenID_Association($assoc_row['handle'], $assoc_row['secret'], $assoc_row['issued'], $assoc_row['lifetime'], $assoc_row['assoc_type']); $assoc->secret = $this->blobDecode($assoc->secret); if ($assoc->getExpiresIn() == 0) { $this->removeAssociation($server_url, $assoc->handle); } else { $associations[] = array($assoc->issued, $assoc); } } if ($associations) { $issued = array(); $assocs = array(); foreach ($associations as $key => $assoc) { $issued[$key] = $assoc[0]; $assocs[$key] = $assoc[1]; } array_multisort($issued, SORT_DESC, $assocs, SORT_DESC, $associations); // return the most recently issued one. list($issued, $assoc) = $associations[0]; return $assoc; } else { return null; } } } /** * @access private */ function _add_nonce($server_url, $timestamp, $salt) { $sql = $this->sql['add_nonce']; $result = $this->connection->query($sql, array($server_url, $timestamp, $salt)); if ($this->isError($result)) { $this->connection->rollback(); } else { $this->connection->commit(); } return $this->resultToBool($result); } function useNonce($server_url, $timestamp, $salt) { global $Auth_OpenID_SKEW; if ( abs($timestamp - mktime()) > $Auth_OpenID_SKEW ) { return False; } return $this->_add_nonce($server_url, $timestamp, $salt); } /** * "Octifies" a binary string by returning a string with escaped * octal bytes. This is used for preparing binary data for * PostgreSQL BYTEA fields. * * @access private */ function _octify($str) { $result = ""; for ($i = 0; $i < Auth_OpenID::bytes($str); $i++) { $ch = substr($str, $i, 1); if ($ch == "\\") { $result .= "\\\\\\\\"; } else if (ord($ch) == 0) { $result .= "\\\\000"; } else { $result .= "\\" . strval(decoct(ord($ch))); } } return $result; } /** * "Unoctifies" octal-escaped data from PostgreSQL and returns the * resulting ASCII (possibly binary) string. * * @access private */ function _unoctify($str) { $result = ""; $i = 0; while ($i < strlen($str)) { $char = $str[$i]; if ($char == "\\") { // Look to see if the next char is a backslash and // append it. if ($str[$i + 1] != "\\") { $octal_digits = substr($str, $i + 1, 3); $dec = octdec($octal_digits); $char = chr($dec); $i += 4; } else { $char = "\\"; $i += 2; } } else { $i += 1; } $result .= $char; } return $result; } function cleanupNonces() { global $Auth_OpenID_SKEW; $v = time() - $Auth_OpenID_SKEW; $this->connection->query($this->sql['clean_nonce'], array($v)); $num = $this->connection->affectedRows(); $this->connection->commit(); return $num; } function cleanupAssociations() { $this->connection->query($this->sql['clean_assoc'], array(time())); $num = $this->connection->affectedRows(); $this->connection->commit(); return $num; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -