annotate reloadarticle.php @ 12:7917bd536187 draft

Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
author Ivo Smits <Ivo@UCIS.nl>
date Wed, 12 Jun 2013 22:22:07 +0200
parents 005339a1b2ce
children cccd73f72bf6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
1 #!/usr/bin/php
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
2 <?php
8
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
3 /* Copyright 2010 Ivo Smits <Ivo@UCIS.nl>. All rights reserved.
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
4 Redistribution and use in source and binary forms, with or without modification, are
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
5 permitted provided that the following conditions are met:
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
6
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
7 1. Redistributions of source code must retain the above copyright notice, this list of
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
8 conditions and the following disclaimer.
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
9
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
10 2. Redistributions in binary form must reproduce the above copyright notice, this list
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
11 of conditions and the following disclaimer in the documentation and/or other materials
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
12 provided with the distribution.
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
13
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
14 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
15 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
18 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
19 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
20 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
21 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
22 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
23
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
24 The views and conclusions contained in the software and documentation are those of the
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
25 authors and should not be interpreted as representing official policies, either expressed
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
26 or implied, of Ivo Smits.*/
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
27
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
28 chdir(__DIR__);
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
29 require_once './common.php';
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
30
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
31 if (count($_SERVER['argv']) < 2) die('Not enough arguments (usage: [server] [messageid])');
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
32 $messageid = $_SERVER['argv'][2];
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
33 $db->update('DELETE FROM `messages` WHERE `messageid` = ?', $messageid);
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
34 $socket = stream_socket_client($_SERVER['argv'][1]);
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
35 if ($socket === FALSE) die("Could not connect to peer\n");
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
36 $line = nntp_readline($socket);
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
37 $code = strtok($line, " \t");
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
38 if ($code == 200) {
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
39 } else if ($code == 201) {
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
40 } else die("Error code $code\n");
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
41 nntp_writeline($socket, 'ARTICLE <'.$messageid.'>');
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
42 $line = nntp_readline($socket);
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
43 $code = strtok($line, " \t");
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
44 if ($code != 220) die("Error code $code\n");
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
45 strtok(" \t"); //article number
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
46 $lines = nntp_readlines($socket);
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
47 nntp_article_store($lines);
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
48
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
49 function writelog($line) {
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
50 print($line."\n");
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
51 }