# HG changeset patch # User Ivo Smits # Date 1302556647 -7200 # Node ID 61fac319ca3e127912512c9ea9861ee29b44e4d5 # Parent d7ab68b71c747fcab4e0fcc00cd4120244b7227f Update Path and Xref header fields while fetching messages, added database schema export diff -r d7ab68b71c74 -r 61fac319ca3e database.mysql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/database.mysql Mon Apr 11 23:17:27 2011 +0200 @@ -0,0 +1,83 @@ +-- phpMyAdmin SQL Dump +-- version 3.3.9.2deb1 +-- http://www.phpmyadmin.net +-- +-- Machine: localhost +-- Genereertijd: 11 Apr 2011 om 23:15 +-- Serverversie: 5.0.51 +-- PHP-Versie: 5.3.3-7 + +SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; + +-- +-- Database: `ivo_pnewss` +-- + +-- -------------------------------------------------------- + +-- +-- Tabelstructuur voor tabel `groupmessages` +-- + +CREATE TABLE IF NOT EXISTS `groupmessages` ( + `group` int(10) unsigned NOT NULL, + `message` int(10) unsigned NOT NULL, + `number` int(10) unsigned NOT NULL auto_increment, + PRIMARY KEY (`group`,`number`), + KEY `message` (`message`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- -------------------------------------------------------- + +-- +-- Tabelstructuur voor tabel `groups` +-- + +CREATE TABLE IF NOT EXISTS `groups` ( + `id` int(10) unsigned NOT NULL auto_increment, + `name` varchar(255) character set ascii NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- -------------------------------------------------------- + +-- +-- Tabelstructuur voor tabel `messages` +-- + +CREATE TABLE IF NOT EXISTS `messages` ( + `id` int(10) unsigned NOT NULL auto_increment, + `messageid` varchar(255) character set ascii NOT NULL, + `header` text character set ascii NOT NULL, + `body` text character set ascii NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `messageid` (`messageid`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- -------------------------------------------------------- + +-- +-- Tabelstructuur voor tabel `peergroups` +-- + +CREATE TABLE IF NOT EXISTS `peergroups` ( + `peer` int(10) unsigned NOT NULL, + `group` int(10) unsigned NOT NULL, + `low` int(10) unsigned default NULL, + `high` int(10) unsigned default NULL, + PRIMARY KEY (`peer`,`group`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- -------------------------------------------------------- + +-- +-- Tabelstructuur voor tabel `peers` +-- + +CREATE TABLE IF NOT EXISTS `peers` ( + `id` int(10) unsigned NOT NULL auto_increment, + `address` varchar(255) collate utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + diff -r d7ab68b71c74 -r 61fac319ca3e fetchnews.php --- a/fetchnews.php Mon Apr 11 22:44:47 2011 +0200 +++ b/fetchnews.php Mon Apr 11 23:17:27 2011 +0200 @@ -46,6 +46,8 @@ if ($code != 221) die("Error code $code from $peer[address]\n"); strtok(" \t"); //article number $lines = nntp_readlines($socket); + nntp_removeheader(&$lines, 'Xref'); + nntp_updatepath(&$lines, 'pNewss.Core.UCIS.nl'); $header = implode("\r\n", $lines); nntp_writeline($socket, 'BODY '.$i); @@ -67,6 +69,25 @@ fclose($socket); } +function nntp_removeheader(&$lines, $header) { + $header = strtoupper($header).':'; + $hlen = strlen($header); + foreach ($lines as $key => $line) if (strtoupper(substr($line, 0, $hlen)) == $header) unset($lines[$key]); +} +function nntp_updatepath(&$lines, $value) { + $header = strtoupper('Path').':'; + $hlen = strlen($header); + $found = FALSE; + foreach ($lines as &$line) if (strtoupper(substr($line, 0, $hlen)) == $header) { + $parts = explode(': ', $line, 2); + $parts[1] = $value.'!'.$parts[1]; + $line = implode(': ', $parts); + $found = TRUE; + break; + } + if (!$found) $lines[] = 'Path: '.$value; +} + function nntp_readline($socket) { $line = rtrim(fgets($socket, 512), "\r\n"); print('R: '.$line."\n");