Re: newsgroup list

From: Jerry McBride (mcbrides@erols.com)
Date: Thu, 08 Apr 1999 23:34:18 -0400

>In article <c2eC38D5wKIX090yn@erols.com>,
> mcbrides@erols.com (Jerry McBride) wrote:
>>>Looking for an OS/2 utility to retrieve a list of newsgroups from my server.
>>>
>>
>>How you want it... Java or Rexx? I can offer up both and include the source
>>for the Java version. :')
>>
>
>Rexx is good 'nuff for me.
>

Here ya' go:

/* makelist.cmd
Requires the following resources to run:
1 - An active Inet connection
2 - RXSOCK.DLL
3 - OS/2...

Execute makelist.cmd thus:

MAKELIST.CMD NEWS.EROLS.COM

Alter the NewsServer name to match your news server... :')

*/

parse arg server

call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

call syscls
say'MakeList 1.2'
say''

if (server = "") then do
say "Expecting a news server name to be passed as a parameter."
exit 1
end /* if */

/*------------------------------------------------------------------
* initialize socket function package
*------------------------------------------------------------------*/

if RxFuncQuery("SockLoadFuncs") then do
rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
rc = SockLoadFuncs()
end /* if */

/*------------------------------------------------------------------
* get address of server
*------------------------------------------------------------------*/
rc = SockGetHostByName(server,"host.!")

if (rc = 0) then do
say "Unable to resolve server name" server
exit 1
end /* if */

server = host.!addr

/*------------------------------------------------------------------
* open socket
*------------------------------------------------------------------*/
sock = SockSocket("AF_INET","SOCK_STREAM",0)

if (sock = -1) then do
say "Error opening socket:" errno
exit 1
end /* if */

/*------------------------------------------------------------------*
* configure socket for large buffers *
*------------------------------------------------------------------*/

rc = SockSetSockOpt(sock, 'SOL_SOCKET', 'SO_RCVBUF', 32768)

/*------------------------------------------------------------------
* connect socket
*------------------------------------------------------------------*/
server.!family = "AF_INET"
server.!port = 119
server.!addr = server

rc = SockConnect(sock,"server.!")

if (rc = -1) then Error(sock,rc,"Error connecting to newsserver :" errno)

trc = GetResponse(sock)

do i = 1 to line.0
say line.i
end /* do */

rc = Interact(sock, group) /*Jump to interact function*/

/*------------------------------------------------------------------
* quittin' time!
*------------------------------------------------------------------*/
rc = SendMessage(sock,"quit")
rc = SockSoclose(sock)

exit

/*------------------------------------------------------------------
* get command and execute in a loop
*------------------------------------------------------------------*/
Interact: procedure expose !.

sock = arg(1)
group = arg(2)
say "Getting current list of ALL newsgroups."
say "This will take some time!"
trc = SendMessage(sock,"list")
trc = GetResponse(sock)

say "Writing complete list of newsgroups to file."
say "Stand-by!"

do i = 1 to line.0
call lineout 'group.list',line.i
end /* do */

call lineout 'group.list'

return ""

/*------------------------------------------------------------------
* send a string to the server
*------------------------------------------------------------------*/
SendMessage: procedure expose !.
sock = arg(1)
data = arg(2) || d2c(13) || d2c(10)

len = length(data)
do while (len > 0)
i = SockSend(sock,data);
if (errno <> 0) then Error(-1,rc,"Error sending data to server.")
if (i <= 0) then Error(sock,100,"Server closed the connection.")
data = substr(data,len+1)
len = length(data)
end

return 0

/*------------------------------------------------------------------
* get a response from the server
*------------------------------------------------------------------*/
GetResponse: procedure expose !. line.
sock = arg(1)

moreids = "100 215 220 221 222 223 230 231"

line.0 = 1
line.1 = GetResponseLine(sock)

parse var line.1 rid .

if (wordpos(rid,moreids) = 0) then return ""

if rid = 223 then return ""

do forever
o = line.0 + 1
line.o = GetResponseLine(sock)
if (line.o == ".") then return "" /* I DID THAT! */
line.0 = o
end /* do */

return ""

/*------------------------------------------------------------------
* get a line from the server
*------------------------------------------------------------------*/
GetResponseLine: procedure expose !.
sock = arg(1)

crlf = d2c(13) || d2c(10)

if (symbol('!.buff') = "LIT") then !.buff = ""

do while (pos(crlf,!.buff) = 0)
rc = SockRecv(sock,"data",8000)
!.buff = !.buff || data
end /* do */

p = pos(crlf,!.buff)

line = substr(!.buff,1,p-1)
!.buff = substr(!.buff,p+2)

return line

/*------------------------------------------------------------------
* halting ...
*------------------------------------------------------------------*/
Halting:

Error(sock,1,"error on line" sigl)

/*------------------------------------------------------------------
* exit with a message and return code
*------------------------------------------------------------------*/
Error: procedure
sock = arg(1)
retc = arg(2)
msg = arg(3)

if (sock <> -1) then rc = SockSoClose(sock)

say msg

exit retc

--

/--------------------\ | Jerry McBride | | mcbrides@erols.com | \--------------------/