comparison 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
comparison
equal deleted inserted replaced
13:cccd73f72bf6 14:372f4e195986
101 nntp_writeline(STDOUT, '411 No such group '.$groupname); 101 nntp_writeline(STDOUT, '411 No such group '.$groupname);
102 } else { 102 } else {
103 $currentgroup = $group; 103 $currentgroup = $group;
104 $groupmessages = $db->evalRow('SELECT MIN(`number`), MAX(`number`), COUNT(`number`) FROM `groupmessages` WHERE `group` = ?', $group['id']); 104 $groupmessages = $db->evalRow('SELECT MIN(`number`), MAX(`number`), COUNT(`number`) FROM `groupmessages` WHERE `group` = ?', $group['id']);
105 nntp_writeline(STDOUT, '211 '.intval($groupmessages[2]).' '.intval($groupmessages[0]).' '.intval($groupmessages[1]).' '.$group['name']); 105 nntp_writeline(STDOUT, '211 '.intval($groupmessages[2]).' '.intval($groupmessages[0]).' '.intval($groupmessages[1]).' '.$group['name']);
106 if ($groupmessages[0] === NULL) { 106 $currentarticle = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `message` IS NOT NULL ORDER BY `number` ASC LIMIT 1', $group['id']);
107 $currentarticle = NULL; 107 if ($currentarticle === FALSE) $currentarticle = NULL;
108 } else {
109 $currentarticle = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` = ?', array($group['id'], $groupmessages[0]));
110 if ($currentarticle === FALSE) $currentarticle = NULL;
111 }
112 if ($cmd == 'LISTGROUP') { 108 if ($cmd == 'LISTGROUP') {
113 $range = strtok(" \t"); 109 $range = strtok(" \t");
114 if ($range !== FALSE) { 110 if ($range !== FALSE) {
115 $parts = explode('-', $range); 111 $parts = explode('-', $range);
116 if (count($parts) == 1 || !strlen($parts[1])) { 112 if (count($parts) == 1 || !strlen($parts[1])) {
117 $query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `number` >= ?'; 113 $query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `number` >= ? AND `message` IS NOT NULL';
118 $queryargs = array($group['id'], $parts[0]); 114 $queryargs = array($group['id'], $parts[0]);
119 } else { 115 } else {
120 $query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `number` BETWEEN ? AND ?'; 116 $query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `number` BETWEEN ? AND ? AND `message` IS NOT NULL';
121 $queryargs = array($group['id'], $parts[0], $parts[1]); 117 $queryargs = array($group['id'], $parts[0], $parts[1]);
122 } 118 }
123 } else { 119 } else {
124 $query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ?'; 120 $query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `message` IS NOT NULL';
125 $queryargs = array($group['id']); 121 $queryargs = array($group['id']);
126 } 122 }
127 foreach ($db->evalColumn($query, $queryargs) as $number) nntp_writeline_data(STDOUT, $number); 123 foreach ($db->evalColumn($query, $queryargs) as $number) nntp_writeline_data(STDOUT, $number);
128 nntp_writeline(STDOUT, '.'); 124 nntp_writeline(STDOUT, '.');
129 } 125 }
160 if ($currentarticle === NULL) { 156 if ($currentarticle === NULL) {
161 nntp_writeline(STDOUT, '420 no current article has been selected'); 157 nntp_writeline(STDOUT, '420 no current article has been selected');
162 break; 158 break;
163 } 159 }
164 switch ($cmd) { 160 switch ($cmd) {
165 case 'LAST': $query = 'SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` < ? ORDER BY `number` DESC LIMIT 1'; break; 161 case 'LAST': $query = 'SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` < ? AND `message` IS NOT NULL ORDER BY `number` DESC LIMIT 1'; break;
166 case 'NEXT': $query = 'SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` > ? ORDER BY `number` ASC LIMIT 1'; break; 162 case 'NEXT': $query = 'SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` > ? AND `message` IS NOT NULL ORDER BY `number` ASC LIMIT 1'; break;
167 default: throw new Exception('Internal error'); 163 default: throw new Exception('Internal error');
168 } 164 }
169 $article = $db->evalRowAssoc($query, array($currentarticle['group'], $currentarticle['number'])); 165 $article = $db->evalRowAssoc($query, array($currentarticle['group'], $currentarticle['number']));
170 if ($article === FALSE) { 166 if ($article === FALSE) {
171 nntp_writeline(STDOUT, '422 no previous article in this group'); 167 nntp_writeline(STDOUT, '422 no previous article in this group');
274 } elseif (is_numeric($article)) { 270 } elseif (is_numeric($article)) {
275 if ($currentgroup === NULL) { 271 if ($currentgroup === NULL) {
276 nntp_writeline(STDOUT, '412 no newsgroup has been selected'); 272 nntp_writeline(STDOUT, '412 no newsgroup has been selected');
277 return NULL; 273 return NULL;
278 } 274 }
279 $article = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` = ?', array($currentgroup['id'], $article)); 275 $article = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` = ? AND `message` IS NOT NULL', array($currentgroup['id'], $article));
280 if ($article === FALSE) { 276 if ($article === FALSE) {
281 nntp_writeline(STDOUT, '423 no such article number in this group'); 277 nntp_writeline(STDOUT, '423 no such article number in this group');
282 return NULL; 278 return NULL;
283 } 279 }
284 $currentarticle = $article; 280 $currentarticle = $article;