* put in a sample vcard.
[citadel.git] / ctdlphp / ctdlprotocol.php
1 <?PHP
2 // $Id$
3 // 
4 // Implements various Citadel server commands.
5 //
6 // Copyright (c) 2003 by Art Cancro <ajc@uncensored.citadel.org>
7 // One program is released under the terms of the GNU General Public License.
8 include "config_ctdlclient.php";
9
10
11 define("FMT_CITADEL", 0);
12 define("FMT_FIXED", 1);
13 define("FMT_RFC822", 4);
14
15 //--------------------------------------------------------------------------------
16 //   internal functions for server communication
17 //--------------------------------------------------------------------------------
18 //
19 // serv_gets() -- generic function to read one line of text from the server
20 //
21 function serv_gets($readblock=FALSE) {
22         global $clientsocket;
23
24         $buf = fgets($clientsocket, 4096);              // Read line
25         $buf = substr($buf, 0, (strlen($buf)-1) );      // strip trailing LF
26         if (CITADEL_DEBUG_CITPROTO == 1) {
27                 if (!$readblock) printf ("<div class='ctdldbgRead'>\n");
28                 printf($buf);
29                 if (!$readblock) printf ("\n</div>\n");
30                 else printf ("<br>\n");
31         }
32         return $buf;
33 }
34
35 //
36 // serv_get_n() -- generic function to read a binary blob from the server
37 //
38 function serv_get_n($nBytes) {
39         global $clientsocket;
40
41         if (CITADEL_DEBUG_CITPROTO == 1) {
42                 printf ("<div class='ctdldbgRead'>\n");
43                 printf("reading ".$nBytes." bytes from server\n");
44                 printf ("</div>\n");
45         }
46         $buf = fread($clientsocket, $nBytes);
47         if (CITADEL_DEBUG_CITPROTO == 1) {
48                 if (!$buf) printf ("<div class='ctdldbgRead'>\n");
49                 printf($buf);
50                 if (!$buf) printf ("</div>\n");
51                 else printf ("<br>\n");
52         }
53         return $buf;
54 }
55
56 //
57 // serv_puts() -- generic function to write one line of text to the server
58 //
59 function serv_puts($buf) {
60         global $clientsocket;
61         
62         fwrite($clientsocket, $buf . "\n", (strlen($buf)+1) );
63         fflush($clientsocket);
64         if (CITADEL_DEBUG_CITPROTO == 1)
65                 printf ("<div class='ctdldbgWrite'>".$buf."</div>\n");
66 }
67
68
69 function read_array() {
70         $nLines = 0;
71         if (CITADEL_DEBUG_CITPROTO == 1)
72             printf ("<div class='ctdldbgRead'>\n");
73         $buf = serv_gets(TRUE);
74         $ret = array();
75         while (strcasecmp($buf, "000")){
76                 array_push($ret, $buf);
77                 $buf = serv_gets(TRUE);
78                 $nLines++;
79         }
80         if (CITADEL_DEBUG_CITPROTO == 1){
81                 echo "read ".$nLines." lines from the server.\n";
82                 printf ("</div>\n");
83         }
84         return $ret;
85 }
86
87 function read_binary() {
88         $nLines = 0;
89         if (CITADEL_DEBUG_CITPROTO == 1)
90             printf ("<div class='ctdldbgRead'>\n");
91         $buf = serv_gets(TRUE);
92         
93         if (CITADEL_DEBUG_CITPROTO == 1){
94                 echo "status line from the server\n";
95         }
96
97         $statusline = explode(" ", $buf);
98         
99         if ($statusline[0] == 600)
100         {
101                 $buf = serv_get_n($statusline[1]);
102                 
103         }
104         if (CITADEL_DEBUG_CITPROTO == 1)
105             printf ("</div>\n");
106         return array($statusline, $buf);
107 }
108
109
110
111 // 
112 // text_to_server() -- sends a block of text to the server.  Assumes that
113 //                     the server just sent back a SEND_LISTING response code
114 //                     and is now expecting a 000-terminated series of lines.
115 //                     Set 'convert_to_html' to TRUE to convert the block of
116 //                     text to HTML along the way.
117 //
118 function text_to_server($thetext, $convert_to_html) {
119
120         // HTML mode
121         if ($convert_to_html) {
122
123                 // Strip CR's; we only want the LF's
124                 $thetext = trim($thetext, "\r");
125
126                 // Replace hard line breaks with <BR>'s
127                 $thetext = str_replace("\n", "<BR>\n", $thetext);
128
129         }
130
131         // Either mode ... send it to the server now
132         $one_line = strtok($thetext, "\n");
133         while ($one_line !== FALSE) {
134                 $one_line = trim($one_line, "\n\r");
135                 if ($one_line == "000") $one_line = "-000" ;
136                 serv_puts($one_line);
137                 $one_line = strtok("\n");
138         }
139
140         serv_puts("000");       // Tell the server we're done...
141
142         serv_puts("ECHO echo test.");           // FIXME
143         echo "Echo test: " . serv_gets() . "<BR>\n" ;
144
145 }
146
147 //--------------------------------------------------------------------------------
148 //   protocol commands
149 //--------------------------------------------------------------------------------
150
151
152 //
153 // Identify ourselves to the Citadel server (do one once after connection)
154 /* http://www.citadel.org/doku.php/documentation:appproto:connection#iden.identify.the.client.software */
155 //
156 function ctdl_iden($client_info) {
157         global $clientsocket;
158
159         if (count($client_info) != 5)
160                 die("ctdl_iden takes 5 arguments!");
161         // Identify client and hostname
162         serv_puts("IDEN ".implode('|', $client_info));
163         $buf = serv_gets();
164 }
165
166 function ctdl_MessageFormatsPrefered($formatlist){
167         // Also express our message format preferences
168         serv_puts("MSGP ".implode("|", $formatlist));
169         $buf = serv_gets();
170 }
171
172 /* http://www.citadel.org/doku.php/documentation:appproto:connection#noop.no.operation */
173 function ctdl_noop(){
174         // Also express our message format preferences
175         serv_puts("NOOP ");
176         $buf = serv_gets();
177 }
178
179 /* http://www.citadel.org/doku.php/documentation:appproto:connection#quit.quit */
180 function ctdl_quit(){
181         // Also express our message format preferences
182         serv_puts("QUIT ");
183         $buf = serv_gets();
184 }
185
186
187 /* http://www.citadel.org/doku.php/documentation:appproto:connection#mesg.read.system.message */
188 function ctdl_gtls(){
189         // Also express our message format preferences
190         serv_puts("GTLS ");
191         $buf = serv_gets();
192         return $buf;
193 }
194
195
196 /* http://www.citadel.org/doku.php/documentation:appproto:connection#qnop.quiet.no.operation */
197 /* this seems to be dangerous. ask IG
198 function ctdl_qnoop(){
199         // Also express our message format preferences
200         serv_puts("QNOP ");
201 }
202 */
203
204 /* http://www.citadel.org/doku.php/documentation:appproto:connection#echo.echo.something */
205 function ctdl_doecho($echotext){
206         // Also express our message format preferences
207         serv_puts("ECHO ".$echotext);
208         $buf = serv_gets();
209
210 }
211
212 /* http://www.citadel.org/doku.php/documentation:appproto:connection#time.get.server.local.time */
213 /* TODO: what are the other two params? doku is incomplete here. */
214 function ctdl_time(){
215         // Also express our message format preferences
216         serv_puts("TIME");
217         $buf = serv_gets();
218
219 }
220
221
222 /* http://www.citadel.org/doku.php/documentation:appproto:connection#qdir.query.global.directory */
223 function ctdl_qdir($who){
224         // Also express our message format preferences
225         serv_puts("QDIR ".$who);
226         $buf = serv_gets();
227         return array((substr($buf, 0, 1) == "2"), $buf);
228 }
229
230
231 /* http://www.citadel.org/doku.php/documentation:appproto:connection#auto.autocompletion.of.email.addresses */
232 function ctdl_auto($who){
233         // Also express our message format preferences
234         serv_puts("AUTO ".$who);
235         $buf = serv_gets();
236         if (substr($buf, 0, 1) == "1") {
237                 $reply = read_array();
238                 if (count($reply) == 0)
239                         return false;
240                 return $reply;
241         }
242         else
243                 return false;
244 }
245
246
247
248 //
249 // login_existing_user() -- attempt to login using a supplied username/password
250 // Returns an array with two variables:
251 // 0. TRUE or FALSE to determine success or failure
252 // 1. String error message (if relevant)
253 /* http://www.citadel.org/doku.php/documentation:appproto:connection#user.send.user.name */
254 /* http://www.citadel.org/doku.php/documentation:appproto:connection#pass.send.password */
255
256 //
257 function login_existing_user($user, $pass) {
258         global $clientsocket;
259
260         serv_puts("USER " . $user);
261         $resp = serv_gets();
262         if (substr($resp, 0, 1) != "3") {
263                 return array(FALSE, substr($resp, 4));
264         }
265
266         serv_puts("PASS " . $pass);
267         $resp = serv_gets();
268         if (substr($resp, 0, 1) != "2") {
269                 return array(FALSE, substr($resp, 4));
270         }
271
272         $_SESSION["username"] = $user;
273         $_SESSION["password"] = $pass;
274         become_logged_in(substr($resp, 4));
275
276         return array(TRUE, "Login successful.  Have fun.");
277 }
278
279
280 //
281 // create_new_user() -- attempt to create a new user 
282 //                      using a supplied username/password
283 // Returns an array with two variables:
284 // 0. TRUE or FALSE to determine success or failure
285 // 1. String error message (if relevant)
286 //
287 function create_new_user($user, $pass) {
288         global $clientsocket;
289
290         serv_puts("NEWU " . $user);
291         $resp = serv_gets();
292         if (substr($resp, 0, 1) != "2") {
293                 return array(FALSE, substr($resp, 4));
294         }
295
296         serv_puts("SETP " . $pass);
297         $resp = serv_gets();
298         if (substr($resp, 0, 1) != "2") {
299                 return array(FALSE, substr($resp, 4));
300         }
301
302         $_SESSION["username"] = $user;
303         $_SESSION["password"] = $pass;
304         become_logged_in(substr($resp, 4));
305
306         return array(TRUE, "Login successful.  Have fun.");
307 }
308
309
310 //
311 // Code common to both existing-user and new-user logins
312 //
313 function become_logged_in($server_parms) {
314         $_SESSION["logged_in"] = 1;
315
316         $tokens = explode("|", $server_parms);
317         
318         $oneline["username"]   = $tokens[0];
319         $oneline["axlevel"]    = $tokens[1];
320         $oneline["calls"]      = $tokens[2];
321         $oneline["posts"]      = $tokens[3];
322         $oneline["userflags"]  = $tokens[4];
323         $oneline["usernum"]    = $tokens[5];
324         $oneline["lastcall"]   = $tokens[6];
325                 
326         ctdl_goto("_BASEROOM_");
327 }
328
329
330
331 //
332 // Learn all sorts of interesting things about the Citadel server to
333 // which we are connected.
334 /* http://www.citadel.org/doku.php/documentation:appproto:connection#info.get.server.info */
335 //
336 function ctdl_get_serv_info() {
337         serv_puts("INFO");
338         $reply = read_array();
339         if ((count($reply) == 18) &&
340             substr($reply[0], 0, 1) == "1") {
341                 $server_info=array();
342                 $server_info["serv_nodename"]  = $reply[1];
343                 $server_info["serv_humannode"] = $reply[2];
344                 $server_info["serv_fqdn"]      = $reply[3];
345                 $server_info["serv_software"]  = $reply[4];
346                 $server_info["serv_city"]      = $reply[6];
347                 $server_info["serv_sysadmin"]  = $reply[7];
348                 if (CITADEL_DEBUG_CITPROTO == 1)
349                 {
350                         echo "<pre>";
351                         print_r($server_info);
352                         echo "</pre>";
353                 }
354                 return $server_info;
355         }
356         else 
357                 die ("didn't understand the reply to the INFO command");
358
359 }
360
361 //
362 // Learn all sorts of interesting things about the Citadel server to
363 // which we are connected.
364 /* http://www.citadel.org/doku.php/documentation:appproto:connection#info.get.server.info */
365 //
366 function ctdl_get_registration_info() {
367         serv_puts("GREG");
368         $reply = read_array();
369         print_r($reply);
370 //              die ("didn't understand the reply to the INFO command");
371
372 }
373
374
375 //
376 // Display a system banner.  (Returns completed HTML.)
377 // (One is probably temporary because it outputs more or less finalized
378 // markup.  For now it's just usable.)
379 //
380 /* http://www.citadel.org/doku.php/documentation:appproto:connection#mesg.read.system.message */
381 function ctdl_mesg($msgname) {
382         global $clientsocket;
383
384         $msgtext = "<DIV ALIGN=CENTER>\n";
385
386         serv_puts("MESG " . $msgname);
387         $response = read_array();
388
389         if (substr($response[0], 0, 1) == "1") {
390                 array_shift($response); // throw away the status code.
391                 $msgtext .= "<TT>" . implode( "</TT><BR>\n" ,$response);
392         }
393         else {
394                 $msgtext .= "<B><I>" . substr($response[0], 4) . "</I></B><BR>\n";
395         }
396
397         $msgtext .= "</DIV>\n";
398         return($msgtext);
399 }
400
401 /* http://www.citadel.org/doku.php/documentation:appproto:connection#mesg.read.system.message */
402 //// TODO: is this still supported?
403 function ctdl_mrtg($what) {
404         global $clientsocket;
405
406         serv_puts("MRTG ".$what);
407         $response = serv_gets();
408
409         if (substr($response, 0, 1) != "1") {
410                 return array(0, NULL);
411         }
412                 
413         $responses = read_array();
414         return $responses;
415 }
416 //
417 // Fetch the list of users currently logged in.
418 /* http://www.citadel.org/doku.php/documentation:appproto:connection#rwho.read.who.s.online */
419 //
420 function ctdl_rwho() {
421         global $clientsocket;
422
423         serv_puts("RWHO");
424         $response = serv_gets();
425
426         if (substr($response, 0, 1) != "1") {
427                 return array(0, NULL);
428         }
429         
430         $all_lines = array();
431         $num_lines = 0;
432         
433         $responses = read_array();
434         foreach ($responses as $response) {
435                 $tokens = explode("|", $response);
436                 $oneline = array();
437
438                 $oneline["session"]      = $tokens[0];          
439                 $oneline["user"]         = $tokens[1];          
440                 $oneline["room"]         = $tokens[2];          
441                 $oneline["host"]         = $tokens[3];          
442                 $oneline["client"]       = $tokens[4];
443                 $oneline["idlesince"]    = $tokens[5];
444                 $oneline["lastcmd"]      = $tokens[6];
445                 $oneline["flags"]        = $tokens[7];
446                 $oneline["realname"]     = $tokens[8];
447                 $oneline["realroom"]     = $tokens[9];
448                 $oneline["realhostname"] = $tokens[10];
449                 $oneline["registered"]   = $tokens[11];
450
451                 // IGnore the rest of the fields for now.
452                 if (CITADEL_DEBUG_CITPROTO == 1)
453                 {
454                         echo "<pre>";
455                         print_r($oneline);
456                         echo "</pre>";
457
458                 }
459
460
461                 $num_lines = array_push($all_lines, $oneline);
462         }
463
464         return array($num_lines, $all_lines);
465
466 }
467
468
469 //
470 // Goto a room.
471 //
472 function ctdl_goto($to_where) {
473         
474         serv_puts("GOTO " . $to_where);
475         $response = serv_gets();
476
477         $results = explode ("|", $response);
478         $status_room = array_shift($results);
479         $status = substr($status_room, 0, 3);
480         if (substr($status, 0, 1) == "2") {
481                 $room = substr($status_room, 4);
482                 array_unshift($results, $room);
483                 $room_state=array(
484                         "state"          => TRUE,
485                         "statereply"     => $status,
486                         "roomname"       => $results[ 0],
487                         "nunreadmsg"     => $results[ 1],
488                         "nmessages"      => $results[ 2],
489                         "rinfopresent"   => $results[ 3],
490                         "flags"          => $results[ 4],
491                         "msgidmax"       => $results[ 5],
492                         "msgidreadmax"   => $results[ 6],
493                         "ismailroom"     => $results[ 7],
494                         "isroomaide"     => $results[ 8],
495                         "nnewmessages"   => $results[ 9],
496                         "floorid"        => $results[10],
497                         "viewselected"   => $results[11],
498                         "defaultview"    => $results[12],
499                         "istrashcan"     => $results[13]);
500                         
501                 $_SESSION["room"] = $room;
502                 if (CITADEL_DEBUG_CITPROTO == 1)
503                 {
504                         echo "<pre>";
505                         print_r($room_state);
506                         echo "</pre>";
507
508                 }
509
510                 return $room_state;
511         }
512
513         else {
514                 return array("state" => FALSE, "statereply" => $status);
515         }
516
517 }
518
519
520
521 //
522 // Fetch the list of known rooms.
523 //
524 function ctdl_knrooms() {
525         global $clientsocket;
526
527         serv_puts("LKRA");
528         $response = serv_gets();
529         if (substr($response, 0, 1) != "1") {
530                 return array(0, NULL);
531         }
532         $results = read_array();
533         $all_lines = array();
534         $num_lines = 0;
535
536         foreach ($results as $result){
537                 $oneline = array();
538                 $tokens = explode("|",$result);
539
540                 $oneline["name"]   = $tokens[0];                
541                 $oneline["flags"]  = $tokens[1];                
542                 $oneline["floor"]  = $tokens[2];                
543                 $oneline["order"]  = $tokens[3];                
544                 $oneline["flags2"] = $tokens[4];                
545                 $oneline["access"] = $tokens[5];
546
547                 if ($oneline["access"] & 8) {
548                         $oneline["hasnewmsgs"] = TRUE;
549                 }
550                 else {
551                         $oneline["hasnewmsgs"] = FALSE;
552                 }
553
554                 if (CITADEL_DEBUG_CITPROTO == 1)
555                 {
556                         echo "<pre>";
557                         print_r($oneline);
558                         echo "</pre>";
559
560                 }
561                 $num_lines = array_push($all_lines, $oneline);
562         }
563
564         return array($num_lines, $all_lines);
565
566 }
567
568 //
569 // Fetch the list of known floors.
570 //
571 /* http://www.citadel.org/doku.php/documentation:appproto:rooms#lflr.list.all.known.floors */
572 function ctdl_knfloors() {
573         global $clientsocket;
574
575         serv_puts("LFLR");
576         $response = serv_gets();
577         if (substr($response, 0, 1) != "1") {
578                 return array(0, NULL);
579         }
580
581         $results = read_array();
582         $all_lines = array();
583         $num_lines = 0;
584
585         foreach ($results as $result){
586                 $oneline = array();
587                 $tokens = explode("|",$result);
588
589                 $oneline["id"] = $tokens[0];            
590                 $oneline["name"]   = $tokens[1];                
591                 $oneline["nref"] = $tokens[2];
592
593                 if (CITADEL_DEBUG_CITPROTO == 1)
594                 {
595                         echo "<pre>";
596                         print_r($oneline);
597                         echo "</pre>";
598
599                 }
600                 $num_lines = array_push($all_lines, $oneline);
601         }
602
603         return array($num_lines, $all_lines);
604
605 }
606
607 /* http://www.citadel.org/doku.php/documentation:appproto:rooms#cflr.create.a.new.floor */
608
609 //
610 // Fetch the list of messages in one room.
611 // Returns: count, response, message array
612 //
613 function ctdl_msgs($mode, $count) {
614         global $clientsocket;
615
616         serv_puts("MSGS " . $mode . "|" . $count);
617         $responses = read_array();
618         print_r($responses);
619
620         $response = array_shift($responses);
621
622         $num_msgs = count($responses);
623         if (substr($response, 0, 1) != "1") {
624                 return array(0, substr($response, 4), NULL);
625         }
626         
627         if (CITADEL_DEBUG_CITPROTO == 1)
628         {
629                 printf("found ".$num_msgs." messages.");
630         }
631         return array($num_msgs, $response, $responses);
632 }
633
634
635 // Load a message from the server.
636 function ctdl_fetch_message($msgnum) {
637         global $clientsocket;
638
639         serv_puts("MSG4 " . $msgnum);
640
641         if (CITADEL_DEBUG_CITPROTO == 1)
642             printf ("<div class='ctdldbgRead'>");
643         $response = serv_gets(TRUE);
644
645         if (substr($response, 0, 1) != "1") {
646                 return array(FALSE, substr($response, 4), NULL);
647         }
648
649         $fields = array();
650         while (strcmp($buf = serv_gets(TRUE), "000")) {
651                 if (substr($buf, 0, 4) == "text") {
652                         if (CITADEL_DEBUG_CITPROTO == 1)
653                                 printf ("</div>\n<h3>Message Body Follows</h3><div class='ctdldbgRead'>");
654                         // We're in the text body.  New loop here.
655                         $fields["text"] = ctdl_msg4_from_server();
656                         if (CITADEL_DEBUG_CITPROTO == 1)
657                                 printf ("</div>");
658                         return array(TRUE, substr($response, 4), $fields);
659                 }
660                 else {
661                         $fields[substr($buf, 0, 4)] = substr($buf, 5);
662                 }
663         }
664
665         // Message terminated prematurely (no text body)
666         return array(FALSE, substr($response, 4), $fields);
667 }
668
669 // Support function for ctdl_fetch_message(). This handles the text body
670 // portion of the message, converting various formats to HTML as
671 // appropriate.
672 function ctdl_msg4_from_server() {
673
674         $txt = "";
675         $msgformat = "text/plain";
676         $in_body = FALSE;
677
678         $previous_line = "";
679         while (strcmp($buf = serv_gets(TRUE), "000")) {
680                 if ($in_body == FALSE) {
681                         if (strlen($buf) == 0) {
682                                 $in_body = TRUE;
683                         }
684                         else {
685                                 if (!strncasecmp($buf, "content-type: ", 14)) {
686                                         $msgformat = substr($buf, 14);
687                                 }
688                         }
689                 }
690                 else {
691                         if (!strcasecmp($msgformat, "text/html")) {
692                                 $txt .= $buf;
693                         }
694                         else if (!strcasecmp($msgformat, "text/plain")) {
695                                 $txt .= "<TT>" . htmlspecialchars($buf) . "</TT><BR>\n" ;
696                         }
697                         else if (!strcasecmp($msgformat, "text/x-citadel-variformat")) {
698                                 if (substr($previous_line, 0, 1) == " ") {
699                                         $txt .= "<BR>\n" ;
700                                 }
701                                 $txt .= htmlspecialchars($buf);
702                         }
703                         else {
704                                 $txt .= htmlspecialchars($buf);
705                         }
706                         $previous_line = $buf;
707                 }
708         }
709
710         return($txt);
711 }
712
713
714
715 function download_attachment($msgnum, $attindex)
716 {
717         $command = "DLAT ".$msgnum."|".$attindex;
718         serv_puts($command);
719         $reply = read_binary();
720         return $reply;
721
722 }
723
724
725 function enter_message_0($msgHdr, $contentType, $data)
726 {
727         $send = array();
728
729         if (isset($msgHdr['newusermail']))
730                 array_unshift($send, $msgHdr['newusermail']);
731         else
732                 array_unshift($send, "");
733
734         if (isset($msgHdr['supplied_euid']))
735                 array_unshift($send, $msgHdr['supplied_euid']);
736         else
737                 array_unshift($send, "");
738
739         if (isset($msgHdr['bcc']))
740                 array_unshift($send, $msgHdr['bcc']);
741         else
742                 array_unshift($send, "");
743
744         if (isset($msgHdr['cc']))
745                 array_unshift($send, $msgHdr['cc']);
746         else
747                 array_unshift($send, "");
748
749         if (isset($msgHdr['do_confirm']))
750                 array_unshift($send, $msgHdr['do_confirm']);
751         else
752                 array_unshift($send, "");
753
754         if (isset($msgHdr['newusername']))
755                 array_unshift($send, $msgHdr['newusername']);
756         else
757                 array_unshift($send, "");
758
759         if (isset($msgHdr['subject']))
760                 array_unshift($send, $msgHdr['subject']);
761         else
762                 array_unshift($send, "");
763
764         if (isset($msgHdr['format_type']))
765                 array_unshift($send, $msgHdr['format_type']);
766         else
767                 array_unshift($send, "");
768
769         if (isset($msgHdr['anon_flag']))
770                 array_unshift($send, $msgHdr['anon_flag']);
771         else
772                 array_unshift($send, "");
773
774         if (isset($msgHdr['recp']))
775                 array_unshift($send, $msgHdr['recp']);
776         else
777                 array_unshift($send, "");
778
779         if (isset($msgHdr['post']))
780                 array_unshift($send, $msgHdr['post']);
781         else
782                 array_unshift($send, "");
783
784         $params = implode('|', $send);
785         serv_puts("ENT0 ".$params);
786
787         $reply=serv_gets();
788         if (substr($reply, 0, 1) != 4)
789                 return array(false, array(), array());
790         serv_puts("Content-type: ".$contentType);
791         serv_puts("");
792         serv_puts($data."\r\n");
793         serv_puts("000");
794 }
795
796
797 ?>