Mercurial > hg > pnewss
annotate server.php @ 2:40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Tue, 12 Apr 2011 00:29:41 +0200 |
parents | d7ab68b71c74 |
children | 0dcdb73cbcbf |
rev | line source |
---|---|
0 | 1 #!/usr/bin/php |
2 <?php | |
2
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
3 chdir(__DIR__); |
0 | 4 require_once './pdo.php'; |
5 require_once './config.php'; | |
6 | |
7 $logfile = fopen('./server.log', 'w'); | |
8 $currentgroup = NULL; | |
9 $currentarticle = NULL; | |
10 | |
11 function exception_handler($exception) { | |
12 nntp_writeline(STDOUT, ''); | |
13 nntp_writeline(STDOUT, '590 Exception: '.$exception->getMessage()); | |
14 die(); | |
15 } | |
16 function error_handler($errno, $errstr, $errfile, $errline) { | |
17 nntp_writeline(STDOUT, ''); | |
18 nntp_writeline(STDOUT, '590 Error in file '.$errfile.' line '.$errline.' error '.$errno.' '.$errstr); | |
19 die(); | |
20 } | |
21 set_exception_handler('exception_handler'); | |
22 set_error_handler("error_handler"); | |
23 | |
24 nntp_writeline(STDOUT, '200 pNewss ready'); | |
25 while (TRUE) { | |
26 $line = nntp_readline(STDIN); | |
2
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
27 if ($line === FALSE || $line === NULL) break; |
0 | 28 $cmd = strtok($line, " \t"); |
29 switch (strtoupper($cmd)) { | |
30 case 'LIST': | |
31 nntp_writeline(STDOUT, '215 List of groups follows'); | |
32 foreach ($db->evalAllAssoc('SELECT * FROM `groups`') as $group) { | |
33 $groupmessages = $db->evalRow('SELECT MIN(`number`), MAX(`number`) FROM `groupmessages` WHERE `group` = ?', $group['id']); | |
34 nntp_writeline(STDOUT, $group['name'].' '.intval($groupmessages[1]).' '.intval($groupmessages[0]).' n'); | |
35 } | |
36 nntp_writeline(STDOUT, '.'); | |
37 break; | |
38 case 'GROUP': | |
39 $groupname = strtok(" \t"); | |
40 $group = $db->evalRowAssoc('SELECT * FROM `groups` WHERE `name` = ?', $groupname); | |
41 if ($group === FALSE) { | |
42 nntp_writeline(STDOUT, '411 No such group '.$groupname); | |
43 } else { | |
44 $currentgroup = $group; | |
45 $groupmessages = $db->evalRow('SELECT MIN(`number`), MAX(`number`), COUNT(`number`) FROM `groupmessages` WHERE `group` = ?', $group['id']); | |
46 nntp_writeline(STDOUT, '211 '.intval($groupmessages[2]).' '.intval($groupmessages[0]).' '.intval($groupmessages[1]).' '.$group['name']); | |
47 if ($groupmessages[0] === NULL) { | |
48 $currentarticle = NULL; | |
49 } else { | |
50 $currentarticle = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` = ?', array($group['id'], $groupmessages[0])); | |
51 if ($currentarticle === FALSE) $currentarticle = NULL; | |
52 } | |
53 } | |
54 break; | |
55 case 'STAT': | |
56 $article = nntp_get_article(strtok(" \t")); | |
57 if ($article === NULL) break; | |
58 nntp_writeline(STDOUT, '223 '.$article['messagenumber'].' <'.$article['messageid'].'> stat'); | |
59 break; | |
60 case 'HEAD': | |
61 $article = nntp_get_article(strtok(" \t")); | |
62 if ($article === NULL) break; | |
63 nntp_writeline(STDOUT, '221 '.$article['messagenumber'].' <'.$article['messageid'].'> head'); | |
64 foreach (explode("\r\n", $article['header']) as $line) nntp_writeline(STDOUT, $line); | |
65 nntp_writeline(STDOUT, '.'); | |
66 break; | |
67 case 'BODY': | |
68 $article = nntp_get_article(strtok(" \t")); | |
69 if ($article === NULL) break; | |
70 nntp_writeline(STDOUT, '222 '.$article['messagenumber'].' <'.$article['messageid'].'> body'); | |
71 foreach (explode("\r\n", $article['body']) as $line) nntp_writeline(STDOUT, $line); | |
72 nntp_writeline(STDOUT, '.'); | |
73 break; | |
74 case 'ARTICLE': | |
75 $article = nntp_get_article(strtok(" \t")); | |
76 if ($article === NULL) break; | |
77 nntp_writeline(STDOUT, '220 '.$article['messagenumber'].' <'.$article['messageid'].'> article'); | |
78 foreach (explode("\r\n", $article['header']) as $line) nntp_writeline(STDOUT, $line); | |
79 nntp_writeline(STDOUT, ''); | |
80 foreach (explode("\r\n", $article['body']) as $line) nntp_writeline(STDOUT, $line); | |
81 nntp_writeline(STDOUT, '.'); | |
82 break; | |
83 case 'LAST': | |
84 if ($currentarticle === NULL) { | |
85 nntp_writeline(STDOUT, '420 no current article has been selected'); | |
86 break; | |
87 } | |
88 $article = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` < ? ORDER BY `number` DESC LIMIT 1', array($currentarticle['group'], $currentarticle['number'])); | |
89 if ($article === FALSE) { | |
90 nntp_writeline(STDOUT, '422 no previous article in this group'); | |
91 } else { | |
92 $articlea = $db->evalRowAssoc('SELECT * FROM `messages` WHERE `id` = ?', $article['message']); | |
93 if ($articlea === FALSE) { | |
94 nntp_writeline(STDOUT, '430 no such article found'); | |
95 return NULL; | |
96 } | |
97 $currentarticle = $article; | |
98 nntp_writeline(STDOUT, '223 '.$article['number'].' <'.$articlea['messageid'].'> ok'); | |
99 } | |
100 break; | |
101 case 'NEXT': | |
102 if ($currentarticle === NULL) { | |
103 nntp_writeline(STDOUT, '420 no current article has been selected'); | |
104 break; | |
105 } | |
106 $article = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` > ? ORDER BY `number` ASC LIMIT 1', array($currentarticle['group'], $currentarticle['number'])); | |
107 if ($article === FALSE) { | |
108 nntp_writeline(STDOUT, '422 no previous article in this group'); | |
109 } else { | |
110 $articlea = $db->evalRowAssoc('SELECT * FROM `messages` WHERE `id` = ?', $article['message']); | |
111 if ($articlea === FALSE) { | |
112 nntp_writeline(STDOUT, '430 no such article found'); | |
113 return NULL; | |
114 } | |
115 $currentarticle = $article; | |
116 nntp_writeline(STDOUT, '223 '.$article['number'].' <'.$articlea['messageid'].'> ok'); | |
117 } | |
118 break; | |
2
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
119 case 'POST': |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
120 nntp_writeline(STDOUT, '340 Ok, recommended message-ID <'.md5(time().rand()).'@pNews.Core.UCIS.nl>'); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
121 $lines = nntp_readlines(STDIN); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
122 $header = array(); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
123 $headers = array(); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
124 while (count($lines)) { |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
125 $line = array_shift($lines); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
126 if (!strlen($line)) break; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
127 $parts = explode(': ', $line, 2); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
128 $headers[strtoupper($parts[0])] = $parts[1]; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
129 switch (strtoupper($parts[0])) { |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
130 case 'PATH': |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
131 $line = $parts[0].': pNews.Core.UCIS.nl!'.$parts[1]; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
132 break; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
133 case 'FROM': case 'NEWSGROUPS': case 'SUBJECT': case 'DATE': case 'ORGANIZATION': |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
134 case 'LINES': case 'MESSAGE-ID': case 'MIME-VERSION': case 'CONTENT-TYPE': case 'CONTENT-TRANSFER-ENCODING': |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
135 case 'USER-AGENT': case 'REFERENCES': case 'REPLY-TO': case 'SENDER': case 'FOLLOWUP-TO': |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
136 case 'EXPIRES': case 'CONTROL': case 'DISTRIBUTION': case 'KEYWORDS': case 'SUMMARY': |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
137 case 'IN-REPLY-TO': |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
138 break; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
139 case 'NNTP-POSTING-HOST': case 'X-TRACE': case 'XREF': case 'X-COMPLAINTS-TO': |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
140 case 'NNTP-POSTING-DATE': |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
141 $line = NULL; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
142 break; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
143 default: |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
144 writelog("Received unknown header $parts[0]"); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
145 } |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
146 if ($line !== NULL) $header[] = $line; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
147 } |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
148 if (!isset($headers['NEWSGROUPS'])) { |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
149 nntp_writeline(STDOUT, '441 Missing required Newsgroups: header'); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
150 break; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
151 } |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
152 if (!isset($headers['MESSAGE-ID'])) { |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
153 $headers['MESSAGE-ID'] = '<'.md5(time().rand()).'@pNews.Core.UCIS.nl>'; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
154 $header[] = 'Message-ID: '.$headers['MESSAGE-ID']; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
155 } |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
156 if (!isset($headers['PATH'])) { |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
157 $headers['PATH'] = 'pNews.Core.UCIS.nl'; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
158 $header[] = 'Path: '.$headers['PATH']; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
159 } |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
160 $msgid = $headers['MESSAGE-ID']; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
161 if (strlen($msgid) <= 2 || $msgid[0] != '<' || $msgid[strlen($msgid)-1] != '>') { |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
162 nntp_writeline(STDOUT, '441 435 Bad Message-ID'); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
163 break; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
164 } |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
165 $msgid = substr($msgid, 1, -1); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
166 $article = $db->evalRowAssoc('SELECT * FROM `messages` WHERE `messageid` = ?', $msgid); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
167 if ($article !== FALSE) { |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
168 nntp_writeline(STDOUT, '441 435 Duplicate'); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
169 return NULL; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
170 } |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
171 $id = $db->insert('INSERT INTO `messages` (`messageid`, `header`, `body`) VALUES (?, ?, ?)', array($msgid, implode("\r\n", $header), implode("\r\n", $lines))); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
172 foreach (explode(',', $headers['NEWSGROUPS']) as $groupname) { |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
173 $group = $db->evalRowAssoc('SELECT * FROM `groups` WHERE `name` = ?', $groupname); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
174 if ($group === FALSE) continue; |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
175 $db->insert('INSERT INTO `groupmessages` (`group`, `message`) VALUES (?, ?)', array($group['id'], $id)); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
176 } |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
177 nntp_writeline(STDOUT, '240 Article received <'.$msgid.'>'); |
40e545510a57
Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents:
0
diff
changeset
|
178 break; |
0 | 179 case 'QUIT': |
180 nntp_writeline(STDOUT, '205 .'); | |
181 return; | |
182 case 'XOVER': | |
183 case 'MODE': | |
184 case 'CAPABILITIES': | |
185 nntp_writeline(STDOUT, '500 Command not implemented'); | |
186 break; | |
187 default: | |
188 nntp_writeline(STDOUT, '500 Command not understood'); | |
189 break; | |
190 } | |
191 } | |
192 | |
193 function nntp_get_article($article) { | |
194 global $currentgroup, $currentarticle, $db; | |
195 if ($article === FALSE) { | |
196 if ($currentarticle === NULL) { | |
197 nntp_writeline(STDOUT, '420 no current article has been selected'); | |
198 return NULL; | |
199 } | |
200 $messagenumber = $currentarticle['number']; | |
201 $article = $db->evalRowAssoc('SELECT * FROM `messages` WHERE `id` = ?', $currentarticle['message']); | |
202 if ($article === FALSE) { | |
203 nntp_writeline(STDOUT, '430 no such article found'); | |
204 return NULL; | |
205 } | |
206 } elseif (strlen($article) > 2 && $article[0] == '<' && $article[strlen($article)-1] == '>') { | |
207 $messagenumber = 0; | |
208 $article = substr($article, 1, -1); | |
209 $article = $db->evalRowAssoc('SELECT * FROM `messages` WHERE `messageid` = ?', $article); | |
210 if ($article === FALSE) { | |
211 nntp_writeline(STDOUT, '430 no such article found'); | |
212 return NULL; | |
213 } | |
214 } elseif (is_numeric($article)) { | |
215 if ($currentgroup === NULL) { | |
216 nntp_writeline(STDOUT, '412 no newsgroup has been selected'); | |
217 return NULL; | |
218 } | |
219 $article = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` = ?', array($currentgroup['id'], $article)); | |
220 if ($article === FALSE) { | |
221 nntp_writeline(STDOUT, '423 no such article number in this group'); | |
222 return NULL; | |
223 } | |
224 $currentarticle = $article; | |
225 $messagenumber = $article['number']; | |
226 $article = $db->evalRowAssoc('SELECT * FROM `messages` WHERE `id` = ?', $article['message']); | |
227 if ($article === FALSE) { | |
228 nntp_writeline(STDOUT, '430 no such article found'); | |
229 return NULL; | |
230 } | |
231 } else { | |
232 nntp_writeline(STDOUT, '500 Error in arguments'); | |
233 } | |
234 $article['messagenumber'] = $messagenumber; | |
235 return $article; | |
236 } | |
237 | |
238 function writelog($line) { | |
239 global $logfile; | |
240 fwrite($logfile, $line."\n"); | |
241 } | |
242 function nntp_readline($socket) { | |
243 global $logfile; | |
244 $line = fgets($socket, 512); | |
245 if ($line === FALSE || $line === NULL) return $line; | |
246 $line = rtrim($line, "\r\n"); | |
247 fwrite($logfile, 'R: '.$line."\n"); | |
248 return $line; | |
249 } | |
250 function nntp_writeline($socket, $line) { | |
251 global $logfile; | |
252 fwrite($logfile, 'W: '.$line."\n"); | |
253 fwrite($socket, $line."\r\n"); | |
254 } | |
255 function nntp_readlines($socket) { | |
256 $line = nntp_readline($socket); | |
257 $lines = array(); | |
258 while ($line != '.' && $line !== FALSE && $line !== FALSE) { | |
259 $lines[] = $line; | |
260 $line = nntp_readline($socket); | |
261 } | |
262 if ($line != '.') die("Unexpected end of message header\n"); | |
263 return $lines; | |
264 } |