2007-08-22 02:59:05 +02:00
|
|
|
// urls.java
|
|
|
|
// (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
|
|
|
// first published 22.08.2007 on http://yacy.net
|
|
|
|
//
|
|
|
|
// This is a part of YaCy, a peer-to-peer based web search engine
|
|
|
|
//
|
|
|
|
// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
|
|
|
|
// $LastChangedRevision: 1986 $
|
|
|
|
// $LastChangedBy: orbiter $
|
|
|
|
//
|
|
|
|
// LICENSE
|
2011-10-04 11:06:24 +02:00
|
|
|
//
|
2007-08-22 02:59:05 +02:00
|
|
|
// 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
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2011-01-03 21:52:54 +01:00
|
|
|
import net.yacy.cora.date.GenericFormatter;
|
2013-09-15 00:30:23 +02:00
|
|
|
import net.yacy.cora.document.encoding.ASCII;
|
|
|
|
import net.yacy.cora.document.id.DigestURL;
|
2010-08-23 14:32:02 +02:00
|
|
|
import net.yacy.cora.protocol.RequestHeader;
|
2014-08-01 11:00:10 +02:00
|
|
|
import net.yacy.cora.util.ConcurrentLog;
|
2012-09-21 15:48:16 +02:00
|
|
|
import net.yacy.crawler.data.NoticedURL;
|
|
|
|
import net.yacy.crawler.retrieval.Request;
|
2012-10-16 18:11:57 +02:00
|
|
|
import net.yacy.kelondro.data.meta.URIMetadataNode;
|
2011-10-04 11:06:24 +02:00
|
|
|
import net.yacy.peers.Protocol;
|
2011-09-25 18:59:06 +02:00
|
|
|
import net.yacy.search.Switchboard;
|
2012-09-21 15:48:16 +02:00
|
|
|
import net.yacy.server.serverObjects;
|
|
|
|
import net.yacy.server.serverSwitch;
|
2007-08-22 02:59:05 +02:00
|
|
|
|
|
|
|
public class urls {
|
2011-10-04 11:06:24 +02:00
|
|
|
|
2012-07-05 09:14:04 +02:00
|
|
|
public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
2009-07-19 22:37:44 +02:00
|
|
|
final Switchboard sb = (Switchboard) env;
|
2011-10-04 11:06:24 +02:00
|
|
|
|
2007-08-22 02:59:05 +02:00
|
|
|
// insert default values
|
2008-08-02 14:12:04 +02:00
|
|
|
final serverObjects prop = new serverObjects();
|
2009-05-28 16:26:05 +02:00
|
|
|
prop.put("iam", sb.peers.mySeed().hash);
|
2007-10-24 23:38:19 +02:00
|
|
|
prop.put("response", "rejected - insufficient call parameters");
|
|
|
|
prop.put("channel_title", "");
|
|
|
|
prop.put("channel_description", "");
|
|
|
|
prop.put("channel_pubDate", "");
|
|
|
|
prop.put("item", "0");
|
2011-10-04 11:06:24 +02:00
|
|
|
|
2007-11-29 03:07:37 +01:00
|
|
|
if ((post == null) || (env == null)) return prop;
|
2011-10-04 11:06:24 +02:00
|
|
|
if (!Protocol.authentifyRequest(post, env)) return prop;
|
|
|
|
|
2007-08-22 02:59:05 +02:00
|
|
|
if (post.get("call", "").equals("remotecrawl")) {
|
|
|
|
// perform a remote crawl url handover
|
2012-02-02 21:33:42 +01:00
|
|
|
final NoticedURL.StackType stackType = NoticedURL.StackType.GLOBAL;
|
2008-11-06 11:07:53 +01:00
|
|
|
int maxCount = Math.min(100, post.getInt("count", 10));
|
2011-10-04 11:06:24 +02:00
|
|
|
final long maxTime = Math.min(20000, Math.max(1000, post.getInt("time", 10000)));
|
|
|
|
final long timeout = System.currentTimeMillis() + maxTime;
|
2007-08-22 02:59:05 +02:00
|
|
|
int c = 0;
|
2009-07-15 23:07:46 +02:00
|
|
|
Request entry;
|
2013-09-15 00:30:23 +02:00
|
|
|
DigestURL referrer;
|
2008-11-06 11:07:53 +01:00
|
|
|
while ((maxCount > 0) &&
|
|
|
|
(System.currentTimeMillis() < timeout) &&
|
2014-11-23 20:09:32 +01:00
|
|
|
(!sb.crawlQueues.noticeURL.isEmpty(stackType))) {
|
2007-08-22 02:59:05 +02:00
|
|
|
try {
|
2012-04-21 13:47:48 +02:00
|
|
|
entry = sb.crawlQueues.noticeURL.pop(stackType, false, sb.crawler, sb.robots);
|
2008-08-02 14:12:04 +02:00
|
|
|
} catch (final IOException e) {
|
2007-08-22 02:59:05 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (entry == null) break;
|
2011-10-04 11:06:24 +02:00
|
|
|
|
2007-11-29 14:58:00 +01:00
|
|
|
// find referrer, if there is one
|
2014-08-01 11:00:10 +02:00
|
|
|
try {
|
|
|
|
referrer = sb.getURL(entry.referrerhash());
|
|
|
|
} catch (IOException e) {
|
|
|
|
referrer = null;
|
|
|
|
ConcurrentLog.logException(e);
|
|
|
|
}
|
2011-10-04 11:06:24 +02:00
|
|
|
|
2007-11-29 03:07:37 +01:00
|
|
|
// place url to notice-url db
|
2015-05-23 02:06:39 +02:00
|
|
|
if (sb.crawlQueues.delegatedURL != null) sb.crawlQueues.delegatedURL.put(ASCII.String(entry.url().hash()), entry.url());
|
2011-10-04 11:06:24 +02:00
|
|
|
|
2007-11-29 03:07:37 +01:00
|
|
|
// create RSS entry
|
2007-08-22 02:59:05 +02:00
|
|
|
prop.put("item_" + c + "_title", "");
|
2012-10-10 11:46:22 +02:00
|
|
|
prop.putXML("item_" + c + "_link", entry.url().toNormalform(true));
|
|
|
|
prop.putXML("item_" + c + "_referrer", (referrer == null) ? "" : referrer.toNormalform(true));
|
2009-02-01 23:35:56 +01:00
|
|
|
prop.putXML("item_" + c + "_description", entry.name());
|
2007-08-22 02:59:05 +02:00
|
|
|
prop.put("item_" + c + "_author", "");
|
2011-01-03 21:52:54 +01:00
|
|
|
prop.put("item_" + c + "_pubDate", GenericFormatter.SHORT_SECOND_FORMATTER.format(entry.appdate()));
|
2007-09-05 11:01:35 +02:00
|
|
|
prop.put("item_" + c + "_guid", entry.url().hash());
|
2007-08-22 02:59:05 +02:00
|
|
|
c++;
|
2008-11-06 11:07:53 +01:00
|
|
|
maxCount--;
|
2007-08-22 02:59:05 +02:00
|
|
|
}
|
|
|
|
prop.put("item", c);
|
2009-02-01 23:35:56 +01:00
|
|
|
prop.putXML("response", "ok");
|
2007-08-22 02:59:05 +02:00
|
|
|
}
|
2011-10-04 11:06:24 +02:00
|
|
|
|
2007-11-29 23:12:01 +01:00
|
|
|
if (post.get("call", "").equals("urlhashlist")) {
|
|
|
|
// retrieve a list of urls from the LURL-db by a given list of url hashes
|
2008-08-02 14:12:04 +02:00
|
|
|
final String urlhashes = post.get("hashes", "");
|
2007-11-29 23:12:01 +01:00
|
|
|
if (urlhashes.length() % 12 != 0) return prop;
|
2008-08-02 14:12:04 +02:00
|
|
|
final int count = urlhashes.length() / 12;
|
2007-11-29 23:12:01 +01:00
|
|
|
int c = 0;
|
2012-10-16 18:11:57 +02:00
|
|
|
URIMetadataNode entry;
|
2013-09-15 00:30:23 +02:00
|
|
|
DigestURL referrer;
|
2007-11-29 23:12:01 +01:00
|
|
|
for (int i = 0; i < count; i++) {
|
2012-08-17 15:52:33 +02:00
|
|
|
entry = sb.index.fulltext().getMetadata(ASCII.getBytes(urlhashes.substring(12 * i, 12 * (i + 1))));
|
2007-11-29 23:12:01 +01:00
|
|
|
if (entry == null) continue;
|
|
|
|
// find referrer, if there is one
|
2014-08-01 11:00:10 +02:00
|
|
|
try {
|
|
|
|
referrer = sb.getURL(entry.referrerHash());
|
|
|
|
// create RSS entry
|
|
|
|
prop.put("item_" + c + "_title", entry.dc_title());
|
|
|
|
prop.putXML("item_" + c + "_link", entry.url().toNormalform(true));
|
|
|
|
prop.putXML("item_" + c + "_referrer", (referrer == null) ? "" : referrer.toNormalform(true));
|
|
|
|
prop.putXML("item_" + c + "_description", entry.dc_title());
|
|
|
|
prop.put("item_" + c + "_author", entry.dc_creator());
|
|
|
|
prop.put("item_" + c + "_pubDate", GenericFormatter.SHORT_SECOND_FORMATTER.format(entry.moddate()));
|
|
|
|
prop.put("item_" + c + "_guid", ASCII.String(entry.hash()));
|
|
|
|
c++;
|
|
|
|
} catch (IOException e) {
|
|
|
|
ConcurrentLog.logException(e);
|
|
|
|
}
|
2007-11-29 23:12:01 +01:00
|
|
|
}
|
|
|
|
prop.put("item", c);
|
2009-02-01 23:35:56 +01:00
|
|
|
prop.putXML("response", "ok");
|
2007-11-29 23:12:01 +01:00
|
|
|
}
|
2007-08-22 02:59:05 +02:00
|
|
|
|
|
|
|
// return rewrite properties
|
|
|
|
return prop;
|
|
|
|
}
|
2011-10-04 11:06:24 +02:00
|
|
|
|
2007-08-22 02:59:05 +02:00
|
|
|
}
|