topical media & game development
alt-bot-lib-nntp.php / php
<?php
/*
#################################################################
Copyright 2007, Michael Schrenk
This software is designed for use with the book,
"Webbots, Spiders, and Screen Scarpers", Michael Schrenk, 2007 No Starch Press, San Francisco CA
W3CŪ SOFTWARE NOTICE AND LICENSE
This work (and included software, documentation such as READMEs, or other
related items) is being provided by the copyright holders under the following license.
By obtaining, using and/or copying this work, you (the licensee) agree that you have read,
understood, and will comply with the following terms and conditions.
Permission to copy, modify, and distribute this software and its documentation, with or
without modification, for any purpose and without fee or royalty is hereby granted, provided
that you include the following on ALL copies of the software and documentation or portions thereof,
including modifications:
1. The full text of this NOTICE in a location viewable to users of the redistributed
or derivative work.
2. Any pre-existing intellectual property disclaimers, notices, or terms and conditions.
If none exist, the W3C Software Short Notice should be included (hypertext is preferred,
text is permitted) within the body of any redistributed or derivative code.
3. Notice of any changes or modifications to the files, including the date changes were made.
(We recommend you provide URIs to the location from which the code is derived.)
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD
PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT
OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the
software without specific, written prior permission. Title to copyright in this software and any associated
documentation will at all times remain with copyright holders.
#################################################################
*/
#-----------------------------------------------------------------------
# F U N C T I O N S
#
# read_nntp_buffer(
server)
# Returns a list of newsgroups on a valid news server
#
# get_nntp_article_ids(
newsgroup)
# Returns a list of article ids for a newsgroup on a news server
#
# read_nntp_article(
newsgroup,
socket)
-------------------------------------------------------------
DESCRIPTION:
Reads data from a news server
THIS FUNCTION IS USED INTERNALLY AND NOT USEFUL ALONE
INPUT:
socket)
{
buffer ="";
while(
this_line = fgets(
buffer =
this_line;
#
# UNCOMMENT THE FOLLOWING LINE IF YOU NEED TO SEE PROGRESS (This script may take a long time to run).
echo "this_line=
buffer;
}
*********************************************************************
get_nntp_groups(socket Reference to the socket of the connection to
the news server
OUTPUT:
A list of newsgroups on the news server
*********************************************************************
function get_nntp_groups(fp = fsockopen(port="119", errstr, 30);
if (!return_array['ERROR'] = "ERROR: errno)";
}
else
{
# Else tell server to return a list of hosted newsgroups
fp, groups = read_nntp_buffer(groups_array = explode("\r\n", fp, "QUIT \r\n"); // Log out
fclose(groups_array;
}
*********************************************************************
get_nntp_article_ids(newsgroup)
-------------------------------------------------------------
DESCRIPTION:
Reads available article ids from a news server
INPUT:
newsgroup Name of newsgroup
OUTPUT:
Returns available article ids for the newsgroup on the server
*********************************************************************
function get_nntp_article_ids(newsgroup)
{
# Open socket connection to the mail server
server, errno, socket)
{
# If socket error, issue error
errstr (socket, "GROUP ".return_array['GROUP_MESSAGE'] = trim(fread(socket, "NEXT \r\n");
socket, 2000);
res);
array[0];
array[1];
array[2];
array[3];
}
fputs(socket);
return
*********************************************************************
read_nntp_article(server, article)
-------------------------------------------------------------
DESCRIPTION:
Reads article from a news server
INPUT:
newsgroup Name of newsgroup
function read_nntp_article(server, article)
{
# Open socket connection to the mail server
server, errno, socket)
{
# If socket error, issue error
errstr (socket, "GROUP ".socket, "HEAD return_array['HEAD'] = read_nntp_buffer(socket, "BODY return_array['ARTICLE'] = read_nntp_buffer(socket, "QUIT \r\n"); // Sign out (newsgroup server)
fclose(return_array; // Return data array
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.