You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.3 KiB
64 lines
2.3 KiB
16 years ago
|
|
||
17 years ago
|
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import java.net.URL;
|
||
16 years ago
|
import java.util.Iterator;
|
||
16 years ago
|
import java.util.Map;
|
||
17 years ago
|
import java.util.Scanner;
|
||
|
|
||
14 years ago
|
import net.yacy.cora.protocol.RequestHeader;
|
||
13 years ago
|
import net.yacy.search.Switchboard;
|
||
14 years ago
|
|
||
17 years ago
|
import de.anomic.server.serverObjects;
|
||
|
import de.anomic.server.serverSwitch;
|
||
|
|
||
|
public class ynetSearch {
|
||
|
|
||
16 years ago
|
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||
|
final Switchboard switchboard = (Switchboard) env;
|
||
17 years ago
|
final boolean isAdmin=switchboard.verifyAuthentication(header, true);
|
||
|
final serverObjects prop = new serverObjects();
|
||
17 years ago
|
|
||
|
if(post != null){
|
||
|
if(!isAdmin){
|
||
|
// force authentication if desired
|
||
|
if(post.containsKey("login")){
|
||
|
prop.put("AUTHENTICATE","admin log-in");
|
||
|
}
|
||
16 years ago
|
return prop;
|
||
17 years ago
|
} else {
|
||
|
InputStream is = null;
|
||
16 years ago
|
try {
|
||
|
String searchaddress = post.get("url");
|
||
|
if (!searchaddress.startsWith("http://")) {
|
||
|
// a relative path .. this addresses the local peer
|
||
15 years ago
|
searchaddress = "http://" + switchboard.peers.mySeed().getPublicAddress() + ((searchaddress.length() > 0 && searchaddress.charAt(0) == '/') ? "" : "/") + searchaddress;
|
||
16 years ago
|
}
|
||
16 years ago
|
post.remove("url");
|
||
|
post.remove("login");
|
||
16 years ago
|
final Iterator <Map.Entry<String, String>> it = post.entrySet().iterator();
|
||
16 years ago
|
String s = searchaddress;
|
||
16 years ago
|
Map.Entry<String, String> k;
|
||
16 years ago
|
while(it.hasNext()) {
|
||
|
k = it.next();
|
||
16 years ago
|
s = s + "&" + k.getKey() + "=" + k.getValue();
|
||
16 years ago
|
}
|
||
15 years ago
|
// final String s = searchaddress+"&query="+post.get("search")+"&maximumRecords="+post.get("maximumRecords")+"&startRecord="+post.get("startRecord");
|
||
17 years ago
|
final URL url = new URL(s);
|
||
17 years ago
|
is = url.openStream();
|
||
16 years ago
|
final String httpout = new Scanner(is).useDelimiter( "\\Z" ).next();
|
||
|
prop.put("http", httpout);
|
||
17 years ago
|
}
|
||
17 years ago
|
catch ( final Exception e ) {
|
||
17 years ago
|
prop.put("url", "error!");
|
||
|
}
|
||
|
finally {
|
||
|
if ( is != null )
|
||
17 years ago
|
try { is.close(); } catch ( final IOException e ) { }
|
||
17 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
return prop;
|
||
|
}
|
||
|
}
|