removed unused anomichttpd code after migration to jetty

pull/1/head
Michael Peter Christen 11 years ago
parent b461a27abb
commit 84167adb49

@ -7,9 +7,6 @@
# you must delete the yacy.conf file in DATA/SETTINGS
# ----------------------------------------------------------------------------
# the HTTP service configurations
# choices are jetty or anomic
defaulthttpserver=jetty
# port number where the server should bind to
port = 8090

@ -42,7 +42,6 @@ import net.yacy.peers.Seed;
import net.yacy.search.Switchboard;
import net.yacy.search.query.AccessTracker;
import net.yacy.search.query.QueryParams;
import net.yacy.server.serverCore;
import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch;
import net.yacy.server.serverAccessTracker.Track;
@ -93,16 +92,6 @@ public class AccessTracker_p {
prop.put("page_num", entCount);
entCount = 0;
try {
for (final Map.Entry<String, Integer> bfe: serverCore.bfHost.entrySet()) {
prop.putHTML("page_bflist_" + entCount + "_host", bfe.getKey());
prop.putNum("page_bflist_" + entCount + "_countSecond", bfe.getValue());
entCount++;
}
} catch (final ConcurrentModificationException e) {
// we don't want to synchronize this
ConcurrentLog.logException(e);
}
prop.put("page_bflist", entCount);
} else if (page == 1) {
String host = (post == null) ? "" : post.get("host", "");

@ -27,9 +27,6 @@
//javac -classpath .:../classes Network.java
//if the shell's current path is HTROOT
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -37,15 +34,10 @@ import java.util.Set;
import net.yacy.cora.protocol.ConnectionInfo;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.http.YaCyHttpServer;
import net.yacy.peers.PeerActions;
import net.yacy.peers.Seed;
import net.yacy.search.Switchboard;
import net.yacy.server.serverCore;
import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch;
import net.yacy.server.serverCore.Session;
public final class Connections_p {
@ -64,7 +56,6 @@ public final class Connections_p {
doNameLookup = post.getBoolean("nameLookup");
if (post.containsKey("closeServerSession")) {
final String sessionName = post.get("closeServerSession", null);
sb.closeSessions(sessionName);
prop.put(serverObjects.ACTION_LOCATION,"");
return prop;
}
@ -73,69 +64,7 @@ public final class Connections_p {
}
// waiting for all threads to finish
int idx = 0, numActiveRunning = 0, numActivePending = 0;
boolean dark = true;
for (final Session s: serverCore.getJobList()) {
if (!s.isAlive()) continue;
// get the session runtime
final long sessionTime = s.getTime();
// get the request command line
String commandLine = s.getCommandLine();
final boolean blockingRequest = (commandLine == null);
final int commandCount = s.getCommandCount();
// get the source ip address and port
final InetAddress userAddress = s.getUserAddress();
final int userPort = s.getUserPort();
if (userAddress == null) {
continue;
}
String prot = "http"; // only httpd sessions listed
// determining if the source is a yacy host
Seed seed = null;
if (doNameLookup) {
seed = sb.peers.lookupByIP(userAddress, -1, true, false, false);
if (seed != null && (seed.hash.equals(sb.peers.mySeed().hash)) &&
(!seed.get(Seed.PORT,"").equals(Integer.toString(userPort)))) {
seed = null;
}
}
prop.put("list_" + idx + "_dark", dark ? "1" : "0");
dark = !dark;
try {
prop.put("list_" + idx + "_serverSessionID",URLEncoder.encode(s.getName(),"UTF8"));
} catch (final UnsupportedEncodingException e) {
// TODO Auto-generated catch block
ConcurrentLog.logException(e);
}
prop.putHTML("list_" + idx + "_sessionName", s.getName());
prop.put("list_" + idx + "_proto", prot);
if (sessionTime > 1000*60) {
prop.put("list_" + idx + "_ms", "0");
prop.put("list_" + idx + "_ms_duration",PeerActions.formatInterval(sessionTime));
} else {
prop.put("list_" + idx + "_ms", "1");
prop.putNum("list_" + idx + "_ms_duration", sessionTime);
}
prop.putHTML("list_" + idx + "_source",(seed!=null)?seed.getName()+".yacy":userAddress.getHostAddress()+":"+userPort);
prop.putHTML("list_" + idx + "_dest", "-");
if (blockingRequest) {
prop.put("list_" + idx + "_running", "0");
prop.putNum("list_" + idx + "_running_reqNr", commandCount+1);
numActivePending++;
} else {
prop.put("list_" + idx + "_running", "1");
prop.put("list_" + idx + "_running_command", commandLine==null ? "" :commandLine);
numActiveRunning++;
}
prop.putNum("list_" + idx + "_used", commandCount);
idx++;
}
int idx = 0, numActivePending = 0;
prop.put("list", idx);
prop.putNum("numMax", httpd.getMaxSessionCount());

@ -52,7 +52,7 @@ public final class hello {
// example:
// http://localhost:8090/yacy/hello.html?count=1&seed=p|{Hash=sCJ6Tq8T0N9x,Port=8090,PeerType=junior}
// http://localhost:8090/yacy/hello.html?count=10&seed=z|H4sIAAAAAAAAADWQW2vDMAyF_81eJork3GyGX-YxGigly2WFvZTQijbQJsHx1pWx_z7nMj1J4ug7B_2s6-GsP5q3G-G6vBz2e0iz8t6zfuBr7-5PUNanQfulhqyzTkuUCFXvmitrBJtq4ed3tkPTtRpXhIiRDAmq0uhHFIiQMduJ-NXYU9NCbrrP1vnjIdUqgk09uIK51V6rMBRIilAo2NajwzfhGcx8QUKsEIp5iCJo-eaTVUXPfPQ4k5dm4pp8NzaESsLzS-14QVNIMlA-ka2m1JuZJJWIBRwPo0GIIiYp4zCSkC5GQSLiJIah0p6X_rvlS-MTbWdhkCSBIni9jA_rfP3-Ae1Oye9dAQAA
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) throws InterruptedException {
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
final long start = System.currentTimeMillis();
@ -146,7 +146,6 @@ public final class hello {
!clientip.equals(reportedip) &&
clientversion >= yacyVersion.YACY_SUPPORTS_PORT_FORWARDING &&
magic != 0) {
serverCore.checkInterruption();
// try first the reportedip, since this may be a connect from a port-forwarding host
prop.put("yourip", reportedip);
@ -171,7 +170,6 @@ public final class hello {
}
if (isNotLocal) {
serverCore.checkInterruption();
prop.put("yourip", clientip);
remoteSeed.setIP(clientip);
@ -221,7 +219,6 @@ public final class hello {
"' to '" + prop.get(Seed.YOURTYPE) + "'.");
}
serverCore.checkInterruption();
final StringBuilder seeds = new StringBuilder(768);
// attach some more seeds, as requested
if (sb.peers.sizeConnected() > 0) {

@ -53,13 +53,12 @@ import net.yacy.peers.Seed;
import net.yacy.repository.Blacklist.BlacklistType;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
import net.yacy.server.serverCore;
import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch;
public final class transferRWI {
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) throws InterruptedException {
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
// return variable that accumulates replacements
final Switchboard sb = (Switchboard) env;
@ -170,7 +169,6 @@ public final class transferRWI {
int count = 0;
Set<String> testids = new HashSet<String>();
while (it.hasNext()) {
serverCore.checkInterruption();
estring = it.next();
count++;
if (count > 1000) break; // protection against flooding
@ -208,7 +206,6 @@ public final class transferRWI {
} catch (final Exception e) {
ConcurrentLog.logException(e);
}
serverCore.checkInterruption();
// check if we need to ask for the corresponding URL
testids.add(ASCII.String(urlHash));

@ -47,13 +47,12 @@ import net.yacy.peers.Seed;
import net.yacy.repository.Blacklist.BlacklistType;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
import net.yacy.server.serverCore;
import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch;
public final class transferURL {
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) throws InterruptedException {
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) {
final long start = System.currentTimeMillis();
long freshdate = 0;
try {freshdate = GenericFormatter.SHORT_DAY_FORMATTER.parse("20061101").getTime();} catch (final ParseException e1) {}
@ -94,7 +93,6 @@ public final class transferURL {
URIMetadataRow lEntry;
Map<String, URIMetadataRow> lEm = new HashMap<String, URIMetadataRow>();
for (int i = 0; i < urlc; i++) {
serverCore.checkInterruption();
// read new lurl-entry
urls = post.get("url" + i);

@ -26,13 +26,15 @@ package net.yacy.http;
import java.io.IOException;
import java.net.MalformedURLException;
import net.yacy.cora.document.id.MultiProtocolURL;
import javax.servlet.http.HttpServletResponse;
import net.yacy.cora.document.id.MultiProtocolURL;
import net.yacy.cora.protocol.Domains;
import net.yacy.search.Switchboard;
import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.security.RoleInfo;
import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.security.UserDataConstraint;
import org.eclipse.jetty.server.AbstractHttpConnection;
@ -86,7 +88,7 @@ public class Jetty8YaCySecurityHandler extends SecurityHandler {
response.sendRedirect(url);
}
else
response.sendError(Response.SC_FORBIDDEN,"!Integral");
response.sendError(HttpServletResponse.SC_FORBIDDEN,"!Integral");
request.setHandled(true);
return false;
@ -109,7 +111,7 @@ public class Jetty8YaCySecurityHandler extends SecurityHandler {
response.sendRedirect(url);
}
else
response.sendError(Response.SC_FORBIDDEN,"!Confidential");
response.sendError(HttpServletResponse.SC_FORBIDDEN,"!Confidential");
request.setHandled(true);
return false;

@ -61,11 +61,9 @@ public class ProxyHandler extends AbstractRemoteHandler implements Handler {
static RequestHeader convertHeaderFromJetty(HttpServletRequest request) {
RequestHeader result = new RequestHeader();
@SuppressWarnings("unchecked")
Enumeration<String> headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
@SuppressWarnings("unchecked")
Enumeration<String> headers = request.getHeaders(headerName);
while(headers.hasMoreElements()) {
String header = headers.nextElement();
@ -94,7 +92,7 @@ public class ProxyHandler extends AbstractRemoteHandler implements Handler {
final String httpVer = request.getHeader(HeaderFramework.CONNECTION_PROP_HTTP_VER);
setViaHeader (proxyHeaders, httpVer);
proxyHeaders.remove(RequestHeader.KEEP_ALIVE);
proxyHeaders.remove(RequestHeader.CONTENT_LENGTH);
proxyHeaders.remove(HeaderFramework.CONTENT_LENGTH);
final HTTPClient client = new HTTPClient(ClientIdentification.yacyProxyAgent);
int timeout = 60000;

@ -45,6 +45,7 @@ import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.analysis.Classification;
import net.yacy.cora.protocol.HeaderFramework;
@ -65,13 +66,13 @@ import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch;
import net.yacy.server.servletProperties;
import net.yacy.visualization.RasterPlotter;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.eclipse.jetty.http.HttpHeaders;
import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.WriterOutputStream;
@ -470,7 +471,7 @@ public class YaCyDefaultServlet extends HttpServlet {
HttpServletResponse response,
boolean include,
Resource resource,
Enumeration reqRanges)
Enumeration<String> reqRanges)
throws IOException {
final long content_length = resource.length();
@ -494,7 +495,7 @@ public class YaCyDefaultServlet extends HttpServlet {
}
} else {
// Parse the satisfiable ranges
List ranges = InclusiveByteRange.satisfiableRanges(reqRanges, content_length);
List<?> ranges = InclusiveByteRange.satisfiableRanges(reqRanges, content_length);
// if there are no satisfiable ranges, send 416 response
if (ranges == null || ranges.size() == 0) {
@ -727,7 +728,6 @@ public class YaCyDefaultServlet extends HttpServlet {
if ((targetClass != null)) {
serverObjects args = new serverObjects();
@SuppressWarnings("unchecked")
Enumeration<String> argNames = request.getParameterNames();
while (argNames.hasMoreElements()) {
String argName = argNames.nextElement();
@ -735,7 +735,6 @@ public class YaCyDefaultServlet extends HttpServlet {
}
//TODO: for SSI request, local parameters are added as attributes, put them back as parameter for the legacy request
// likely this should be implemented via httpservletrequestwrapper to supply complete parameters
@SuppressWarnings("unchecked")
Enumeration<String> attNames = request.getAttributeNames();
while (attNames.hasMoreElements()) {
String argName = attNames.nextElement();
@ -900,7 +899,7 @@ public class YaCyDefaultServlet extends HttpServlet {
}
// parse SSI line and include resource
protected void parseSSI(final net.yacy.cora.util.ByteBuffer in, final int off, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
protected void parseSSI(final net.yacy.cora.util.ByteBuffer in, final int off, HttpServletRequest request, HttpServletResponse response) throws ServletException {
if (in.startsWith("<!--#include virtual=\"".getBytes(), off)) {
final int q = in.indexOf("\"".getBytes(), off + 22);
if (q > 0) {

@ -60,9 +60,8 @@ public class YaCyLegacyCredential extends Credential {
if(credentials instanceof String) {
final String pw = (String) credentials;
return calcHash(pw).equals(this.hash);
} else {
throw new UnsupportedOperationException();
}
throw new UnsupportedOperationException();
}
/**

@ -85,212 +85,211 @@ public class YaCyProxyServlet extends ProxyServlet implements Servlet {
if (!continuation.isInitial()) {
response.sendError(HttpServletResponse.SC_GATEWAY_TIMEOUT); // Need better test that isInitial
return;
} else {
URL proxyurl = null;
String strARGS = request.getQueryString();
if (strARGS == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,"url parameter missing");
return;
}
}
URL proxyurl = null;
String strARGS = request.getQueryString();
if (strARGS == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,"url parameter missing");
return;
}
if (strARGS.startsWith("action=")) {
int detectnextargument = strARGS.indexOf("&");
action = strARGS.substring(7, detectnextargument);
strARGS = strARGS.substring(detectnextargument + 1);
}
if (strARGS.startsWith("url=")) {
final String strUrl = strARGS.substring(4); // strip "url="
if (strARGS.startsWith("action=")) {
int detectnextargument = strARGS.indexOf("&");
action = strARGS.substring(7, detectnextargument);
strARGS = strARGS.substring(detectnextargument + 1);
}
if (strARGS.startsWith("url=")) {
final String strUrl = strARGS.substring(4); // strip "url="
try {
proxyurl = new URL(strUrl);
} catch (final MalformedURLException e) {
proxyurl = new URL(URLDecoder.decode(strUrl, UTF8.charset.name()));
try {
proxyurl = new URL(strUrl);
} catch (final MalformedURLException e) {
proxyurl = new URL(URLDecoder.decode(strUrl, UTF8.charset.name()));
}
}
if (proxyurl == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,"url parameter missing");
return;
}
int port = proxyurl.getPort();
if (port < 1) {
port = 80;
}
}
if (proxyurl == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND,"url parameter missing");
return;
}
int port = proxyurl.getPort();
if (port < 1) {
port = 80;
}
String host = proxyurl.getHost();
if (proxyurl.getPort() != -1) {
host += ":" + proxyurl.getPort();
}
RequestHeader yacyRequestHeader = ProxyHandler.convertHeaderFromJetty(request);
yacyRequestHeader.remove(RequestHeader.KEEP_ALIVE);
yacyRequestHeader.remove(RequestHeader.CONTENT_LENGTH);
final HashMap<String, Object> prop = new HashMap<String, Object>();
prop.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_1_1);
prop.put(HeaderFramework.CONNECTION_PROP_HOST, proxyurl.getHost());
prop.put(HeaderFramework.CONNECTION_PROP_PATH, proxyurl.getFile().replaceAll(" ", "%20"));
prop.put(HeaderFramework.CONNECTION_PROP_REQUESTLINE, "PROXY");
prop.put("CLIENTIP", "0:0:0:0:0:0:0:1");
yacyRequestHeader.put(HeaderFramework.HOST, proxyurl.getHost());
// temporarily add argument to header to pass it on to augmented browsing
if (action != null) yacyRequestHeader.put("YACYACTION", action);
final ByteArrayOutputStream tmpproxyout = new ByteArrayOutputStream();
HTTPDProxyHandler.doGet(prop, yacyRequestHeader, tmpproxyout, ClientIdentification.yacyProxyAgent);
// reparse header to extract content-length and mimetype
final ResponseHeader outgoingHeader = new ResponseHeader(200); //
final InputStream proxyout = new ByteArrayInputStream(tmpproxyout.toByteArray());
String line = readLine(proxyout);
while (line != null && !line.equals("")) {
int p;
if ((p = line.indexOf(':')) >= 0) {
// store a property
outgoingHeader.add(line.substring(0, p).trim(), line.substring(p + 1).trim());
}
line = readLine(proxyout);
}
if (line == null) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Proxy Header missing");
return;
String host = proxyurl.getHost();
if (proxyurl.getPort() != -1) {
host += ":" + proxyurl.getPort();
}
RequestHeader yacyRequestHeader = ProxyHandler.convertHeaderFromJetty(request);
yacyRequestHeader.remove(RequestHeader.KEEP_ALIVE);
yacyRequestHeader.remove(HeaderFramework.CONTENT_LENGTH);
final HashMap<String, Object> prop = new HashMap<String, Object>();
prop.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_1_1);
prop.put(HeaderFramework.CONNECTION_PROP_HOST, proxyurl.getHost());
prop.put(HeaderFramework.CONNECTION_PROP_PATH, proxyurl.getFile().replaceAll(" ", "%20"));
prop.put(HeaderFramework.CONNECTION_PROP_REQUESTLINE, "PROXY");
prop.put("CLIENTIP", "0:0:0:0:0:0:0:1");
yacyRequestHeader.put(HeaderFramework.HOST, proxyurl.getHost());
// temporarily add argument to header to pass it on to augmented browsing
if (action != null) yacyRequestHeader.put("YACYACTION", action);
final ByteArrayOutputStream tmpproxyout = new ByteArrayOutputStream();
HTTPDProxyHandler.doGet(prop, yacyRequestHeader, tmpproxyout, ClientIdentification.yacyProxyAgent);
// reparse header to extract content-length and mimetype
final ResponseHeader outgoingHeader = new ResponseHeader(200); //
final InputStream proxyout = new ByteArrayInputStream(tmpproxyout.toByteArray());
String line = readLine(proxyout);
while (line != null && !line.equals("")) {
int p;
if ((p = line.indexOf(':')) >= 0) {
// store a property
outgoingHeader.add(line.substring(0, p).trim(), line.substring(p + 1).trim());
}
line = readLine(proxyout);
}
if (line == null) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Proxy Header missing");
return;
}
final int httpStatus = Integer.parseInt((String) prop.get(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_STATUS));
final int httpStatus = Integer.parseInt((String) prop.get(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_STATUS));
String directory = "";
if (proxyurl.getPath().lastIndexOf('/') > 0) {
directory = proxyurl.getPath().substring(0, proxyurl.getPath().lastIndexOf('/'));
}
if (response.getHeader(HeaderFramework.LOCATION) != null) {
// rewrite location header
String location = response.getHeader(HeaderFramework.LOCATION);
String actioncmdstr = (action != null) ? "action=" + action + "&" : "";
if (location.startsWith("http")) {
location = "/proxy.html?" + actioncmdstr + "url=" + location;
} else {
location = "/proxy.html?" + actioncmdstr + "url=http://" + proxyurl.getHost() + "/" + location;
}
//outgoingHeader.put(HeaderFramework.LOCATION, location);
response.addHeader(HeaderFramework.LOCATION, location);
String directory = "";
if (proxyurl.getPath().lastIndexOf('/') > 0) {
directory = proxyurl.getPath().substring(0, proxyurl.getPath().lastIndexOf('/'));
}
if (response.getHeader(HeaderFramework.LOCATION) != null) {
// rewrite location header
String location = response.getHeader(HeaderFramework.LOCATION);
String actioncmdstr = (action != null) ? "action=" + action + "&" : "";
if (location.startsWith("http")) {
location = "/proxy.html?" + actioncmdstr + "url=" + location;
} else {
location = "/proxy.html?" + actioncmdstr + "url=http://" + proxyurl.getHost() + "/" + location;
}
//outgoingHeader.put(HeaderFramework.LOCATION, location);
response.addHeader(HeaderFramework.LOCATION, location);
}
//final String mimeType = outgoingHeader.getContentType();
final String mimeType = outgoingHeader.getContentType();
if ((mimeType != null) && (mimeType.startsWith("text/html") || mimeType.startsWith("text"))) {
final StringWriter buffer = new StringWriter();
if (outgoingHeader.containsKey(HeaderFramework.TRANSFER_ENCODING)) {
FileUtils.copy(new ChunkedInputStream(proxyout), buffer, UTF8.charset);
} else {
FileUtils.copy(proxyout, buffer, UTF8.charset);
}
final String sbuffer = buffer.toString();
final Pattern p = Pattern.compile("(href=\"|src=\")([^\"]+)|(href='|src=')([^']+)|(url\\(')([^']+)|(url\\(\")([^\"]+)|(url\\()([^\\)]+)");
final Matcher m = p.matcher(sbuffer);
final StringBuffer result = new StringBuffer(80);
Switchboard sb = Switchboard.getSwitchboard();
while (m.find()) {
String init = null;
if (m.group(1) != null) { init = m.group(1); }
if (m.group(3) != null) { init = m.group(3); }
if (m.group(5) != null) { init = m.group(5); }
if (m.group(7) != null) { init = m.group(7); }
if (m.group(9) != null) { init = m.group(9); }
String url = null;
if (m.group(2) != null) { url = m.group(2); }
if (m.group(4) != null) { url = m.group(4); }
if (m.group(6) != null) { url = m.group(6); }
if (m.group(8) != null) { url = m.group(8); }
if (m.group(10) != null) { url = m.group(10); }
if (url.startsWith("data:") || url.startsWith("#") || url.startsWith("mailto:") || url.startsWith("javascript:")) {
String newurl = init + url;
newurl = newurl.replaceAll("\\$", "\\\\\\$");
m.appendReplacement(result, newurl);
//final String mimeType = outgoingHeader.getContentType();
final String mimeType = outgoingHeader.getContentType();
if ((mimeType != null) && (mimeType.startsWith("text/html") || mimeType.startsWith("text"))) {
final StringWriter buffer = new StringWriter();
} else if (url.startsWith("http")) {
// absoulte url of form href="http://domain.com/path"
if (sb.getConfig("proxyURL.rewriteURLs", "all").equals("domainlist")) {
try {
if (sb.crawlStacker.urlInAcceptedDomain(new DigestURL(url)) != null) {
continue;
}
} catch (final MalformedURLException e) {
ConcurrentLog.fine("PROXY","ProxyServlet: malformed url for url-rewirte " + url);
if (outgoingHeader.containsKey(HeaderFramework.TRANSFER_ENCODING)) {
FileUtils.copy(new ChunkedInputStream(proxyout), buffer, UTF8.charset);
} else {
FileUtils.copy(proxyout, buffer, UTF8.charset);
}
final String sbuffer = buffer.toString();
final Pattern p = Pattern.compile("(href=\"|src=\")([^\"]+)|(href='|src=')([^']+)|(url\\(')([^']+)|(url\\(\")([^\"]+)|(url\\()([^\\)]+)");
final Matcher m = p.matcher(sbuffer);
final StringBuffer result = new StringBuffer(80);
Switchboard sb = Switchboard.getSwitchboard();
while (m.find()) {
String init = null;
if (m.group(1) != null) { init = m.group(1); }
if (m.group(3) != null) { init = m.group(3); }
if (m.group(5) != null) { init = m.group(5); }
if (m.group(7) != null) { init = m.group(7); }
if (m.group(9) != null) { init = m.group(9); }
String url = null;
if (m.group(2) != null) { url = m.group(2); }
if (m.group(4) != null) { url = m.group(4); }
if (m.group(6) != null) { url = m.group(6); }
if (m.group(8) != null) { url = m.group(8); }
if (m.group(10) != null) { url = m.group(10); }
if (url.startsWith("data:") || url.startsWith("#") || url.startsWith("mailto:") || url.startsWith("javascript:")) {
String newurl = init + url;
newurl = newurl.replaceAll("\\$", "\\\\\\$");
m.appendReplacement(result, newurl);
} else if (url.startsWith("http")) {
// absoulte url of form href="http://domain.com/path"
if (sb.getConfig("proxyURL.rewriteURLs", "all").equals("domainlist")) {
try {
if (sb.crawlStacker.urlInAcceptedDomain(new DigestURL(url)) != null) {
continue;
}
} catch (final MalformedURLException e) {
ConcurrentLog.fine("PROXY","ProxyServlet: malformed url for url-rewirte " + url);
continue;
}
}
String newurl = init + "/proxy.html?url=" + url;
newurl = newurl.replaceAll("\\$", "\\\\\\$");
m.appendReplacement(result, newurl);
String newurl = init + "/proxy.html?url=" + url;
newurl = newurl.replaceAll("\\$", "\\\\\\$");
m.appendReplacement(result, newurl);
} else if (url.startsWith("//")) {
// absoulte url but same protocol of form href="//domain.com/path"
final String complete_url = proxyurl.getProtocol() + ":" + url;
if (sb.getConfig("proxyURL.rewriteURLs", "all").equals("domainlist")) {
try {
if (sb.crawlStacker.urlInAcceptedDomain(new DigestURL(complete_url)) != null) {
continue;
}
} catch (MalformedURLException ex) {
ConcurrentLog.fine("PROXY","ProxyServlet: malformed url for url-rewirte " + complete_url);
continue;
}
} else if (url.startsWith("//")) {
// absoulte url but same protocol of form href="//domain.com/path"
final String complete_url = proxyurl.getProtocol() + ":" + url;
if (sb.getConfig("proxyURL.rewriteURLs", "all").equals("domainlist")) {
try {
if (sb.crawlStacker.urlInAcceptedDomain(new DigestURL(complete_url)) != null) {
continue;
}
} catch (MalformedURLException ex) {
ConcurrentLog.fine("PROXY","ProxyServlet: malformed url for url-rewirte " + complete_url);
continue;
}
}
String newurl = init + "/proxy.html?url=" + complete_url;
newurl = newurl.replaceAll("\\$", "\\\\\\$");
m.appendReplacement(result, newurl);
String newurl = init + "/proxy.html?url=" + complete_url;
newurl = newurl.replaceAll("\\$", "\\\\\\$");
m.appendReplacement(result, newurl);
} else if (url.startsWith("/")) {
// absolute path of form href="/absolute/path/to/linked/page"
String newurl = init + "/proxy.html?url=http://" + host + url;
newurl = newurl.replaceAll("\\$", "\\\\\\$");
m.appendReplacement(result, newurl);
} else if (url.startsWith("/")) {
// absolute path of form href="/absolute/path/to/linked/page"
String newurl = init + "/proxy.html?url=http://" + host + url;
} else {
// relative path of form href="relative/path"
try {
MultiProtocolURL target = new MultiProtocolURL("http://" + host + directory + "/" + url);
String newurl = init + "/proxy.html?url=" + target.toString();
newurl = newurl.replaceAll("\\$", "\\\\\\$");
m.appendReplacement(result, newurl);
} else {
// relative path of form href="relative/path"
try {
MultiProtocolURL target = new MultiProtocolURL("http://" + host + directory + "/" + url);
String newurl = init + "/proxy.html?url=" + target.toString();
newurl = newurl.replaceAll("\\$", "\\\\\\$");
m.appendReplacement(result, newurl);
} catch (final MalformedURLException e) {}
}
} catch (final MalformedURLException e) {}
}
m.appendTail(result);
byte[] sbb = UTF8.getBytes(result.toString());
// add some proxy-headers to response header
response.setContentType(outgoingHeader.getContentType());
if (outgoingHeader.containsKey(HeaderFramework.SERVER)) {
response.addHeader(HeaderFramework.SERVER, outgoingHeader.get(HeaderFramework.SERVER));
}
if (outgoingHeader.containsKey(HeaderFramework.DATE)) {
response.addHeader(HeaderFramework.DATE, outgoingHeader.get(HeaderFramework.DATE));
}
if (outgoingHeader.containsKey(HeaderFramework.LAST_MODIFIED)) {
response.addHeader(HeaderFramework.LAST_MODIFIED, outgoingHeader.get(HeaderFramework.LAST_MODIFIED));
}
if (outgoingHeader.containsKey(HeaderFramework.EXPIRES)) {
response.addHeader(HeaderFramework.EXPIRES, outgoingHeader.get(HeaderFramework.EXPIRES));
}
response.setStatus(httpStatus);
response.addIntHeader(HeaderFramework.CONTENT_LENGTH, sbb.length);
response.getOutputStream().write(sbb);
} else {
if ((response.getHeader(HeaderFramework.CONTENT_LENGTH) == null) && prop.containsKey(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE)) {
response.addHeader(HeaderFramework.CONTENT_LENGTH, (String) prop.get(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE));
}
response.setStatus(httpStatus);
FileUtils.copy(proxyout, response.getOutputStream());
}
m.appendTail(result);
byte[] sbb = UTF8.getBytes(result.toString());
// add some proxy-headers to response header
response.setContentType(outgoingHeader.getContentType());
if (outgoingHeader.containsKey(HeaderFramework.SERVER)) {
response.addHeader(HeaderFramework.SERVER, outgoingHeader.get(HeaderFramework.SERVER));
}
if (outgoingHeader.containsKey(HeaderFramework.DATE)) {
response.addHeader(HeaderFramework.DATE, outgoingHeader.get(HeaderFramework.DATE));
}
if (outgoingHeader.containsKey(HeaderFramework.LAST_MODIFIED)) {
response.addHeader(HeaderFramework.LAST_MODIFIED, outgoingHeader.get(HeaderFramework.LAST_MODIFIED));
}
if (outgoingHeader.containsKey(HeaderFramework.EXPIRES)) {
response.addHeader(HeaderFramework.EXPIRES, outgoingHeader.get(HeaderFramework.EXPIRES));
}
response.setStatus(httpStatus);
response.addIntHeader(HeaderFramework.CONTENT_LENGTH, sbb.length);
response.getOutputStream().write(sbb);
} else {
if ((response.getHeader(HeaderFramework.CONTENT_LENGTH) == null) && prop.containsKey(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE)) {
response.addHeader(HeaderFramework.CONTENT_LENGTH, (String) prop.get(HeaderFramework.CONNECTION_PROP_PROXY_RESPOND_SIZE));
}
response.setStatus(httpStatus);
FileUtils.copy(proxyout, response.getOutputStream());
}
}
}

@ -125,7 +125,6 @@ public class YacyDomainHandler extends AbstractHandler implements Handler {
return super.getHeader(name);
}
@SuppressWarnings("unchecked")
@Override
public Enumeration<String> getHeaders(String name) {
if (name.equals("Host")) {

@ -1,157 +0,0 @@
package net.yacy.interaction;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.URLEncoder;
import net.yacy.cora.document.encoding.ASCII;
import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.protocol.ClientIdentification;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.protocol.http.HTTPClient;
import net.yacy.cora.util.ConcurrentLog;
import net.yacy.search.Switchboard;
import net.yacy.server.http.ServerSideIncludes;
import org.jsoup.Jsoup;
public class AugmentHtmlStream {
static RequestHeader globalrequestHeader;
/**
* send web page to external REFLECT web service
*
* @return the web page with integrated REFLECT elements
*/
private static String processExternal(String url, String fieldname, String data) throws IOException {
final HTTPClient client = new HTTPClient(ClientIdentification.yacyInternetCrawlerAgent);
try {
StringBuilder postdata = new StringBuilder();
postdata.append(fieldname);
postdata.append('=');
postdata.append(URLEncoder.encode(data, "UTF-8"));
InputStream in = new ByteArrayInputStream(postdata.toString()
.getBytes());
byte[] result = client.POSTbytes(url, in, postdata.length());
if (result != null) {
return new String(result);
}
} finally {
client.finish();
}
return null;
}
private static String loadInternal(String path, RequestHeader requestHeader) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
String realmProp = requestHeader.get(RequestHeader.AUTHORIZATION);
ServerSideIncludes.writeContent(path, buffer, realmProp, Domains.LOCALHOST, requestHeader); // TODO: ip
return buffer.toString();
}
/**
* add DOCTYPE if necessary
*
* @return the web page with a leading DOCTYPE definition
*/
private static String processAddDoctype(String data) {
String result = data;
BufferedReader reader = new BufferedReader(new StringReader(data));
try {
String firstline = reader.readLine();
if (firstline != null) {
if (!firstline.startsWith("<!DOCTYPE")) {
result = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
+ data;
}
}
} catch (final IOException e1) {
}
return result;
}
public static StringBuilder process(StringBuilder data, DigestURL url, RequestHeader requestHeader) {
String action = requestHeader.get("YACYACTION");
requestHeader.remove("YACYACTION");
globalrequestHeader = requestHeader;
Switchboard sb = Switchboard.getSwitchboard();
boolean augmented = false;
try {
ConcurrentLog.info("AUGMENTATION", url.getName());
} catch (final IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String Doc = data.toString();
// Send document to REFLECT (http://www.reflect.ws/REST_API.html)
if (sb.getConfigBool("augmentation.reflect", false) == true) {
try {
Doc = processExternal("http://reflect.ws/REST/GetHTML", "document", Doc);
ConcurrentLog.info("AUGMENTATION", "reflected " + url);
augmented = true;
} catch (final Exception e) {
}
}
// Add DOCTYPE if not present.
// This is required for IE to render position:absolute correctly.
if (sb.getConfigBool("augmentation.addDoctype", false) == true) {
Doc = processAddDoctype(Doc);
augmented = true;
}
if (sb.getConfigBool("augmentation.reparse", false) == true) {
org.jsoup.nodes.Document d = Jsoup.parse(Doc);
d.title ("yacy - "+d.title());
if (sb.getConfigBool("interaction.overlayinteraction.enabled", false) == true) {
d.head().append (loadInternal("env/templates/jqueryheader.template", requestHeader));
d.head().append ("<script type='text/javascript'>"+loadInternal("interaction_elements/interaction.js", requestHeader)+"</script>");
d.head().append ("<script type='text/javascript'>"+loadInternal("interaction_elements/interaction_metadata.js", requestHeader)+"</script>");
d.body().append (loadInternal("interaction_elements/OverlayInteraction.html?action="+action+"&urlhash="+ ASCII.String(url.hash()) +"&url="+url.toNormalform(false), requestHeader));
d.body().append (loadInternal("interaction_elements/Footer.html?action="+action+"&urlhash="+ ASCII.String(url.hash()) +"&url="+url.toNormalform(false), requestHeader));
}
Doc = d.html();
augmented = true;
}
if (augmented) {
return (new StringBuilder(Doc));
}
return (data);
}
}

@ -1,64 +0,0 @@
package net.yacy.server.http;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.interaction.AugmentHtmlStream;
public class AugmentedHtmlStream extends FilterOutputStream {
private final Writer out;
private final ByteArrayOutputStream buffer;
private final Charset charset;
private final DigestURL url;
private final String urls;
private final RequestHeader requestHeader;
public AugmentedHtmlStream(OutputStream out, Charset charset, DigestURL url, RequestHeader requestHeader) {
super(out);
this.out = new BufferedWriter(new OutputStreamWriter(out, charset));
this.buffer = new ByteArrayOutputStream();
this.charset = charset;
this.url = url;
this.urls = this.url.toNormalform(false);
this.requestHeader = requestHeader;
}
@Override
public void write(int b) throws IOException {
this.buffer.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
this.buffer.write(b, off, len);
}
@Override
public void close() throws IOException {
StringBuilder b = new StringBuilder(this.buffer.toString(this.charset.name()));
b = process(b);
this.out.write(b.toString());
this.out.close();
}
public StringBuilder process(StringBuilder data) {
if (this.urls.contains("StringBuilder/")) {
return data;
}
return AugmentHtmlStream.process(data, this.url, this.requestHeader);
}
public static boolean supportsMime(String mime) {
// System.out.println("mime" +mime);
return mime.split(";")[0].equals("text/html");
}
}

File diff suppressed because it is too large Load Diff

@ -446,7 +446,6 @@ public final class HTTPDProxyHandler {
private static void fulfillRequestFromWeb(final HashMap<String, Object> conProp, final DigestURL url, final RequestHeader requestHeader, final ResponseHeader cachedResponseHeader, final OutputStream respond, final ClientIdentification.Agent agent) {
try {
final boolean proxyAugmentation = sb.getConfigBool("proxyAugmentation", false);
final int reqID = requestHeader.hashCode();
String host = (String) conProp.get(HeaderFramework.CONNECTION_PROP_HOST);
@ -504,12 +503,6 @@ public final class HTTPDProxyHandler {
throw new Exception(client.getHttpResponse().getStatusLine().toString());
}
if (proxyAugmentation && AugmentedHtmlStream.supportsMime(responseHeader.mime())) {
// enable chunk encoding, because we don't know the length after annotating
responseHeader.remove(HeaderFramework.CONTENT_LENGTH);
responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked");
}
ChunkedOutputStream chunkedOut = setTransferEncoding(conProp, responseHeader, statusCode, respond);
// the cache does either not exist or is (supposed to be) stale
@ -545,11 +538,6 @@ public final class HTTPDProxyHandler {
// prepareResponseHeader(responseHeader, res.getHttpVer());
prepareResponseHeader(responseHeader, client.getHttpResponse().getProtocolVersion().toString());
if(proxyAugmentation && AugmentedHtmlStream.supportsMime(responseHeader.mime())) {
// chunked encoding disables somewhere, add it again
responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked");
}
// sending the respond header back to the client
if (chunkedOut != null) {
responseHeader.put(HeaderFramework.TRANSFER_ENCODING, "chunked");
@ -578,9 +566,6 @@ public final class HTTPDProxyHandler {
final boolean storeHTCache = response.profile().storeHTCache();
final String supportError = TextParser.supports(response.url(), response.getMimeType());
if(proxyAugmentation && AugmentedHtmlStream.supportsMime(responseHeader.mime())) {
outStream = new AugmentedHtmlStream(outStream, responseHeader.getCharSet(), url, requestHeader);
}
if (
/*
* Now we store the response into the htcache directory if
@ -737,11 +722,6 @@ public final class HTTPDProxyHandler {
HTTPDemon.sendRespondHeader(conProp,respond,httpVer,203,cachedResponseHeader);
//respondHeader(respond, "203 OK", cachedResponseHeader); // respond with 'non-authoritative'
if(sb.getConfigBool("proxyAugmentation", false)
&& AugmentedHtmlStream.supportsMime(cachedResponseHeader.mime())) {
respond = new AugmentedHtmlStream(respond, cachedResponseHeader.getCharSet(), url, requestHeader);
}
// send also the complete body now from the cache
// simply read the file and transfer to out socket
FileUtils.copy(cacheEntry, respond);

File diff suppressed because it is too large Load Diff

@ -1,99 +0,0 @@
// ServerSideIncludes.java
// -----------------------------
// (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published 26.06.2007 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// LICENSE
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package net.yacy.server.http;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import net.yacy.cora.document.encoding.ASCII;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.util.ByteBuffer;
public class ServerSideIncludes {
public static void writeSSI(final ByteBuffer in, final OutputStream out, final String authorization, final String requesthost, final RequestHeader requestHeader) throws IOException {
writeSSI(in, 0, out, authorization, requesthost, requestHeader);
}
private static void writeSSI(final ByteBuffer in, int off, final OutputStream out, final String authorization, final String requesthost, final RequestHeader requestHeader) throws IOException {
int p = in.indexOf(ASCII.getBytes("<!--#"), off);
int q;
while (p >= 0) {
q = in.indexOf(ASCII.getBytes("-->"), p + 10);
if (out instanceof ChunkedOutputStream) {
((ChunkedOutputStream) out).write(in, off, p - off);
} else {
out.write(in.getBytes(off, p - off));
}
parseSSI(in, p, out, authorization, requesthost, requestHeader);
off = q + 3;
p = in.indexOf(ASCII.getBytes("<!--#"), off);
}
if (out instanceof ChunkedOutputStream) {
((ChunkedOutputStream) out).write(in, off, in.length() - off);
} else {
out.write(in.getBytes(off, in.length() - off));
}
}
private static void parseSSI(final ByteBuffer in, final int off, final OutputStream out, final String authorization, final String requesthost, final RequestHeader requestHeader) {
if (in.startsWith(ASCII.getBytes("<!--#include virtual=\""), off)) {
final int q = in.indexOf(ASCII.getBytes("\""), off + 22);
if (q > 0) {
final String path = in.toString(off + 22, q - off - 22);
writeContent(path, out, authorization, requesthost, requestHeader);
}
}
}
public static void writeContent(String path, final OutputStream out, final String authorization, final String requesthost, final RequestHeader requestHeader) {
// check if there are arguments in path string
String args = "";
final int argpos = path.indexOf('?');
if (argpos > 0) {
args = path.substring(argpos + 1);
path = path.substring(0, argpos);
}
// set up virtual connection properties to call httpdFileHander.doGet()
final HashMap<String, Object> conProp = new HashMap<String, Object>();
final RequestHeader header = new RequestHeader(HTTPDemon.reverseMappingCache);
conProp.put(HeaderFramework.CONNECTION_PROP_METHOD, HeaderFramework.METHOD_GET);
conProp.put(HeaderFramework.CONNECTION_PROP_PATH, path);
conProp.put(HeaderFramework.CONNECTION_PROP_ARGS, args);
conProp.put(HeaderFramework.CONNECTION_PROP_HTTP_VER, HeaderFramework.HTTP_VERSION_0_9);
conProp.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, requesthost);
header.put(RequestHeader.AUTHORIZATION, authorization);
if (requestHeader.containsKey(RequestHeader.COOKIE)) header.put(RequestHeader.COOKIE, requestHeader.get(RequestHeader.COOKIE));
header.put(RequestHeader.REFERER, requestHeader.get(RequestHeader.REFERER));
HTTPDFileHandler.doGet(conProp, header, out);
}
}

File diff suppressed because it is too large Load Diff

@ -1,212 +0,0 @@
//serverCoreSocket.java
//-------------------------------------
//part of YACY
//
//(C) 2006 by Martin Thelian
//
//last change: $LastChangedDate$ by $LastChangedBy$
//Revision: $LastChangedRevision$
//
//This program is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2 of the License, or
//(at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package net.yacy.server;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.nio.channels.SocketChannel;
public class serverCoreSocket extends Socket {
private PushbackInputStream input = null;
private Socket sock = null;
private boolean isSSL = false;
private String sslType = null;
public serverCoreSocket(final Socket sock) throws IOException {
this.sock = sock;
// determine the socket type
detectSSL();
}
public boolean isSSL() {
return this.isSSL;
}
public String getProtocol() {
return this.sslType;
}
private void detectSSL() throws IOException {
final InputStream in = getInputStream();
// read the first 5 bytes to determine the protocol type
final byte[] preRead = new byte[5];
int read, count = 0;
while ((count < preRead.length) && ((read = in.read()) != -1)) {
preRead[count] = (byte) read;
count++;
}
if (count < preRead.length) {
((PushbackInputStream) in).unread(preRead,0,count);
return;
}
int idx = 0;
if ((preRead[0] & 0xFF) == 22) {
// we have detected the ContentType field.
// 22 means "handshake"
idx = 1;
} else {
// SSL messages have two preceding bytes
// byte nr 3 specifies the handshake type
// 3 means "ClientHello"
final int handshakeType = preRead[2] & 0x00FF;
if (handshakeType == 1) this.isSSL = true;
idx = 3;
}
// determine the protocol version
if (preRead[idx] == 3 && (preRead[idx+1] >= 0 && preRead[idx+1] <= 2)) {
switch (preRead[idx+1]) {
case 0:
this.sslType = "SSL_3";
break;
case 1:
this.sslType = "TLS_1";
break;
case 2:
this.sslType = "TLS_1_1";
break;
default:
this.sslType = "SSL_3";
break;
}
this.isSSL = true;
//} else {
// maybe SSL_2, but we can not be sure
}
// unread pre read bytes
((PushbackInputStream) in).unread(preRead);
}
@Override
public InetAddress getInetAddress() {
return this.sock.getInetAddress();
}
@Override
public InetAddress getLocalAddress() {
return this.sock.getLocalAddress();
}
@Override
public int getPort() {
return this.sock.getPort();
}
@Override
public int getLocalPort() {
return this.sock.getLocalPort();
}
@Override
public SocketAddress getRemoteSocketAddress() {
return this.sock.getRemoteSocketAddress();
}
@Override
public SocketAddress getLocalSocketAddress() {
return this.sock.getLocalSocketAddress();
}
@Override
public SocketChannel getChannel() {
return this.sock.getChannel();
}
@Override
public InputStream getInputStream() throws IOException {
if (this.input == null) {
this.input = new PushbackInputStream(this.sock.getInputStream(),100);
}
return this.input;
}
@Override
public OutputStream getOutputStream() throws IOException {
return this.sock.getOutputStream();
}
@Override
public synchronized void close() throws IOException {
this.sock.close();
}
@Override
public void shutdownInput() throws IOException {
this.sock.shutdownInput();
}
@Override
public void shutdownOutput() throws IOException {
this.sock.shutdownOutput();
}
@Override
public String toString() {
return this.sock.toString();
}
@Override
public boolean isConnected() {
return this.sock.isConnected();
}
@Override
public boolean isBound() {
return this.sock.isBound();
}
@Override
public boolean isClosed() {
return this.sock.isClosed();
}
@Override
public boolean isInputShutdown() {
return this.sock.isInputShutdown();
}
@Override
public boolean isOutputShutdown() {
return this.sock.isOutputShutdown();
}
@Override
public synchronized void setSoTimeout(final int timeout) throws SocketException {
this.sock.setSoTimeout(timeout);
}
}

@ -1,105 +0,0 @@
// serverHandler.java
// -------------------------------------------
// (C) by Michael Peter Christen; mc@yacy.net
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004
// last major change: 05.04.2004
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/*
serverHandler:
A Generic Server becomes a server for s specific protocol by impementation of
a corresponding handler class. The handler class provides methods for each
command of the protocol that is implemented.
The Handler class is assigned to the serverCore by passing the handlers
name to the serverCore upon initialization.
Example:
serverCore server = new serverCore(port, 1000, 0, false, "ftpdProtocol", null, 0);
In this example the protocol handler "ftpdProtocol" is assigned. There a class
named ftpdProtocol.java must be implemented, that implements this interface,
a serverHandler.
Any protocol command can be implemented in either way:
public String COMMAND(String arg) throws IOException;
public InputStream COMMAND(String arg) throws IOException;
public void COMMAND(String arg) throws IOException;
..where COMMAND is the command that had been passed to the server
on the terminal connection. The 'arg' argument is the remaining part of
the command on the terminal connection.
If the handler method returns a NULL value, which is especially
the case if the method implements a 'void' return-value method,
then the server disconnects the connection.
Any other return value (String or an InputStream) is returned to
the client on it's own line through the terminal connection.
If it is wanted that the server terminates right after submitting
a last line, then this can be indicated by prefixing the return
value by a '!'-character.
If one of the command methods throws a IOException, then the
server asks the error - method for a return value on the terminal
connection.
The greeting-method is used to request a string that is transmitted
to the client as terminal output at the beginning of a connection
session.
*/
package net.yacy.server;
import java.io.IOException;
import net.yacy.server.serverCore.Session;
public interface serverHandler {
// a response line upon connection is send to client
// if no response line is wanted, return "" or null
public String greeting();
// return string in case of any error that occurs during communication
// is always (but not only) called if an IO-dependent exception occurs.
public String error(Throwable e);
// clone method for the handler prototype
// each time a server makes a new connection it clones the hanlder prototype
// the clone method does not need to clone every detail of a handler connection,
// but only the necessary one for a newly initialized instance
public serverHandler clone();
/**
* Instead of using clone this function can be used to reset an existing
* handler prototype so that it can e reused
*/
public void reset();
/**
* Tthis function will be called by the {@link serverCore}.listen() function
* if the whole request line is empty and therefore no function of this
* serverHandlerClass can be called because of the missing command name
*/
public Boolean EMPTY(String arg, Session session) throws IOException;
/**
* This function will be called by the {@link serverCore}.listen() function
* if no corresponding funktion of the serverHandler class can be
* found for the received command.
*/
public Boolean UNKNOWN(String requestLine, Session session) throws IOException;
}

@ -52,7 +52,6 @@ import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.workflow.BusyThread;
import net.yacy.kelondro.workflow.WorkflowThread;
import net.yacy.server.serverAccessTracker.Track;
import net.yacy.server.serverCore.Session;
public class serverSwitch
{
@ -442,43 +441,6 @@ public class serverSwitch
}
}
public void closeSessions(String sessionName) {
if ( sessionName == null ) {
return;
}
for ( final Session s : serverCore.getJobList() ) {
if ( (s.isAlive()) && (s.getName().equals(sessionName)) ) {
// try to stop session
s.setStopped(true);
try {
Thread.sleep(100);
} catch (final InterruptedException ex ) {
}
// try to interrupt session
s.interrupt();
try {
Thread.sleep(100);
} catch (final InterruptedException ex ) {
}
// try to close socket
if ( s.isAlive() ) {
s.close();
}
// wait for session to finish
if ( s.isAlive() ) {
try {
s.join(500);
} catch (final InterruptedException ex ) {
}
}
}
}
}
public Iterator<String> /*of serverThread-Names (String)*/threadNames() {
return this.workerThreads.keySet().iterator();
}

@ -64,8 +64,6 @@ import net.yacy.peers.operation.yacyVersion;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
import net.yacy.server.serverCore;
import net.yacy.server.http.HTTPDemon;
import com.google.common.io.Files;
import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.federate.yacy.CacheStrategy;
@ -349,23 +347,7 @@ public final class yacy {
try {
// start http server
YaCyHttpServer httpServer;
// default jetty (alternative "anomichttpd")
if (sb.getConfig("defaulthttpserver","jetty").equalsIgnoreCase("jetty")) {
httpServer = new Jetty8HttpServerImpl(port);
} else {
final HTTPDemon protocolHandler = new HTTPDemon(sb);
httpServer = new serverCore(
timeout /*control socket timeout in milliseconds*/,
true /* block attacks (wrong protocol) */,
protocolHandler /*command class*/,
sb,
30000 /*command max length incl. GET args*/);
((serverCore) httpServer).setName("httpd:"+port);
((serverCore) httpServer).setPriority(Thread.MAX_PRIORITY);
((serverCore) httpServer).setObeyIntermission(false);
// start the server
//sb.deployThread("10_httpd", "HTTPD Server/Proxy", "the HTTPD, used as web server and proxy", null, server, 0, 0, 0, 0);
}
httpServer = new Jetty8HttpServerImpl(port);
httpServer.startupServer();
sb.setHttpServer(httpServer);
ConcurrentLog.info("STARTUP",httpServer.getVersion());

Loading…
Cancel
Save