home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / lynx2_8.zip / inews.cmd < prev    next >
OS/2 REXX Batch file  |  1996-06-07  |  4KB  |  163 lines

  1. /* inews rexx v0.9 by Rupa Schomaker (rupa@rupa.com) */
  2. /* post an aritcle to an NNTP deamon  */
  3. /* options -- none are used but -h is required, input to stdin expected */
  4. /* env variables used: NNTPSERVER */
  5.  
  6. CALL ON halt
  7. CALL ON error 
  8. CALL init
  9.  
  10. /* eat the -h option, and take the next argument as input    */
  11. /* this should also work with stdin -- at least it does with */
  12. /* person rexx -- dunno about OS/2 rexx                      */
  13. PARSE ARG  infile 
  14. infile=Strip(infile)
  15.  
  16. /* setup the structure for the socket calls */
  17. sin.!family='AF_INET'
  18. sin.!port=port
  19. if SockGetHostByName(nntpserver,'host.!') = 0 THEN 
  20.    IF SockGetHostByAddr(nntpserver,'host.!') = 0 THEN DO 
  21.    SAY 'Could not resolve:' host
  22.    EXIT
  23. END
  24. sin.!addr=host.!addr
  25.  
  26. socket = SockSocket('AF_INET','SOCK_STREAM','IPPROTO_TCP')
  27. if SockConnect(socket,'sin.!') = -1 THEN DO
  28.    SAY 'Could not open socket with:' nntpserver 'on port' port'.'
  29.    EXIT
  30. END
  31.  
  32. line = SockGets(socket,nntprc)
  33. SELECT 
  34.  WHEN nntprc = 200 THEN NOP
  35.  WHEN nntprc = 201 THEN DO
  36.     SAY 'You do not have permission to post on this server.'
  37.     SIGNAL halt
  38.  END
  39.  OTHERWISE DO
  40.     SAY 'Your nntp server did no respond with code 200, but rather with:'
  41.     SAY line
  42.     SAY 'Report this to rupa@netcom.com and maybe your news admin.'
  43.     SIGNAL halt
  44.  END
  45. END
  46.  
  47.  
  48. IF SockSend(socket,'POST'||crlf) = -1 THEN DO 
  49.    SAY 'Attempt to send data to socket failed.'
  50.    SIGNAL halt
  51. END
  52.  
  53. line = SockGets(socket,nntprc)
  54. SELECT
  55.  WHEN nntprc = 340 THEN NOP
  56.  WHEN nntprc = 380 THEN DO
  57.     SAY 'Your host needs authorization info, we do not do that yet.'
  58.     SAY line
  59.     signal halt
  60.  END
  61.  OTHERWISE DO
  62.    SAY 'Could not post to your NNTP server, it returned:'
  63.    SAY line
  64.    SIGNAL halt
  65.  END
  66. END
  67.  
  68. DO WHILE Lines(infile)
  69.    line = LineIn(infile)
  70.    /* take care of lines with just a '.' in it */
  71.    IF line = '.' THEN 
  72.       line = line||'.'
  73.    IF SockSend(socket,line||crlf) = -1 THEN DO
  74.       SAY 'unexpected close of server socket, article not sent.'
  75.       SIGNAL halt
  76.    END
  77. END
  78. IF SockSend(socket,'.'||crlf) = -1 THEN DO
  79.    SAY 'unexpected close of server socket, article not sent.'
  80.    SIGNAL halt
  81. END
  82.  
  83. line = SockGets(socket,nntprc)
  84. SELECT
  85.  WHEN nntprc = 235 THEN NOP
  86.  WHEN nntprc = 240 THEN NOP
  87.  OTHERWISE DO
  88.     SAY 'Article not posted, server said:'
  89.     SAY line
  90.  END
  91. END
  92.  
  93. /* done, CALL the halt stuff */
  94. SIGNAL halt
  95.  
  96. EXIT
  97.  
  98.  
  99. init:
  100.    /* Set some definitions for easier handling */
  101.    cr='0d'x
  102.    crlf='0d0a'x
  103.    eot = '.'||crlf
  104.    buffsize = 512
  105.    port = 119
  106.    
  107.    
  108.    nntpserver=value('NNTPSERVER',,'OS2ENVIRONMENT')
  109.    IF nntpserver ='' THEN DO
  110.          nntpserver='news'
  111. /*       SAY 'You must have "NNTPSERVER" set in order to post articles.'
  112.       EXIT
  113. */   
  114.    END
  115.  
  116.    /* init socket library */
  117.    rc = RxFuncAdd("SockLoadFuncs","rxsock","SockLoadFuncs")
  118.    rc = SockLoadFuncs('quiet')
  119.    IF RxFuncQuery("SockLoadFuncs") THEN DO
  120.       SAY 'Could not find rxsock.dll!'
  121.       SAY 'Make sure it is in your LIBPATH.  If you do not have it,'
  122.       say 'get it from software.watson.ibm.com:/pub/os2/ews/rxsock.zip'
  123.    END
  124.  
  125.    /* load the rxutil stuff */
  126.    IF RxFuncQuery("SysLoadFuncs") THEN DO
  127.       rc = RxFuncAdd("SysLoadFuncs","rexxutil","SysLoadFuncs")
  128.       rc = SysLoadFuncs()
  129.    END
  130. return
  131.  
  132. SockGets: PROCEDURE EXPOSE buffsize nntprc crlf
  133.    sock = Arg(1)
  134.    nntprc = Arg(2)
  135.    
  136.    if (symbol('!.buff') = "LIT") then
  137.       !.buff = ""
  138.  
  139.    do while (pos(crlf,!.buff) = 0)
  140.       rc = SockRecv(sock,"data",8000)
  141.       !.buff = !.buff || data
  142.    end
  143.  
  144.    p = pos(crlf,!.buff)
  145.  
  146.    line = substr(!.buff,1,p-1)
  147.    !.buff = substr(!.buff,p+2)
  148.    
  149.    PARSE VAR line nntprc .
  150.    
  151. RETURN line
  152.  
  153. halt:
  154.    rc = SockClose(socket)
  155. EXIT
  156.  
  157.  
  158. error:
  159.    SAY 'oops, better send an email to rupa@netcom.com to squash that bug!'
  160.    SIGNAL halt 
  161. EXIT
  162.  
  163.