home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / pine3.07 / c-client / nntp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-29  |  3.1 KB  |  98 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:    3 March 1992
  14.  *
  15.  * Copyright 1992 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. #if unix
  40. #include <sys/types.h>
  41. #endif
  42. #include "osdep.h"
  43. #include "mail.h"
  44. #include "smtp.h"
  45. #include "nntp.h"
  46. #include "rfc822.h"
  47. #include "misc.h"
  48.  
  49. /* Network News Transfer Protocol open connection
  50.  * Accepts: service host list
  51.  *        initial debugging flag
  52.  * Returns: T on success, NIL on failure
  53.  */
  54.  
  55. SMTPSTREAM *nntp_open (hostlist,debug)
  56.     char **hostlist;
  57.     long debug;
  58. {
  59.   SMTPSTREAM *stream = NIL;
  60.   void *tcpstream;
  61.   char tmp[MAILTMPLEN];
  62.   if (!(hostlist && *hostlist)) mm_log ("Missing NNTP service host",ERROR);
  63.   else do {            /* try to open connection */
  64.     if (tcpstream = tcp_open (*hostlist,NNTPTCPPORT)) {
  65.       stream = (SMTPSTREAM *) fs_get (sizeof (SMTPSTREAM));
  66.       stream->tcpstream = tcpstream;
  67.       stream->debug = debug;
  68.       stream->reply = NIL;
  69.                 /* get NNTP greeting */
  70.       if (smtp_reply (stream) == NNTPGREET) return stream;
  71.       smtp_close (stream);    /* otherwise punt stream */
  72.     }
  73.   } while (*++hostlist);    /* try next server */
  74.   return NIL;
  75. }
  76.  
  77. /* Network News Transfer Protocol deliver news
  78.  * Accepts: stream
  79.  *        message envelope
  80.  *        message body
  81.  * Returns: T on success, NIL on failure
  82.  */
  83.  
  84. long nntp_mail (stream,env,body)
  85.     SMTPSTREAM *stream;
  86.     ENVELOPE *env;
  87.     BODY *body;
  88. {
  89.   char tmp[8*MAILTMPLEN];
  90.                 /* negotiate post command */
  91.   if (!(smtp_send (stream,"POST",NIL) == NNTPREADY)) return NIL;
  92.                 /* set up error in case failure */
  93.   smtp_fake (stream,SMTPSOFTFATAL,"NNTP connection went away!");
  94.                 /* output data, return success status */
  95.   return rfc822_output (tmp,env,body,smtp_soutr,stream->tcpstream) &&
  96.     (smtp_send (stream,".",NIL) == NNTPOK);
  97. }
  98.