Mercurial > hg > pnewss
comparison fetchnews.php @ 9:ae0c67d72670
Bugfix in server POST code, add support for client side IHAVE and fall back to STAT-before-POST
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Tue, 12 Apr 2011 14:54:26 +0200 |
parents | 005339a1b2ce |
children | e0807e0b1a67 |
comparison
equal
deleted
inserted
replaced
8:005339a1b2ce | 9:ae0c67d72670 |
---|---|
91 } else { | 91 } else { |
92 $articles = $db->evalAllAssoc('SELECT * FROM `messages` WHERE `id` > ? LIMIT 10', $peer['lastposted']); | 92 $articles = $db->evalAllAssoc('SELECT * FROM `messages` WHERE `id` > ? LIMIT 10', $peer['lastposted']); |
93 } | 93 } |
94 if (!count($articles)) break; | 94 if (!count($articles)) break; |
95 foreach ($articles as $article) { | 95 foreach ($articles as $article) { |
96 nntp_writeline($socket, 'POST'); | 96 $dopost = FALSE; |
97 $line = nntp_readline($socket); | 97 if ($peer['post'] == 2) { |
98 $code = strtok($line, " \t"); | 98 nntp_writeline($socket, 'IHAVE <'.$article['messageid'].'>'); |
99 if ($code != 340) die("Error code $code from $peer[address]\n"); | 99 $line = nntp_readline($socket); |
100 foreach (explode("\r\n", $article['header']) as $line) { | 100 $code = strtok($line, " \t"); |
101 $parts = explode(': ', $line, 2); | 101 if ($code == 335) $dopost = TRUE; |
102 switch (strtoupper($parts[0])) { | 102 elseif ($code != 435) $peer['post'] = 1; |
103 case 'PATH': case 'FROM': case 'NEWSGROUPS': case 'SUBJECT': case 'DATE': case 'ORGANIZATION': | 103 } |
104 case 'LINES': case 'MESSAGE-ID': case 'MIME-VERSION': case 'CONTENT-TYPE': case 'CONTENT-TRANSFER-ENCODING': | 104 if ($peer['post'] != 2) { |
105 case 'USER-AGENT': case 'REFERENCES': case 'REPLY-TO': case 'SENDER': case 'FOLLOWUP-TO': | 105 nntp_writeline($socket, 'STAT <'.$article['messageid'].'>'); |
106 case 'EXPIRES': case 'CONTROL': case 'DISTRIBUTION': case 'KEYWORDS': case 'SUMMARY': | 106 $line = nntp_readline($socket); |
107 case 'IN-REPLY-TO': | 107 $code = strtok($line, " \t"); |
108 break; | 108 if ($code == 430) $dopost = TRUE; |
109 case 'NNTP-POSTING-HOST': case 'X-TRACE': case 'XREF': case 'X-COMPLAINTS-TO': | 109 elseif ($code != 223) die("Error code $code from $peer[address]\n"); |
110 case 'NNTP-POSTING-DATE': | 110 if ($dopost) { |
111 $line = NULL; | 111 nntp_writeline($socket, 'POST'); |
112 break; | 112 $line = nntp_readline($socket); |
113 default: | 113 $code = strtok($line, " \t"); |
114 print("Sending unknown header $parts[0]\n"); | 114 if ($code != 340) die("Error code $code from $peer[address]\n"); |
115 } | 115 } |
116 if ($line !== NULL) nntp_writeline_data($socket, $line); | |
117 } | 116 } |
118 nntp_writeline($socket, ''); | 117 if ($dopost) { |
119 foreach (explode("\r\n", $article['body']) as $line) nntp_writeline_data($socket, $line); | 118 foreach (explode("\r\n", $article['header']) as $line) nntp_writeline_data($socket, $line); |
120 nntp_writeline($socket, '.'); | 119 nntp_writeline($socket, ''); |
121 $line = nntp_readline($socket); | 120 foreach (explode("\r\n", $article['body']) as $line) nntp_writeline_data($socket, $line); |
122 $code = strtok($line, " \t"); | 121 nntp_writeline($socket, '.'); |
123 if ($code != 240) print("Article $article[messageid] was not accepted ($code)\n"); | 122 $line = nntp_readline($socket); |
123 $code = strtok($line, " \t"); | |
124 if ($code != 240 && $code != 235) print("Article $article[messageid] was not accepted ($code)\n"); | |
125 } | |
124 if ($article['id'] > $peer['lastposted']) $peer['lastposted'] = $article['id']; | 126 if ($article['id'] > $peer['lastposted']) $peer['lastposted'] = $article['id']; |
125 } | 127 } |
126 $db->update('UPDATE `peers` SET `lastposted` = ? WHERE `id` = ?', array($peer['lastposted'], $peer['id'])); | 128 $db->update('UPDATE `peers` SET `lastposted` = ? WHERE `id` = ?', array($peer['lastposted'], $peer['id'])); |
127 } | 129 } |
128 nntp_writeline($socket, 'QUIT'); | 130 nntp_writeline($socket, 'QUIT'); |
131 nntp_readline($socket); | |
129 fclose($socket); | 132 fclose($socket); |
130 } | 133 } |
131 | 134 |
132 function writelog($line) { | 135 function writelog($line) { |
133 print($line."\n"); | 136 print($line."\n"); |