From 2d70103f88f87a213b1050ea783435584e665f1e Mon Sep 17 00:00:00 2001 From: dust Date: Tue, 18 Oct 2005 03:14:01 +0000 Subject: [PATCH] 2005-10-17 dust * Exchange the remaining URL with EepGet in Sucker. * Allow /TOPIC irc command. --- .../net/i2p/i2ptunnel/I2PTunnelIRCClient.java | 11 +- .../java/src/net/i2p/syndie/Sucker.java | 107 ++++++++---------- history.txt | 6 +- 3 files changed, 57 insertions(+), 67 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java index d2678a505..1e5fb7ab9 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java @@ -14,6 +14,7 @@ import net.i2p.data.DataFormatException; import net.i2p.data.DataHelper; import net.i2p.data.Destination; import net.i2p.util.EventDispatcher; +import net.i2p.util.I2PThread; import net.i2p.util.Log; public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable { @@ -81,9 +82,9 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable try { i2ps = createI2PSocket(dest); i2ps.setReadTimeout(readTimeout); - Thread in = new Thread(new IrcInboundFilter(s,i2ps)); + Thread in = new I2PThread(new IrcInboundFilter(s,i2ps)); in.start(); - Thread out = new Thread(new IrcOutboundFilter(s,i2ps)); + Thread out = new I2PThread(new IrcOutboundFilter(s,i2ps)); out.start(); } catch (Exception ex) { if (_log.shouldLog(Log.ERROR)) @@ -268,7 +269,8 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable "QUIT", "PART", "WALLOPS", - "ERROR" + "ERROR", + "TOPIC" }; if(field[0].charAt(0)==':') @@ -338,7 +340,8 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable "PING", "KICK", "HELPME", - "RULES" + "RULES", + "TOPIC" }; if(field[0].length()==0) diff --git a/apps/syndie/java/src/net/i2p/syndie/Sucker.java b/apps/syndie/java/src/net/i2p/syndie/Sucker.java index 786c2f7a0..39f6d0721 100644 --- a/apps/syndie/java/src/net/i2p/syndie/Sucker.java +++ b/apps/syndie/java/src/net/i2p/syndie/Sucker.java @@ -7,15 +7,9 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.net.MalformedURLException; -import java.net.Socket; -import java.net.SocketAddress; -import java.net.URL; -import java.net.URLConnection; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -23,7 +17,6 @@ import java.util.ListIterator; //import sun.security.provider.SHA; -import com.sun.syndication.feed.atom.Entry; import com.sun.syndication.feed.synd.SyndCategory; import com.sun.syndication.feed.synd.SyndContent; import com.sun.syndication.feed.synd.SyndEntry; @@ -50,6 +43,8 @@ public class Sucker { private boolean importEnclosures=true; private boolean importRefs=true; private boolean pendingEndLink; + private boolean shouldProxy; + private int proxyPortNum; public Sucker() {} @@ -96,22 +91,14 @@ public class Sucker { if(idx==0) idx=x; baseUrl=urlToLoad.substring(0,idx); - System.out.println("BaseUrl: "+baseUrl); + + System.out.println("Processing: "+urlToLoad); return true; } public void suck() { - URL feedUrl; SyndFeed feed; - int i; - - //if (proxyHost != null && proxyPort != null) { - // // Set proxy - // System.setProperty("http.proxyHost", proxyHost); - // System.setProperty("http.proxyPort", proxyPort); - //} - // try { @@ -141,8 +128,8 @@ public class Sucker { SyndFeedInput input = new SyndFeedInput(); - boolean shouldProxy = false; - int proxyPortNum = -1; + shouldProxy = false; + proxyPortNum = -1; if ( (proxyHost != null) && (proxyPort != null) ) { try { proxyPortNum = Integer.parseInt(proxyPort); @@ -206,14 +193,15 @@ public class Sucker { System.out.println("new: " + messageId); if (convertToSml(e, ""+messageNumber)) { - hos.write(messageId.getBytes()); - hos.write("\n".getBytes()); if (pushScript != null) { - if (!execPushScript(""+messageNumber, time)) - System.out.println("push failed"); - else + if (!execPushScript(""+messageNumber, time)) { + System.out.println("################## push failed"); + }else { System.out.println("push success"); + hos.write(messageId.getBytes()); + hos.write("\n".getBytes()); + } } } messageNumber++; @@ -285,7 +273,6 @@ public class Sucker { private boolean convertToSml(SyndEntry e, String messageName) { // Create message - File messageFile = new File(messageName); FileOutputStream fos; messagePath=outputDir+"/"+messageName; try { @@ -376,14 +363,15 @@ public class Sucker { private String htmlTagToSmlTag(String htmlTag) { String ret=""; + String htmlTagLowerCase=htmlTag.toLowerCase(); - if(importEnclosures && htmlTag.startsWith("=5) { b=a+1; - while(htmlTag.charAt(b)!='\"') + while(htmlTagLowerCase.charAt(b)!='\"') b++; String altText=htmlTag.substring(a,b); ret+=altText; @@ -416,14 +404,14 @@ public class Sucker { return ret; } - if(importRefs && htmlTag.startsWith("".equals(htmlTag)) { + if ("".equals(htmlTagLowerCase)) { if (pendingEndLink) return "[/link]"; } - if("".equals(htmlTag)) + if("".equals(htmlTagLowerCase)) return "[b]"; - if("".equals(htmlTag)) + if("".equals(htmlTagLowerCase)) return "[/b]"; - if("".equals(htmlTag)) + if("".equals(htmlTagLowerCase)) return "[i]"; - if("".equals(htmlTag)) + if("".equals(htmlTagLowerCase)) return "[/i]"; return null; } private void fetchAttachment(String link) { - System.out.println("Fetch attachment from: "+link); - String attachmentPath = messagePath+"."+attachmentCounter; - try { - link=link.replaceAll("&","&"); - URL attachmentUrl = new URL(link); - InputStream is = attachmentUrl.openStream(); - - FileOutputStream fos = new FileOutputStream(attachmentPath); - - while(true) - { - int i =is.read(); - if(i<0) - break; - fos.write(i); - } - - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + System.out.println("Fetch attachment from: "+link); + + String attachmentPath = messagePath+"."+attachmentCounter; + link=link.replaceAll("&","&"); + + int numRetries = 2; + File fetched = new File(attachmentPath); + // we use eepGet, since it retries and doesn't leak DNS requests like URL does + EepGet get = new EepGet(I2PAppContext.getGlobalContext(), shouldProxy, proxyHost, proxyPortNum, + numRetries, fetched.getAbsolutePath(), link); + SuckerFetchListener lsnr = new SuckerFetchListener(); + get.addStatusListener(lsnr); + get.fetch(); + boolean ok = lsnr.waitForSuccess(); + if (!ok) { + System.err.println("Unable to retrieve the url after " + numRetries + " tries."); + fetched.delete(); + return; + } attachmentCounter++; } diff --git a/history.txt b/history.txt index 2c8856cd0..31672039f 100644 --- a/history.txt +++ b/history.txt @@ -1,4 +1,8 @@ -$Id: history.txt,v 1.298 2005/10/14 11:26:31 jrandom Exp $ +$Id: history.txt,v 1.299 2005/10/17 19:39:46 jrandom Exp $ + +2005-10-17 dust + * Exchange the remaining URL with EepGet in Sucker. + * Allow /TOPIC irc command. 2005-10-17 jrandom * Allow an env prop to configure whether we want to use the backwards