home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / pine / c-client / nntp.c < prev    next >
C/C++ Source or Header  |  1994-01-19  |  4KB  |  118 lines

  1. /*
  2.  * Program:    Network News Transfer Protocol (NNTP) routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *        Internet: MRC@CAC.Washington.EDU
  11.  *
  12.  * Date:    10 February 1992
  13.  * Last Edited:    23 October 1993
  14.  *
  15.  * Copyright 1993 by the University of Washington.
  16.  *
  17.  *  Permission to use, copy, modify, and distribute this software and its
  18.  * documentation for any purpose and without fee is hereby granted, provided
  19.  * that the above copyright notices appear in all copies and that both the
  20.  * above copyright notices and this permission notice appear in supporting
  21.  * documentation, and that the name of the University of Washington not be
  22.  * used in advertising or publicity pertaining to distribution of the software
  23.  * without specific, written prior permission.  This software is made
  24.  * available "as is", and
  25.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  26.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  27.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  28.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  29.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  30.  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  31.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN
  32.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35.  
  36.  
  37. #include <ctype.h>
  38. #include <stdio.h>
  39. /* VMS - The following two lines were transposed */
  40. #include "osdep.h"
  41. #include "mail.h"
  42. #include "smtp.h"
  43. #include "nntp.h"
  44. #include "rfc822.h"
  45. #include "misc.h"
  46.  
  47. /* Network News Transfer Protocol open connection
  48.  * Accepts: service host list
  49.  *        initial debugging flag
  50.  * Returns: T on success, NIL on failure
  51.  */
  52.  
  53. SMTPSTREAM *nntp_open (hostlist,debug)
  54.     char **hostlist;
  55.     long debug;
  56. {
  57.   SMTPSTREAM *stream = NIL;
  58.   void *tcpstream;
  59.   if (!(hostlist && *hostlist)) mm_log ("Missing NNTP service host",ERROR);
  60.   else do {            /* try to open connection */
  61.     if (tcpstream = tcp_open (*hostlist,NNTPTCPPORT)) {
  62.       stream = (SMTPSTREAM *) fs_get (sizeof (SMTPSTREAM));
  63.       stream->tcpstream = tcpstream;
  64.       stream->debug = debug;
  65.       stream->reply = NIL;
  66.                 /* get NNTP greeting */
  67.       if ((smtp_reply (stream) == NNTPGREET) &&
  68.       (smtp_send (stream,"MODE","READER") == NNTPGREET)) return stream;
  69.       smtp_close (stream);    /* otherwise punt stream */
  70.     }
  71.   } while (*++hostlist);    /* try next server */
  72.   return NIL;
  73. }
  74.  
  75. /* Network News Transfer Protocol deliver news
  76.  * Accepts: stream
  77.  *        message envelope
  78.  *        message body
  79.  * Returns: T on success, NIL on failure
  80.  */
  81.  
  82. long nntp_mail (stream,env,body)
  83.     SMTPSTREAM *stream;
  84.     ENVELOPE *env;
  85.     BODY *body;
  86. {
  87.   long ret;
  88.   char tmp[8*MAILTMPLEN],*s;
  89.                 /* negotiate post command */
  90.   if (!(smtp_send (stream,"POST",NIL) == NNTPREADY)) return NIL;
  91.                 /* set up error in case failure */
  92.   smtp_fake (stream,SMTPSOFTFATAL,"NNTP connection went away!");
  93.   /* Gabba gabba hey, we need some brain damage to send netnews!!!
  94.    *
  95.    * First, we give ourselves a frontal lobotomy, and put in some UUCP
  96.    *  syntax.  It doesn't matter that it's completely bogus UUCP, and
  97.    *  that UUCP has nothing to do with anything we're doing.
  98.    *
  99.    * Then, we bop ourselves on the head with a ball-peen hammer.  How
  100.    *  dare we be so presumptious as to insert a *comment* in a Date:
  101.    *  header line.  Why, we were actually trying to be nice to a human
  102.    *  by giving a symbolic timezone (such as PST) in addition to a
  103.    *  numeric timezone (such as -0800).  But the gods of news transport
  104.    *  will have none of this.  Unix weenies, tried and true, rule!!!
  105.    */
  106.                 /* RFC-1036 requires this cretinism */
  107.   sprintf (tmp,"Path: %s!%s\015\012",tcp_localhost (stream->tcpstream),
  108.        env->from ? env->from->mailbox : "foo");
  109.                 /* here's another cretinism */
  110.   if (s = strstr (env->date," (")) *s = NIL;
  111.                 /* output data, return success status */
  112.   ret = tcp_soutr (stream->tcpstream,tmp) &&
  113.     rfc822_output (tmp,env,body,smtp_soutr,stream->tcpstream) &&
  114.       (smtp_send (stream,".",NIL) == NNTPOK);
  115.   if (s) *s = ' ';        /* put the comment in the date back */
  116.   return ret;
  117. }
  118.