home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / bingrb2b.zip / groups.cmd < prev    next >
OS/2 REXX Batch file  |  1997-08-08  |  6KB  |  217 lines

  1. /*------------------------------------------------------------------
  2.  * REXX - OS/2
  3.  * bingrab.cmd : binaries grabber
  4.  * Grabs uudecoded files (multiple and single part) from newsgroups
  5.  * then decodes them into executable binaries
  6.  *------------------------------------------------------------------*/
  7. parse arg server group 
  8.  
  9.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  10.   call SysLoadFuncs
  11.  
  12. call syscls
  13. say "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  14. say "GROUPS v0.001a"
  15. say "by Timothy Millea - CyberLord"
  16. say "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  17.   
  18. if (server = "") then
  19.    do
  20.    say "Expecting a news server name to be passed as a parameter."
  21. end
  22.  
  23. /*------------------------------------------------------------------
  24.  * initialize socket function package
  25.  *------------------------------------------------------------------*/
  26.  
  27.    if RxFuncQuery("SockLoadFuncs") then
  28.       do
  29.       rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
  30.       rc = SockLoadFuncs()
  31.       end
  32.  
  33. /*------------------------------------------------------------------
  34.  * get address of server
  35.  *------------------------------------------------------------------*/
  36. rc = SockGetHostByName(server,"host.!")
  37. if (rc = 0) then
  38.    do
  39.    say "Unable to resolve server name" server
  40.    exit
  41.    end
  42.  
  43. server = host.!addr
  44.  
  45. /*------------------------------------------------------------------
  46.  * open socket
  47.  *------------------------------------------------------------------*/
  48. sock = SockSocket("AF_INET","SOCK_STREAM",0)
  49. if (sock = -1) then
  50.    do
  51.    say "Error opening socket:" errno
  52.    exit
  53.    end
  54.  
  55. /*------------------------------------------------------------------
  56.  * connect socket
  57.  *------------------------------------------------------------------*/
  58. server.!family = "AF_INET"
  59. server.!port   = 119
  60. server.!addr   = server
  61.  
  62. rc = SockConnect(sock,"server.!")
  63. if (rc = -1) then
  64.    Error(sock,rc,"Error connecting to newsserver :" errno)
  65.  
  66. trc = GetResponse(sock)
  67. do i = 1 to line.0
  68.    say line.i
  69. end
  70.  
  71. rc = Interact(sock, group)    /*Jump to interact function*/
  72.  
  73. /*------------------------------------------------------------------
  74.  * quittin' time!
  75.  *------------------------------------------------------------------*/
  76. rc = SendMessage(sock,"quit")
  77. rc = SockSoclose(sock)
  78.  
  79. exit
  80.  
  81. /*------------------------------------------------------------------
  82.  * get command and execute in a loop
  83.  *------------------------------------------------------------------*/
  84. Interact:        procedure expose !.
  85.    sock = arg(1)
  86.    group = arg(2)
  87. say "Getting current list of ALL newsgroups."
  88. say "This will take some time!"
  89. trc = SendMessage(sock,"list")
  90. trc = GetResponse(sock)
  91.  
  92. pause
  93.  
  94. say "Writing ONLY BINARIES groups to file."
  95.   do i = 1 to line.0
  96.     if pos('binaries',line.i) > 0 then do
  97.        call lineout binaries||".grp",line.i
  98.   end /*then do*/
  99.   end /*do i*/
  100.  
  101. return ""
  102.  
  103. /*------------------------------------------------------------------
  104.  * send a string to the server
  105.  *------------------------------------------------------------------*/
  106. SendMessage:     procedure expose !.
  107.    sock = arg(1)
  108.    data = arg(2) || d2c(13) || d2c(10)
  109.  
  110.    len = length(data)
  111.    do while (len > 0)
  112.       i = SockSend(sock,data);
  113.  
  114.       if (errno <> 0) then
  115.          Error(-1,rc,"Error sending data to server.")
  116.  
  117.       if (i <= 0) then
  118.          Error(sock,100,"Server closed the connection.")
  119.  
  120.       data = substr(data,len+1)
  121.       len  = length(data)
  122.    end
  123.  
  124.    return 0
  125.  
  126.  
  127. /*------------------------------------------------------------------
  128.  * get a response from the server
  129.  *------------------------------------------------------------------*/
  130. GetResponse:     procedure expose !. line.
  131.    sock = arg(1)
  132.  
  133.    moreids = "100 215 220 221 222 223 230 231"
  134.  
  135.    line.0 = 1
  136.    line.1 = GetResponseLine(sock)
  137.  
  138.    parse var line.1 rid .
  139.  
  140.    if (wordpos(rid,moreids) = 0) then
  141.       return ""
  142.  
  143. if rid = 223 then return ""
  144.  
  145.    do forever
  146.       o = line.0 + 1
  147.  
  148.       line.o = GetResponseLine(sock)
  149.  
  150.       if (line.o = ".") then
  151.          return ""
  152.  
  153.       line.0 = o
  154.    end
  155.  
  156.    return ""
  157.  
  158. /*------------------------------------------------------------------
  159.  * get a line from the server
  160.  *------------------------------------------------------------------*/
  161. GetResponseLine: procedure expose !.
  162.    sock = arg(1)
  163.  
  164.    crlf = d2c(13) || d2c(10)
  165.  
  166.    if (symbol('!.buff') = "LIT") then
  167.       !.buff = ""
  168.  
  169.    do while (pos(crlf,!.buff) = 0)
  170.       rc = SockRecv(sock,"data",8000)
  171.       !.buff = !.buff || data
  172.    end
  173.  
  174.    p = pos(crlf,!.buff)
  175.  
  176.    line = substr(!.buff,1,p-1)
  177.    !.buff = substr(!.buff,p+2)
  178.  
  179.    return line
  180.  
  181. /*------------------------------------------------------------------
  182.  * halting ...
  183.  *------------------------------------------------------------------*/
  184. Halting:
  185.    Error(sock,1,"error on line" sigl)
  186.  
  187. /*------------------------------------------------------------------
  188.  * exit with a message and return code
  189.  *------------------------------------------------------------------*/
  190. Error: procedure
  191.    sock = arg(1)
  192.    retc = arg(2)
  193.    msg  = arg(3)
  194.  
  195.    if (sock <> -1) then
  196.       rc = SockSoClose(sock)
  197.  
  198.    say msg
  199.  
  200.    exit retc
  201.  
  202. /*------------------------------------------------------------------
  203.  * help
  204.  *------------------------------------------------------------------*/
  205. Help: procedure
  206.    say "commands:"
  207.    say
  208.    say "quit    - to quit"
  209.    say "group   - to change to a particular group"
  210.    say "article - to see an article"
  211.    say
  212.    return ""
  213.  
  214.  
  215. /*
  216.  
  217. */