<NME> HttpClient.java
<BEF> package com.planet_ink.coffee_mud.Common.interfaces;
import com.planet_ink.coffee_mud.core.interfaces.*;
import com.planet_ink.coffee_mud.core.*;
import com.planet_ink.coffee_mud.core.collections.*;
import com.planet_ink.coffee_mud.Abilities.interfaces.*;
import com.planet_ink.coffee_mud.Areas.interfaces.*;
import com.planet_ink.coffee_mud.Behaviors.interfaces.*;
import com.planet_ink.coffee_mud.CharClasses.interfaces.*;
import com.planet_ink.coffee_mud.Commands.interfaces.*;
import com.planet_ink.coffee_mud.Common.interfaces.*;
import com.planet_ink.coffee_mud.Exits.interfaces.*;
import com.planet_ink.coffee_mud.Items.interfaces.*;
import com.planet_ink.coffee_mud.Libraries.interfaces.*;
import com.planet_ink.coffee_mud.Locales.interfaces.*;
import com.planet_ink.coffee_mud.Races.interfaces.*;

import java.util.List;

/* 
   Copyright 2000-2013 Bo Zimmerman

/*
   Copyright 2013-2022 Bo Zimmerman

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

	   http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
/**
 * A simple utility for making HTTP requests, which is
 * implemented as a builder-type object.
 */
public interface HttpClient extends Tickable, CMCommon
{
	/**
	 * Reads the simple raw return content from a given url and returns it as a
	 * byte array.  Good for getting files or web pages! Returns null if any
	 * @return null or a completed byte array of the returned content
	 */
	public byte[] getRawUrl(final String urlStr, final int maxLength, final int readTimeout);
}
	 * Calls GET on the given url, waiting no more than a few seconds for connection,
	 * and returns the headers from the response.
	 * @param urlStr the url to GET
	 * @return the map of headers
	 */
	public Map<String,List<String>> getHeaders(final String urlStr);

	/**
	 * An http request builder method that sets the maximum number of
	 * bytes that can be read by the request processor.
	 * @param bytes max bytes to read, or 0 for no limit
	 * @return this
	 */
	public HttpClient maxReadBytes(int bytes);

	/**
	 * An http request builder method that sets the maximum number of
	 * milliseconds that the reader will remain idle waiting for
	 * a byte of data.
	 * @param ms the maximum number of ms to wait, or 0 for unlimited
	 * @return this
	 */
	public HttpClient readTimeout(int ms);

	/**
	 * An http request builder method that sets the maximum number of
	 * milliseconds that the reader will remain idle waiting for
	 * a connection to occur.
	 * @param ms the maximum number of ms to wait, or 0 for unlimited
	 * @return this
	 */
	public HttpClient connectTimeout(int ms);

	/**
	 * An http request builder method that resets the client obj
	 * so that the connection can be used for another request.
	 * @return this
	 */
	public HttpClient reset();

	/**
	 * An http request builder method that sets the body to send.
	 * @param body the body to send
	 * @return this
	 */
	public HttpClient body(String body);

	/**
	 * An http request builder method that sets the body to send.
	 * @param body the body to send
	 * @return this
	 */
	public HttpClient body(byte[] body);

	/**
	 * An http request builder method that adds a header.
	 * @param key the header name
	 * @param value the header value
	 * @return this
	 */
	public HttpClient header(String key, String value);

	/**
	 * An http request builder method that sets the http method
	 * @param meth the method
	 * @return this
	 */
	public HttpClient method(Method meth);

	/**
	 * An http request builder method that causes this request
	 * to occur as a GET
	 * @param url the url to use
	 * @return this
	 * @throws java.io.IOException a socket error
	 */
	public HttpClient doGet(String url) throws IOException;

	/**
	 * An http request builder method that causes this request
	 * to occur as a HEAD
	 * @param url the url to use
	 * @return this
	 * @throws java.io.IOException a socket error
	 */
	public HttpClient doHead(String url) throws IOException;

	/**
	 * An http request builder method that causes this request
	 * to occur.
	 * @param url the url to use
	 * @return this
	 * @throws java.io.IOException a socket error
	 */
	public HttpClient doRequest(String url) throws IOException;

	/**
	 * Returns the headers in the response to this request
	 * @return the headers in the response to this request
	 */
	public Map<String,List<String>> getResponseHeaders();

	/**
	 * Returns the http status code from the response
	 * @return the http status code from the response
	 */
	public int getResponseCode();

	/**
	 * Returns an input stream to the body of the response
	 * to this request.
	 * @return an input stream to the body of the response
	 */
	public InputStream getResponseBody();

	/**
	 * Gets the length of the body of the response to this
	 * request.
	 * @return the length of the body
	 */
	public int getResponseContentLength();

	/**
	 * Closes this connection, entirely.  Always call this
	 * in a finally block!
	 */
	public void finished();

	/**
	 * HTTP Methods that are acceptable
	 * @author Bo Zimmerman
	 */
	public enum Method { GET, POST, HEAD }
}

<MSG> 

git-svn-id: svn://192.168.1.10/public/CoffeeMud@10458 0d6f1817-ed0e-0410-87c9-987e46238f29

<DFF> @@ -15,6 +15,7 @@ import com.planet_ink.coffee_mud.MOBS.interfaces.*;
 import com.planet_ink.coffee_mud.Races.interfaces.*;
 
 import java.util.List;
+import java.util.Map;
 
 /* 
    Copyright 2000-2013 Bo Zimmerman
@@ -46,4 +47,40 @@ public interface HttpClient extends Tickable, CMCommon
 	 * @return null or a completed byte array of the returned content
 	 */
 	public byte[] getRawUrl(final String urlStr, final int maxLength, final int readTimeout);
+	/**
+	 * Reads the simple raw return content from a given url and returns it as a 
+	 * byte array.  Good for getting files or web pages! Returns null if any
+	 * error occurs, including a 404, timeouts, or read failures.
+	 * @param urlStr the url to fetch
+	 * @param cookieStr cookies to send, or "", or null for none
+	 * @return null or a completed byte array of the returned content
+	 */
+	public byte[] getRawUrl(final String urlStr, String cookieStr);
+	/**
+	 * Reads the simple raw return content from a given url and returns it as a 
+	 * byte array.  Good for getting files or web pages! Returns null if any
+	 * error occurs, including a 404, timeouts, or read failures.
+	 * @param urlStr the url to fetch
+	 * @return null or a completed byte array of the returned content
+	 */
+	public byte[] getRawUrl(final String urlStr);
+	/**
+	 * Reads the simple raw return content from a given url and returns it as a 
+	 * byte array.  Good for getting files or web pages! Returns null if any
+	 * error occurs, including a 404, timeouts, or read failures.
+	 * @param urlStr the url to fetch
+	 * @param cookieStr cookies to send, or "", or null for none
+	 * @param maxLength the maximum size of the content, or 0 for any size
+	 * @param readTimeout the maximum time, in ms, to wait for connects, and reads
+	 * @return null or a completed byte array of the returned content
+	 */
+	public byte[] getRawUrl(final String urlStr, String cookieStr, final int maxLength, final int readTimeout);
+	
+	/**
+	 * Calls GET on the given url, waiting no more than a few seconds for connection,
+	 * and returns the headers from the response.
+	 * @param urlStr the url to GET
+	 * @return the map of headers
+	 */
+	public Map<String,List<String>> getHeaders(final String urlStr);
 }

{'commit': 'diff --git a/com/planet_ink/coffee_mud/Commands/Test.java b/com/planet_ink/coffee_mud/Commands/Test.java\nindex 4aa6f1597b..b9b4de7c00 100644\n--- a/com/planet_ink/coffee_mud/Commands/Test.java\n+++ b/com/planet_ink/coffee_mud/Commands/Test.java\n@@ -2,6 +2,7 @@ package com.planet_ink.coffee_mud.Commands;\n import com.planet_ink.coffee_mud.core.interfaces.*;\r\n import com.planet_ink.coffee_mud.core.*;\r\n import com.planet_ink.coffee_mud.core.collections.*;\r\n+import com.planet_ink.coffee_mud.core.exceptions.HTTPServerException;\r\n import com.planet_ink.coffee_mud.Abilities.interfaces.*;\r\n import com.planet_ink.coffee_mud.Areas.interfaces.*;\r\n import com.planet_ink.coffee_mud.Behaviors.interfaces.*;\r\n@@ -14,8 +15,15 @@ import com.planet_ink.coffee_mud.Libraries.interfaces.ColorLibrary;\n import com.planet_ink.coffee_mud.Locales.interfaces.*;\r\n import com.planet_ink.coffee_mud.MOBS.interfaces.*;\r\n import com.planet_ink.coffee_mud.Races.interfaces.*;\r\n+import com.planet_ink.coffee_mud.WebMacros.interfaces.WebMacro;\r\n+import com.planet_ink.miniweb.http.HTTPMethod;\r\n+import com.planet_ink.miniweb.http.MultiPartData;\r\n+import com.planet_ink.miniweb.interfaces.HTTPRequest;\r\n \r\n \r\n+import java.io.InputStream;\r\n+import java.net.InetAddress;\r\n+import java.net.UnknownHostException;\r\n import java.util.*;\r\n \r\n /*\r\n@@ -218,6 +226,7 @@ public class Test extends StdCommand\n \t\tif(commands.size()>1)\r\n \t\t{\r\n \t\t\tString what=((String)commands.elementAt(1)).toUpperCase().trim();\r\n+\t\t\tString rest=CMParms.combine(commands,2);\r\n \t\t\tif(what.equalsIgnoreCase("levelxptest"))\r\n \t\t\t{\r\n \t\t\t\tfor(int i=0;i<100;i++)\r\n@@ -1353,6 +1362,40 @@ public class Test extends StdCommand\n \t\t\t||(what.equalsIgnoreCase("Prop_ReqTattoo")))\r\n \t\t\t{\r\n \t\t\t\t\r\n+\t\t\t}\r\n+\t\t\tif(what.equalsIgnoreCase("yahoo")&&(mob.session()!=null))\r\n+\t\t\t{\r\n+\t\t\t\tWebMacro M=CMClass.getWebMacro("YAHOOGROUPS");\r\n+\t\t\t\ttry {\r\n+\t\t\t\t\tmob.tell(M.runMacro(new HTTPRequest(){\r\n+\t\t\t\t\t\tpublic final Hashtable<String,String> params=new Hashtable<String,String>();\r\n+\t\t\t\t\t\tpublic final Hashtable<String,Object> objects=new Hashtable<String,Object>();\r\n+\t\t\t\t\t\t@Override public String getHost() { return "localhost"; }\r\n+\t\t\t\t\t\t@Override public String getUrlPath() { return "localhost/file"; }\r\n+\t\t\t\t\t\t@Override public String getFullRequest() { return "GET "+getUrlPath(); }\r\n+\t\t\t\t\t\t@Override public String getUrlParameter(String name) { return params.get(name.toLowerCase()); }\r\n+\t\t\t\t\t\t@Override public boolean isUrlParameter(String name) { return params.containsKey(name.toLowerCase()); }\r\n+\t\t\t\t\t\t@Override public Map<String,String> getUrlParametersCopy() { return new XHashtable<String,String>(params); }\r\n+\t\t\t\t\t\t@Override public Set<String> getUrlParameters() { return params.keySet(); }\r\n+\t\t\t\t\t\t@Override public HTTPMethod getMethod() { return HTTPMethod.GET; }\r\n+\t\t\t\t\t\t@Override public String getHeader(String name) { return null; }\r\n+\t\t\t\t\t\t@Override public InetAddress getClientAddress() { try { return InetAddress.getLocalHost(); } catch (UnknownHostException e) { return null; } }\r\n+\t\t\t\t\t\t@Override public int getClientPort() { return 0; }\r\n+\t\t\t\t\t\t@Override public InputStream getBody() { return null; }\r\n+\t\t\t\t\t\t@Override public String getCookie(String name) { return null; }\r\n+\t\t\t\t\t\t@Override public Set<String> getCookieNames() { return objects.keySet(); }\r\n+\t\t\t\t\t\t@Override public List<MultiPartData> getMultiParts() { return new XVector<MultiPartData>(); }\r\n+\t\t\t\t\t\t@Override public double getSpecialEncodingAcceptability(String type) { return 0; }\r\n+\t\t\t\t\t\t@Override public String getFullHost() { return "localhost"; }\r\n+\t\t\t\t\t\t@Override public List<int[]> getRangeAZ() { return null; }\r\n+\t\t\t\t\t\t@Override public void addFakeUrlParameter(String name, String value) { params.put(name.toUpperCase(), value); }\r\n+\t\t\t\t\t\t@Override public void removeUrlParameter(String name) { params.remove(name.toUpperCase()); }\r\n+\t\t\t\t\t\t@Override public Map<String,Object> getRequestObjects() { return objects; }\r\n+\t\t\t\t\t\t@Override public float getHttpVer() { return (float)1.1; }\r\n+\t\t\t\t\t}, rest));\r\n+\t\t\t\t} catch (HTTPServerException e) {\r\n+\t\t\t\t\tmob.tell(e.getMessage());\r\n+\t\t\t\t}\r\n \t\t\t}\r\n \t\t\tif((what.equalsIgnoreCase("all"))||(what.equalsIgnoreCase("escapefilterbug")))\r\n \t\t\t{\r\ndiff --git a/com/planet_ink/coffee_mud/Common/DefaultHttpClient.java b/com/planet_ink/coffee_mud/Common/DefaultHttpClient.java\nindex 2422fcb35a..dc9f99d3dd 100644\n--- a/com/planet_ink/coffee_mud/Common/DefaultHttpClient.java\n+++ b/com/planet_ink/coffee_mud/Common/DefaultHttpClient.java\n@@ -55,7 +55,20 @@ public class DefaultHttpClient implements HttpClient, Cloneable\n \t}\r\n \tpublic void initializeClass(){}\r\n \r\n+\tpublic byte[] getRawUrl(final String urlStr, String cookieStr)\r\n+\t{\r\n+\t\treturn getRawUrl(urlStr, cookieStr, 1024*1024*10, 10000);\r\n+\t}\r\n+\tpublic byte[] getRawUrl(final String urlStr)\r\n+\t{\r\n+\t\treturn getRawUrl(urlStr, null, 1024*1024*10, 10000);\r\n+\t}\r\n \tpublic byte[] getRawUrl(final String urlStr, final int maxLength, final int readTimeout)\r\n+\t{\r\n+\t\treturn getRawUrl(urlStr, null, maxLength, readTimeout);\r\n+\t}\r\n+\t\r\n+\tpublic byte[] getRawUrl(final String urlStr, String cookieStr, final int maxLength, final int readTimeout)\r\n \t{\r\n \t\tHttpURLConnection connection=null;\r\n \t\ttry {\r\n@@ -65,6 +78,33 @@ public class DefaultHttpClient implements HttpClient, Cloneable\n \t\t\tconnection.setInstanceFollowRedirects(true);\r\n \t\t\tconnection.setConnectTimeout(readTimeout);\r\n \t\t\tconnection.setRequestMethod("GET");\r\n+\t\t\tif((cookieStr!=null)&&(cookieStr.length()>0))\r\n+\t\t\t\tconnection.setRequestProperty("Cookie", cookieStr);\r\n+\t\t\tconnection.connect();\r\n+\t\t\tif (connection.getResponseCode() == 302) {\r\n+\t\t\t\tfor(String key : connection.getHeaderFields().keySet())\r\n+\t\t\t\t{\r\n+\t\t\t\t\tSystem.out.println(key+"="+connection.getHeaderField(key));\r\n+\t\t\t\t}\r\n+\t\t\t\tInputStream in=connection.getInputStream();\r\n+\t\t\t\tint len=connection.getContentLength();\r\n+\t\t\t\tif((len > 0)&&((maxLength==0)||(len<=maxLength)))\r\n+\t\t\t\t{\r\n+\t\t\t\t\tbyte[] buf=new byte[len];\r\n+\t\t\t\t\tint read=in.read(buf);\r\n+\t\t\t\t\tint readTotal=read;\r\n+\t\t\t\t\twhile(readTotal < len)\r\n+\t\t\t\t\t{\r\n+\t\t\t\t\t\tif(read<0)\r\n+\t\t\t\t\t\t\treturn null;\r\n+\t\t\t\t\t\tread=in.read(buf, readTotal, len-readTotal);\r\n+\t\t\t\t\t\tif(read>0)\r\n+\t\t\t\t\t\t\treadTotal+=read;\r\n+\t\t\t\t\t}\r\n+\t\t\t\t\treturn buf;\r\n+\t\t\t\t}\r\n+\t\t\t}\r\n+\t\t\t\t\r\n \t\t\tif (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {\r\n \t\t\t\tInputStream in=connection.getInputStream();\r\n \t\t\t\tint len=connection.getContentLength();\r\n@@ -95,6 +135,30 @@ public class DefaultHttpClient implements HttpClient, Cloneable\n \t\treturn null;\r\n \t}\r\n \r\n+\tpublic Map<String,List<String>> getHeaders(final String urlStr)\r\n+\t{\r\n+\t\tHttpURLConnection connection=null;\r\n+\t\ttry {\r\n+\t\t\tURL url = new URL(urlStr);\r\n+\t\t\tconnection = (HttpURLConnection) url.openConnection();\r\n+\t\t\tconnection.setReadTimeout(3000);\r\n+\t\t\tconnection.setInstanceFollowRedirects(true);\r\n+\t\t\tconnection.setConnectTimeout(3000);\r\n+\t\t\tconnection.setRequestMethod("GET");\r\n+\t\t\t//connection.setDoInput(false);\r\n+\t\t\t//connection.setDoOutput(false);\r\n+\t\t\tconnection.connect();\r\n+\t\t\treturn connection.getHeaderFields();\r\n+\t\t} catch (Exception e) {\r\n+\t\t\tLog.errOut("HttpClient",e);\r\n+\t\t\treturn null;\r\n+\t\t}\r\n+\t\tfinally {\r\n+\t\t\tif(connection!=null)\r\n+\t\t\t\tconnection.disconnect();\r\n+\t\t}\r\n+\t}\r\n+\r\n \t@Override\r\n     public long getTickStatus() { return tickStatus; }\r\n \r\ndiff --git a/com/planet_ink/coffee_mud/Common/interfaces/HttpClient.java b/com/planet_ink/coffee_mud/Common/interfaces/HttpClient.java\nindex 1745e7691b..270aebdca2 100644\n--- a/com/planet_ink/coffee_mud/Common/interfaces/HttpClient.java\n+++ b/com/planet_ink/coffee_mud/Common/interfaces/HttpClient.java\n@@ -15,6 +15,7 @@ import com.planet_ink.coffee_mud.MOBS.interfaces.*;\n import com.planet_ink.coffee_mud.Races.interfaces.*;\r\n \r\n import java.util.List;\r\n+import java.util.Map;\r\n \r\n /* \r\n    Copyright 2000-2013 Bo Zimmerman\r\n@@ -46,4 +47,40 @@ public interface HttpClient extends Tickable, CMCommon\n \t * @return null or a completed byte array of the returned content\r\n \t */\r\n \tpublic byte[] getRawUrl(final String urlStr, final int maxLength, final int readTimeout);\r\n+\t/**\r\n+\t * Reads the simple raw return content from a given url and returns it as a \r\n+\t * byte array.  Good for getting files or web pages! Returns null if any\r\n+\t * error occurs, including a 404, timeouts, or read failures.\r\n+\t * @param urlStr the url to fetch\r\n+\t * @param cookieStr cookies to send, or "", or null for none\r\n+\t * @return null or a completed byte array of the returned content\r\n+\t */\r\n+\tpublic byte[] getRawUrl(final String urlStr, String cookieStr);\r\n+\t/**\r\n+\t * Reads the simple raw return content from a given url and returns it as a \r\n+\t * byte array.  Good for getting files or web pages! Returns null if any\r\n+\t * error occurs, including a 404, timeouts, or read failures.\r\n+\t * @param urlStr the url to fetch\r\n+\t * @return null or a completed byte array of the returned content\r\n+\t */\r\n+\tpublic byte[] getRawUrl(final String urlStr);\r\n+\t/**\r\n+\t * Reads the simple raw return content from a given url and returns it as a \r\n+\t * byte array.  Good for getting files or web pages! Returns null if any\r\n+\t * error occurs, including a 404, timeouts, or read failures.\r\n+\t * @param urlStr the url to fetch\r\n+\t * @param cookieStr cookies to send, or "", or null for none\r\n+\t * @param maxLength the maximum size of the content, or 0 for any size\r\n+\t * @param readTimeout the maximum time, in ms, to wait for connects, and reads\r\n+\t * @return null or a completed byte array of the returned content\r\n+\t */\r\n+\tpublic byte[] getRawUrl(final String urlStr, String cookieStr, final int maxLength, final int readTimeout);\r\n+\t\r\n+\t/**\r\n+\t * Calls GET on the given url, waiting no more than a few seconds for connection,\r\n+\t * and returns the headers from the response.\r\n+\t * @param urlStr the url to GET\r\n+\t * @return the map of headers\r\n+\t */\r\n+\tpublic Map<String,List<String>> getHeaders(final String urlStr);\r\n }\r\ndiff --git a/com/planet_ink/coffee_mud/WebMacros/YahooGroups.java b/com/planet_ink/coffee_mud/WebMacros/YahooGroups.java\nindex 7fdedde374..bc361bb208 100644\n--- a/com/planet_ink/coffee_mud/WebMacros/YahooGroups.java\n+++ b/com/planet_ink/coffee_mud/WebMacros/YahooGroups.java\n@@ -37,8 +37,7 @@ import java.util.*;\n */\r\n public class YahooGroups extends StdWebMacro\r\n {\r\n-\tprivate final String id=this.getClass().getName().substring(this.getClass().getName().lastIndexOf(\'.\')+1);\r\n-\tpublic String name(){return id;}\r\n+\tpublic String name(){return "YahooGroups";}\r\n \tpublic boolean isAdminMacro()\t{return true;}\r\n \r\n \t\r\n@@ -47,32 +46,65 @@ public class YahooGroups extends StdWebMacro\n \t\tjava.util.Map<String,String> parms=parseParms(parm);\r\n \t\tString command=parms.get("COMMAND");\r\n \t\tif(command==null)\r\n-\t\t\treturn "@break@";\r\n+\t\t\treturn " @break@";\r\n \t\tif(command.equalsIgnoreCase("LOGIN"))\r\n \t\t{\r\n \t\t\tHttpClient H=(HttpClient)CMClass.getCommon("DefaultHttpClient");\r\n \t\t\tString user=parms.get("USER");\r\n \t\t\tif(user==null)\r\n-\t\t\t\treturn "@break@";\r\n+\t\t\t\treturn " @break@";\r\n \t\t\tString password=parms.get("PASSWORD");\r\n \t\t\tif(password==null)\r\n-\t\t\t\treturn "@break@";\r\n+\t\t\t\treturn " @break@";\r\n \t\t\ttry {\r\n-\t\t\t\tbyte[] b = H.getRawUrl("http://login.yahoo.com/config/login?login="+URLEncoder.encode(user,"UTF8")+"&passwd="+URLEncoder.encode(user,"UTF8"), 0, 10000);\r\n-\t\t\t\tif(b==null)\r\n+\t\t\t\tMap<String,List<String>> M = H.getHeaders("http://login.yahoo.com/config/login?login="+URLEncoder.encode(user,"UTF8")+"&passwd="+URLEncoder.encode(password,"UTF8"));\r\n+\t\t\t\tif(M==null)\r\n \t\t\t\t\treturn "Fail: Http error";\r\n-\t\t\t\treturn new String(b);\r\n+\t\t\t\tStringBuilder cookieSet=new StringBuilder("");\r\n+\t\t\t\tList<String> cookies=M.get("Set-Cookie");\r\n+\t\t\t\tfor(String val : cookies)\r\n+\t\t\t\t{\r\n+\t\t\t\t\tif(cookieSet.length()>0)\r\n+\t\t\t\t\t\tcookieSet.append(" ; ");\r\n+\t\t\t\t\tint x=val.indexOf(\';\');\r\n+\t\t\t\t\tcookieSet.append((x>=0)?val.substring(0,x).trim():val.trim());\r\n+\t\t\t\t}\r\n+\t\t\t\treturn cookieSet.toString().replace(\'&\',\'#\');\r\n \t\t\t} catch (UnsupportedEncodingException e) {\r\n \t\t\t\tLog.errOut(Thread.currentThread().getName(),e);\r\n \t\t\t}\r\n-\t\t\treturn "@break@";\r\n+\t\t\treturn " @break@";\r\n \t\t}\r\n \t\tString url=parms.get("URL");\r\n \t\tif(url==null)\r\n-\t\t\treturn "@break@";\r\n+\t\t\treturn " @break@";\r\n \t\tif(command.equalsIgnoreCase("NUMMSGS"))\r\n \t\t{\r\n-\t\t\t\r\n+\t\t\tString token=parms.get("TOKEN");\r\n+\t\t\tif(token==null)\r\n+\t\t\t\treturn " @break@";\r\n+\t\t\tHttpClient H=(HttpClient)CMClass.getCommon("DefaultHttpClient");\r\n+\t\t\tbyte[] b=H.getRawUrl(url,token.replace(\'#\',\'&\'));\r\n+\t\t\tif(b==null)\r\n+\t\t\t\treturn "Failed: Bad login token?";\r\n+\t\t\tStringBuffer s=new StringBuffer(new String(b));\r\n+\t\t\tCMStrings.convertHtmlToText(s);\r\n+\t\t\tString txt=s.toString();\r\n+\t\t\tint x=txt.indexOf(" of ");\r\n+\t\t\tint num=-1;\r\n+\t\t\twhile((num<0)&&(x>=0))\r\n+\t\t\t{\r\n+\t\t\t\tif(Character.isDigit(txt.charAt(x+4)))\r\n+\t\t\t\t{\r\n+\t\t\t\t\tint y=4;\r\n+\t\t\t\t\twhile(Character.isDigit(txt.charAt(x+y)))\r\n+\t\t\t\t\t\ty++;\r\n+\t\t\t\t\treturn Integer.toString(CMath.s_int(txt.substring(x+4,x+y)));\r\n+\t\t\t\t}\r\n+\t\t\t\telse\r\n+\t\t\t\t\tx=txt.indexOf(" of ",x+1);\r\n+\t\t\t}\r\n+\t\t\treturn "Fail: no numbers found";\r\n \t\t}\r\n \t\treturn "";\r\n \t}\r\n', 'commit_subject': '', 'repo_name': 'bozimmerman/CoffeeMud', 'committer': {'name': 'bozimmerman', 'email': 'dc45fe023482b3b890b5e574e53c1d051f45b1ef@zimmers.net', 'time_sec': '1372270547', 'tz_offset': '0', 'date': {'seconds': '1372270547'}}, 'commit_tree': 'c0ed713aa8f37f4fe557575530933aa7da59155c', 'commit_message': '\n\ngit-svn-id: svn://192.168.1.10/public/CoffeeMud@10458 0d6f1817-ed0e-0410-87c9-987e46238f29\n', 'language_name': 'JavaScript', 'license': 'apache-2.0', 'hunks': '@@ -15,6 +15,7 @@ import com.planet_ink.coffee_mud.MOBS.interfaces.*;\n import com.planet_ink.coffee_mud.Races.interfaces.*;\r\n \r\n import java.util.List;\r\n+import java.util.Map;\r\n \r\n /* \r\n    Copyright 2000-2013 Bo Zimmerman\r\n@@ -46,4 +47,40 @@ public interface HttpClient extends Tickable, CMCommon\n \t * @return null or a completed byte array of the returned content\r\n \t */\r\n \tpublic byte[] getRawUrl(final String urlStr, final int maxLength, final int readTimeout);\r\n+\t/**\r\n+\t * Reads the simple raw return content from a given url and returns it as a \r\n+\t * byte array.  Good for getting files or web pages! Returns null if any\r\n+\t * error occurs, including a 404, timeouts, or read failures.\r\n+\t * @param urlStr the url to fetch\r\n+\t * @param cookieStr cookies to send, or "", or null for none\r\n+\t * @return null or a completed byte array of the returned content\r\n+\t */\r\n+\tpublic byte[] getRawUrl(final String urlStr, String cookieStr);\r\n+\t/**\r\n+\t * Reads the simple raw return content from a given url and returns it as a \r\n+\t * byte array.  Good for getting files or web pages! Returns null if any\r\n+\t * error occurs, including a 404, timeouts, or read failures.\r\n+\t * @param urlStr the url to fetch\r\n+\t * @return null or a completed byte array of the returned content\r\n+\t */\r\n+\tpublic byte[] getRawUrl(final String urlStr);\r\n+\t/**\r\n+\t * Reads the simple raw return content from a given url and returns it as a \r\n+\t * byte array.  Good for getting files or web pages! Returns null if any\r\n+\t * error occurs, including a 404, timeouts, or read failures.\r\n+\t * @param urlStr the url to fetch\r\n+\t * @param cookieStr cookies to send, or "", or null for none\r\n+\t * @param maxLength the maximum size of the content, or 0 for any size\r\n+\t * @param readTimeout the maximum time, in ms, to wait for connects, and reads\r\n+\t * @return null or a completed byte array of the returned content\r\n+\t */\r\n+\tpublic byte[] getRawUrl(final String urlStr, String cookieStr, final int maxLength, final int readTimeout);\r\n+\t\r\n+\t/**\r\n+\t * Calls GET on the given url, waiting no more than a few seconds for connection,\r\n+\t * and returns the headers from the response.\r\n+\t * @param urlStr the url to GET\r\n+\t * @return the map of headers\r\n+\t */\r\n+\tpublic Map<String,List<String>> getHeaders(final String urlStr);\r\n }\r\n', 'addition_count': 37, 'deletion_count': 0, 'src_file': 'a/com/planet_ink/coffee_mud/Common/interfaces/HttpClient.java', 'tgt_file': 'b/com/planet_ink/coffee_mud/Common/interfaces/HttpClient.java', 'file_extension': '.java', 'before_file': 'package com.planet_ink.coffee_mud.Common.interfaces;\nimport com.planet_ink.coffee_mud.core.interfaces.*;\nimport com.planet_ink.coffee_mud.core.*;\nimport com.planet_ink.coffee_mud.core.collections.*;\nimport com.planet_ink.coffee_mud.Abilities.interfaces.*;\nimport com.planet_ink.coffee_mud.Areas.interfaces.*;\nimport com.planet_ink.coffee_mud.Behaviors.interfaces.*;\nimport com.planet_ink.coffee_mud.CharClasses.interfaces.*;\nimport com.planet_ink.coffee_mud.Commands.interfaces.*;\nimport com.planet_ink.coffee_mud.Common.interfaces.*;\nimport com.planet_ink.coffee_mud.Exits.interfaces.*;\nimport com.planet_ink.coffee_mud.Items.interfaces.*;\nimport com.planet_ink.coffee_mud.Libraries.interfaces.*;\nimport com.planet_ink.coffee_mud.Locales.interfaces.*;\nimport com.planet_ink.coffee_mud.Races.interfaces.*;\r\n\r\nimport java.util.List;\r\n\r\n/* \r\n   Copyright 2000-2013 Bo Zimmerman\r\n\n/*\n   Copyright 2013-2022 Bo Zimmerman\n\n   Licensed under the Apache License, Version 2.0 (the "License");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n\t   http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an "AS IS" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n*/\n/**\n * A simple utility for making HTTP requests, which is\n * implemented as a builder-type object.\n */\npublic interface HttpClient extends Tickable, CMCommon\n{\n\t/**\n\t * Reads the simple raw return content from a given url and returns it as a\n\t * byte array.  Good for getting files or web pages! Returns null if any\n\t * @return null or a completed byte array of the returned content\r\n\t */\r\n\tpublic byte[] getRawUrl(final String urlStr, final int maxLength, final int readTimeout);\r\n}\r\n\t * Calls GET on the given url, waiting no more than a few seconds for connection,\n\t * and returns the headers from the response.\n\t * @param urlStr the url to GET\n\t * @return the map of headers\n\t */\n\tpublic Map<String,List<String>> getHeaders(final String urlStr);\n\n\t/**\n\t * An http request builder method that sets the maximum number of\n\t * bytes that can be read by the request processor.\n\t * @param bytes max bytes to read, or 0 for no limit\n\t * @return this\n\t */\n\tpublic HttpClient maxReadBytes(int bytes);\n\n\t/**\n\t * An http request builder method that sets the maximum number of\n\t * milliseconds that the reader will remain idle waiting for\n\t * a byte of data.\n\t * @param ms the maximum number of ms to wait, or 0 for unlimited\n\t * @return this\n\t */\n\tpublic HttpClient readTimeout(int ms);\n\n\t/**\n\t * An http request builder method that sets the maximum number of\n\t * milliseconds that the reader will remain idle waiting for\n\t * a connection to occur.\n\t * @param ms the maximum number of ms to wait, or 0 for unlimited\n\t * @return this\n\t */\n\tpublic HttpClient connectTimeout(int ms);\n\n\t/**\n\t * An http request builder method that resets the client obj\n\t * so that the connection can be used for another request.\n\t * @return this\n\t */\n\tpublic HttpClient reset();\n\n\t/**\n\t * An http request builder method that sets the body to send.\n\t * @param body the body to send\n\t * @return this\n\t */\n\tpublic HttpClient body(String body);\n\n\t/**\n\t * An http request builder method that sets the body to send.\n\t * @param body the body to send\n\t * @return this\n\t */\n\tpublic HttpClient body(byte[] body);\n\n\t/**\n\t * An http request builder method that adds a header.\n\t * @param key the header name\n\t * @param value the header value\n\t * @return this\n\t */\n\tpublic HttpClient header(String key, String value);\n\n\t/**\n\t * An http request builder method that sets the http method\n\t * @param meth the method\n\t * @return this\n\t */\n\tpublic HttpClient method(Method meth);\n\n\t/**\n\t * An http request builder method that causes this request\n\t * to occur as a GET\n\t * @param url the url to use\n\t * @return this\n\t * @throws java.io.IOException a socket error\n\t */\n\tpublic HttpClient doGet(String url) throws IOException;\n\n\t/**\n\t * An http request builder method that causes this request\n\t * to occur as a HEAD\n\t * @param url the url to use\n\t * @return this\n\t * @throws java.io.IOException a socket error\n\t */\n\tpublic HttpClient doHead(String url) throws IOException;\n\n\t/**\n\t * An http request builder method that causes this request\n\t * to occur.\n\t * @param url the url to use\n\t * @return this\n\t * @throws java.io.IOException a socket error\n\t */\n\tpublic HttpClient doRequest(String url) throws IOException;\n\n\t/**\n\t * Returns the headers in the response to this request\n\t * @return the headers in the response to this request\n\t */\n\tpublic Map<String,List<String>> getResponseHeaders();\n\n\t/**\n\t * Returns the http status code from the response\n\t * @return the http status code from the response\n\t */\n\tpublic int getResponseCode();\n\n\t/**\n\t * Returns an input stream to the body of the response\n\t * to this request.\n\t * @return an input stream to the body of the response\n\t */\n\tpublic InputStream getResponseBody();\n\n\t/**\n\t * Gets the length of the body of the response to this\n\t * request.\n\t * @return the length of the body\n\t */\n\tpublic int getResponseContentLength();\n\n\t/**\n\t * Closes this connection, entirely.  Always call this\n\t * in a finally block!\n\t */\n\tpublic void finished();\n\n\t/**\n\t * HTTP Methods that are acceptable\n\t * @author Bo Zimmerman\n\t */\n\tpublic enum Method { GET, POST, HEAD }\n}\n', 'message': '\n\ngit-svn-id: svn://192.168.1.10/public/CoffeeMud@10458 0d6f1817-ed0e-0410-87c9-987e46238f29\n', 'author_name': 'bozimmerman', 'lang': 'java'}