[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Librefm-commits] [1490] convert more gnukebox stuff to adodb
From: |
Clint Adams |
Subject: |
[Librefm-commits] [1490] convert more gnukebox stuff to adodb |
Date: |
Mon, 11 May 2009 21:14:27 +0000 |
Revision: 1490
http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1490
Author: clint
Date: 2009-05-11 21:14:27 +0000 (Mon, 11 May 2009)
Log Message:
-----------
convert more gnukebox stuff to adodb
Modified Paths:
--------------
trunk/gnukebox/auth-utils.php
trunk/gnukebox/nowplaying/1.2/index.php
trunk/gnukebox/submissions/1.1/handshake.php
trunk/gnukebox/submissions/1.2/handshake.php
trunk/gnukebox/submissions/1.2/index.php
Modified: trunk/gnukebox/auth-utils.php
===================================================================
--- trunk/gnukebox/auth-utils.php 2009-05-11 21:11:40 UTC (rev 1489)
+++ trunk/gnukebox/auth-utils.php 2009-05-11 21:14:27 UTC (rev 1490)
@@ -19,40 +19,39 @@
*/
-require_once('database.php');
+require_once('database2.php');
function check_web_auth($username, $token, $timestamp, $api_key, $sk) {
// Validates authentication using a web services token
- global $mdb2;
+ global $adodb;
// Using the valid_api_key function from nixtape/2.0/index.php would be
appropriate here
if (strlen($api_key) != 32) {
return false;
}
- $result = $mdb2->query('SELECT username FROM Auth WHERE '
+ $result = $adodb->GetOne('SELECT username FROM Auth WHERE '
//. 'expires > ' . time() . ' AND ' // session keys have an
infinite lifetime
- . 'sk = ' . $mdb2->quote($sk, 'text')
+ . 'sk = ' . $adodb->qstr($sk)
);
- if (PEAR::isError($result) || !$result->numRows()) {
+ if (!$result) {
// TODO: Log failures somewhere
return false;
}
- return $result->fetchOne(0) == $username;
+ return $result == $username;
}
function check_standard_auth($username, $token, $timestamp) {
// Validates authentication using a standard authentication token
- global $mdb2;
+ global $adodb;
- $result = $mdb2->query("SELECT password FROM Users WHERE username =" .
$mdb2->quote($username, 'text'));
- if (PEAR::isError($result) || !$result->numRows()) {
+ $pass = $adodb->GetOne("SELECT password FROM Users WHERE username =" .
$adodb->qstr($username));
+ if (!$pass) {
// TODO: Log failures somewhere
return false;
}
- $pass = $result->fetchOne(0);
$check_token = md5($pass . $timestamp);
return $check_token == $token;
Modified: trunk/gnukebox/nowplaying/1.2/index.php
===================================================================
--- trunk/gnukebox/nowplaying/1.2/index.php 2009-05-11 21:11:40 UTC (rev
1489)
+++ trunk/gnukebox/nowplaying/1.2/index.php 2009-05-11 21:14:27 UTC (rev
1490)
@@ -18,7 +18,7 @@
*/
-require_once('../../database.php');
+require_once('../../database2.php');
require_once('../../scrobble-utils.php');
if(!isset($_POST['s']) || !isset($_POST['a']) || !isset($_POST['t'])) {
@@ -30,16 +30,16 @@
$session_id = $_POST['s'];
-$username = $mdb2->quote(usernameFromSID($session_id), "text");
-$MQsess = $mdb2->quote($session_id, "text");
+$username = $adodb->qstr(usernameFromSID($session_id));
+$MQsess = $adodb->qstr($session_id);
-$artist = $mdb2->quote($_POST['a'], "text");
+$artist = $adodb->qstr($_POST['a']);
if(isset($_POST['b'])) {
- $album = $mdb2->quote($_POST['b'], "text");
+ $album = $adodb->qstr($_POST['b']);
} else {
$album = 'NULL';
}
-$track = $mdb2->quote($_POST['t'], "text");
+$track = $adodb->qstr($_POST['t']);
if(isset($_POST['l']) && is_numeric($_POST['l'])) {
$expires = time() + (int) $_POST['l'];
} else {
@@ -49,7 +49,7 @@
$mb = validateMBID($_POST['m']);
if($mb) {
- $mbid = $mdb2->quote($mb, "text");
+ $mbid = $adodb->qstr($mb, "text");
} else {
$mbid = 'NULL';
}
@@ -61,12 +61,12 @@
getTrackCreateIfNew($artist, $album, $track, $mbid);
//Expire old tracks
-$mdb2->exec("DELETE FROM Now_Playing WHERE expires < " . time());
+$adodb->Execute("DELETE FROM Now_Playing WHERE expires < " . time());
//Delete this user's last playing song (if any)
-$mdb2->exec("DELETE FROM Now_Playing WHERE sessionid = " . ($MQsess));
+$adodb->Execute("DELETE FROM Now_Playing WHERE sessionid = " . ($MQsess));
-$mdb2->exec("INSERT INTO Now_Playing (sessionid, artist, album, track,
expires, mbid) VALUES ("
+$adodb->Execute("INSERT INTO Now_Playing (sessionid, artist, album, track,
expires, mbid) VALUES ("
. $MQsess . ", "
. $artist . ", "
. $album . ", "
Modified: trunk/gnukebox/submissions/1.1/handshake.php
===================================================================
--- trunk/gnukebox/submissions/1.1/handshake.php 2009-05-11 21:11:40 UTC
(rev 1489)
+++ trunk/gnukebox/submissions/1.1/handshake.php 2009-05-11 21:14:27 UTC
(rev 1490)
@@ -42,20 +42,20 @@
$timestamp = time();
-$res = $mdb2->query("SELECT password FROM Users WHERE username = ".
$mdb2->quote($username, "text"));
+$res = $adodb->GetOne("SELECT password FROM Users WHERE username = ".
$adodb->qstr($username));
if(PEAR::isError($res)) {
die("FAILED " . $res->getMessage() . "\r\n");
}
if(!$res->numRows()) {
die("BADUSER\r\n");
}
-$password = $res->fetchOne(0);
+$password = $res;
$session_id = md5($password . $timestamp);
-$res = $mdb2->exec("INSERT INTO Scrobble_Sessions(username, sessionid, client,
expires) VALUES ("
- . $mdb2->quote($username, "text") . ","
- . $mdb2->quote($session_id, "text") . ","
- . $mdb2->quote($client, "text") . ","
- . $mdb2->quote(time() + 86400) . ")");
+$res = $adodb->Execute("INSERT INTO Scrobble_Sessions(username, sessionid,
client, expires) VALUES ("
+ . $adodb->qstr($username, "text") . ","
+ . $adodb->qstr($session_id, "text") . ","
+ . $adodb->qstr($client, "text") . ","
+ . $adodb->qstr(time() + 86400) . ")");
if(PEAR::isError($res)) {
die("FAILED " . $res->getMessage() . "\r\n");
Modified: trunk/gnukebox/submissions/1.2/handshake.php
===================================================================
--- trunk/gnukebox/submissions/1.2/handshake.php 2009-05-11 21:11:40 UTC
(rev 1489)
+++ trunk/gnukebox/submissions/1.2/handshake.php 2009-05-11 21:14:27 UTC
(rev 1490)
@@ -56,12 +56,12 @@
$session_id = md5($auth_token . time());
$sql = "INSERT INTO Scrobble_Sessions(username, sessionid, client, expires)
VALUES ("
- . $mdb2->quote($username, "text") . ","
- . $mdb2->quote($session_id, "text") . ","
- . $mdb2->quote($client, "text") . ","
- . $mdb2->quote(time() + 86400) . ")";
+ . $adodb->qstr($username) . ","
+ . $adodb->qstr($session_id) . ","
+ . $adodb->qstr($client) . ","
+ . (time() + 86400) . ")";
-$res = $mdb2->exec($sql);
+$res = $adodb->Execute($sql);
if(PEAR::isError($res)) {
$msg = $res->getMessage();
Modified: trunk/gnukebox/submissions/1.2/index.php
===================================================================
--- trunk/gnukebox/submissions/1.2/index.php 2009-05-11 21:11:40 UTC (rev
1489)
+++ trunk/gnukebox/submissions/1.2/index.php 2009-05-11 21:14:27 UTC (rev
1490)
@@ -35,7 +35,7 @@
$session_id = $_POST['s'];
-$username = $mdb2->quote(usernameFromSID($session_id), "text");
+$username = $adodb->qstr(usernameFromSID($session_id));
$rowvalues = array();
$actualcount = 0;
@@ -43,7 +43,7 @@
switch (mb_detect_encoding($_POST['a'][$i])) {
case "ASCII":
case "UTF-8":
- $artist = $mdb2->quote($_POST['a'][$i], "text");
+ $artist = $adodb->qstr($_POST['a'][$i]);
break;
default:
die("FAILED Bad encoding in artist submission $i\r\n");
@@ -52,7 +52,7 @@
switch (mb_detect_encoding($_POST['b'][$i])) {
case "ASCII":
case "UTF-8":
- $album = $mdb2->quote($_POST['b'][$i], "text");
+ $album = $adodb->qstr($_POST['b'][$i]);
break;
default:
die("FAILED Bad encoding in album submission $i\r\n");
@@ -72,7 +72,7 @@
switch (mb_detect_encoding($_POST['t'][$i])) {
case "ASCII":
case "UTF-8":
- $track = $mdb2->quote($_POST['t'][$i], "text");
+ $track = $adodb->qstr($_POST['t'][$i]);
break;
default:
die("FAILED Bad encoding in title submission $i\r\n");
@@ -88,23 +88,23 @@
$mb = validateMBID($_POST['m'][$i]);
if($mb) {
- $mbid = $mdb2->quote($mb, "text");
+ $mbid = $adodb->qstr($mb);
} else {
$mbid = 'NULL';
}
if(isset($_POST['o'][$i])) {
- $source = $mdb2->quote($_POST['o'][$i], "text");
+ $source = $adodb->qstr($_POST['o'][$i]);
} else {
$source = 'NULL';
}
if(!empty($_POST['r'][$i])) {
- $rating = $mdb2->quote($_POST['r'][$i], "text");
+ $rating = $adodb->qstr($_POST['r'][$i]);
} else {
- $rating = $mdb2->quote("0", "text"); // use the fake rating
code 0 for now
+ $rating = $adodb->qstr("0"); // use the fake rating code 0 for
now
}
if(isset($_POST['l'][$i])) {
- $length = $mdb2->quote($_POST['l'][$i], "integer");
+ $length = (int)($_POST['l'][$i]);
} else {
$length = 'NULL';
}
@@ -141,33 +141,35 @@
if(($i+1) == count($_POST['a']) && $actualcount>0) {
- $mdb2->exec("BEGIN");
+ $adodb->StartTrans();
for($j = 0; $j < $actualcount; $j++) {
// Scrobble!
$sql = "INSERT INTO Scrobbles (username, artist, album, track,
time, mbid, source, rating, length, stid) VALUES " . $rowvalues[$j];
- $res =& $mdb2->exec($sql);
+ $res =& $adodb->Execute($sql);
if(PEAR::isError($res)) {
$msg = $res->getMessage() . " - " . $res->getUserInfo();
- $mdb2->exec("ROLLBACK");
+ $adodb->FailTrans();
+ $adodb->CompleteTrans();
reportError($msg, $sql);
die("FAILED " . $msg . "\nError has been reported to site
administrators.\r\n");
}
}
- $mdb2->exec("COMMIT");
+ $adodb->CompleteTrans();
if(PEAR::isError($res)) {
$msg = $res->getMessage() . " - " . $res->getUserInfo();
- $mdb2->exec("ROLLBACK");
+ $adodb->FailTrans();
+ $adodb->CompleteTrans();
reportError($msg, $sql);
die("FAILED " . $msg . "\nError has been reported to site
administrators.\r\n");
}
// Destroy now_playing since it is almost certainly obsolescent
- $mdb2->exec("DELETE FROM Now_Playing WHERE sessionid = " .
$mdb2->quote($session_id, "text"));
+ $adodb->Execute("DELETE FROM Now_Playing WHERE sessionid = " .
$adodb->qstr($session_id));
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Librefm-commits] [1490] convert more gnukebox stuff to adodb,
Clint Adams <=