diff server.php @ 14:372f4e195986 draft default tip

Added article blacklist function, switch to binary-safe latin1 character set for database
author Ivo Smits <Ivo@UCIS.nl>
date Thu, 17 Jul 2014 23:24:17 +0200
parents cccd73f72bf6
children
line wrap: on
line diff
--- a/server.php	Thu Jul 10 22:26:45 2014 +0200
+++ b/server.php	Thu Jul 17 23:24:17 2014 +0200
@@ -103,25 +103,21 @@
 				$currentgroup = $group;
 				$groupmessages = $db->evalRow('SELECT MIN(`number`), MAX(`number`), COUNT(`number`) FROM `groupmessages` WHERE `group` = ?', $group['id']);
 				nntp_writeline(STDOUT, '211 '.intval($groupmessages[2]).' '.intval($groupmessages[0]).' '.intval($groupmessages[1]).' '.$group['name']);
-				if ($groupmessages[0] === NULL) {
-					$currentarticle = NULL;
-				} else {
-					$currentarticle = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` = ?', array($group['id'], $groupmessages[0]));
-					if ($currentarticle === FALSE) $currentarticle = NULL;
-				}
+				$currentarticle = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `message` IS NOT NULL ORDER BY `number` ASC LIMIT 1', $group['id']);
+				if ($currentarticle === FALSE) $currentarticle = NULL;
 				if ($cmd == 'LISTGROUP') {
 					$range = strtok(" \t");
 					if ($range !== FALSE) {
 						$parts = explode('-', $range);
 						if (count($parts) == 1 || !strlen($parts[1])) {
-							$query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `number` >= ?';
+							$query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `number` >= ? AND `message` IS NOT NULL';
 							$queryargs = array($group['id'], $parts[0]);
 						} else {
-							$query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `number` BETWEEN ? AND ?';
+							$query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `number` BETWEEN ? AND ? AND `message` IS NOT NULL';
 							$queryargs = array($group['id'], $parts[0], $parts[1]);
 						}
 					} else {
-						$query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ?';
+						$query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `message` IS NOT NULL';
 						$queryargs = array($group['id']);
 					}
 					foreach ($db->evalColumn($query, $queryargs) as $number) nntp_writeline_data(STDOUT, $number);
@@ -162,8 +158,8 @@
 				break;
 			}
 			switch ($cmd) {
-				case 'LAST': $query = 'SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` < ? ORDER BY `number` DESC LIMIT 1'; break;
-				case 'NEXT': $query = 'SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` > ? ORDER BY `number` ASC LIMIT 1'; break;
+				case 'LAST': $query = 'SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` < ? AND `message` IS NOT NULL ORDER BY `number` DESC LIMIT 1'; break;
+				case 'NEXT': $query = 'SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` > ? AND `message` IS NOT NULL ORDER BY `number` ASC LIMIT 1'; break;
 				default: throw new Exception('Internal error');
 			}
 			$article = $db->evalRowAssoc($query, array($currentarticle['group'], $currentarticle['number']));
@@ -276,7 +272,7 @@
 			nntp_writeline(STDOUT, '412 no newsgroup has been selected');
 			return NULL;
 		}
-		$article = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` = ?', array($currentgroup['id'], $article));
+		$article = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` = ? AND `message` IS NOT NULL', array($currentgroup['id'], $article));
 		if ($article === FALSE) {
 			nntp_writeline(STDOUT, '423 no such article number in this group');
 			return NULL;