2005-04-07 21:19:42 +02:00
// dir.java
// -----------------------
// (C) by Michael Peter Christen; mc@anomic.de
// first published on http://www.anomic.de
// Frankfurt, Germany, 2004, 2005
2005-09-19 01:07:29 +02:00
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
2005-04-07 21:19:42 +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
//
// Using this software in any meaning (reading, learning, copying, compiling,
// running) means that you agree that the Author(s) is (are) not responsible
// for cost, loss of data or any harm that may be caused directly or indirectly
// by usage of this softare or this documentation. The usage of this software
// is on your own risk. The installation and usage (starting/running) of this
// software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with
// the software.
//
// Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such.
2005-09-19 01:07:29 +02:00
//
2005-05-12 19:50:45 +02:00
// You must compile this file with
2005-04-07 21:19:42 +02:00
// javac -classpath <application_root>/classes <application_root>/htroot/htdocsdefault/dir.java
// which most probably means to compile this with
// javac -classpath ../../classes dir.java
2005-05-05 07:36:42 +02:00
import java.io.ByteArrayInputStream ;
import java.io.File ;
import java.io.IOException ;
2006-09-30 00:27:20 +02:00
import java.net.InetAddress ;
import java.net.UnknownHostException ;
2005-05-05 07:36:42 +02:00
import java.text.SimpleDateFormat ;
2006-08-06 16:38:07 +02:00
import java.util.Arrays ;
2005-05-05 07:36:42 +02:00
import java.util.Date ;
2006-01-22 01:07:00 +01:00
import java.util.Iterator ;
2006-09-30 00:27:20 +02:00
import de.anomic.data.userDB ;
2005-05-05 07:36:42 +02:00
import de.anomic.http.httpHeader ;
2007-03-23 07:25:21 +01:00
import de.anomic.http.httpc ;
2007-02-05 20:46:50 +01:00
import de.anomic.http.httpd ;
2006-11-08 17:17:47 +01:00
import de.anomic.index.indexURLEntry ;
2006-01-04 01:39:00 +01:00
import de.anomic.kelondro.kelondroBase64Order ;
2006-11-23 03:16:30 +01:00
import de.anomic.kelondro.kelondroBitfield ;
2005-05-05 07:36:42 +02:00
import de.anomic.plasma.plasmaCondenser ;
2007-09-05 11:01:35 +02:00
import de.anomic.plasma.plasmaHTCache ;
2005-05-05 07:36:42 +02:00
import de.anomic.plasma.plasmaSwitchboard ;
import de.anomic.server.serverCodings ;
import de.anomic.server.serverCore ;
2007-07-24 02:46:17 +02:00
import de.anomic.server.serverDomains ;
2005-05-05 07:36:42 +02:00
import de.anomic.server.serverFileUtils ;
2006-08-06 10:09:39 +02:00
import de.anomic.server.serverMemory ;
2005-05-05 07:36:42 +02:00
import de.anomic.server.serverObjects ;
import de.anomic.server.serverSwitch ;
2005-08-15 01:35:18 +02:00
import de.anomic.server.logging.serverLog ;
2006-08-06 16:38:07 +02:00
import de.anomic.tools.dirlistComparator ;
import de.anomic.tools.md5DirFileFilter ;
2005-05-05 07:36:42 +02:00
import de.anomic.yacy.yacyCore ;
import de.anomic.yacy.yacySeed ;
2007-09-05 11:01:35 +02:00
import de.anomic.yacy.yacyURL ;
2005-04-07 21:19:42 +02:00
public class dir {
private static SimpleDateFormat SimpleFormatter = new SimpleDateFormat ( " yyyy/MM/dd HH:mm:ss " ) ;
public static String dateString ( Date date ) {
2006-08-06 10:09:39 +02:00
return SimpleFormatter . format ( date ) ;
2005-04-07 21:19:42 +02:00
}
public static serverObjects respond ( httpHeader header , serverObjects post , serverSwitch env ) {
2005-09-19 01:07:29 +02:00
final plasmaSwitchboard switchboard = ( plasmaSwitchboard ) env ;
final serverObjects prop = new serverObjects ( ) ;
// System.out.println("###Header="+ header);
// System.out.println("###post=" + post);
2005-04-07 21:19:42 +02:00
String action = ( ( post = = null ) ? " info " : post . get ( " action " , " info " ) ) ;
2006-08-06 10:09:39 +02:00
2005-04-07 21:19:42 +02:00
// variables for this path
2005-09-19 01:07:29 +02:00
// File htroot = new File(switchboard.getRootPath(), switchboard.getConfig("htRootPath", "htroot"));
final File htroot = new File ( switchboard . getRootPath ( ) , switchboard . getConfig ( " htDocsPath " , " DATA/HTDOCS " ) ) ;
2005-04-07 21:19:42 +02:00
String path = ( String ) header . get ( " PATH " , " / " ) ;
2005-09-19 01:07:29 +02:00
int pos = path . lastIndexOf ( " / " ) ;
if ( pos > = 0 ) { path = path . substring ( 0 , pos + 1 ) ; }
final File dir = new File ( htroot , path ) ;
2005-04-07 21:19:42 +02:00
// general settings
prop . put ( " peername " , env . getConfig ( " peerName " , " <nameless> " ) ) ;
prop . put ( " peerdomain " , env . getConfig ( " peerName " , " <nameless> " ) . toLowerCase ( ) ) ;
2007-10-01 14:30:23 +02:00
prop . put ( " peeraddress " , yacyCore . seedDB . mySeed ( ) . getPublicAddress ( ) ) ;
2007-07-24 02:46:17 +02:00
prop . put ( " hostname " , serverDomains . myPublicIP ( ) ) ;
2005-09-19 01:07:29 +02:00
try {
2007-07-24 02:46:17 +02:00
prop . put ( " hostip " , InetAddress . getByName ( serverDomains . myPublicIP ( ) ) ) ;
2005-09-19 01:07:29 +02:00
} catch ( UnknownHostException e ) {
prop . put ( " hostip " , " Unknown Host Exception " ) ;
2006-02-17 11:53:20 +01:00
}
prop . put ( " port " , serverCore . getPortNr ( env . getConfig ( " port " , " 8080 " ) ) ) ;
2005-09-19 01:07:29 +02:00
2005-04-07 21:19:42 +02:00
// generate upload/download authorizations
2007-02-05 20:46:50 +01:00
final String adminAccountBase64MD5 = switchboard . getConfig ( httpd . ADMIN_ACCOUNT_B64MD5 , " " ) ;
2005-09-19 01:07:29 +02:00
final String uploadAccountBase64MD5 = switchboard . getConfig ( " uploadAccountBase64MD5 " , " " ) ;
final String downloadAccountBase64MD5 = switchboard . getConfig ( " downloadAccountBase64MD5 " , " " ) ;
2005-10-19 13:51:24 +02:00
userDB . Entry entry = switchboard . userDB . proxyAuth ( ( String ) header . get ( " Authorization " , " xxxxxx " ) ) ;
boolean adminAuthorization , downloadAuthorization , uploadAuthorization ;
if ( entry = = null ) {
final String authorizationMD5 = de . anomic . server . serverCodings . encodeMD5Hex ( ( ( String ) header . get ( " Authorization " , " xxxxxx " ) ) . trim ( ) . substring ( 6 ) ) ;
// if (logoutAccountBase64.equals(authorization))
adminAuthorization = ( adminAccountBase64MD5 . length ( ) ! = 0 & & adminAccountBase64MD5 . equals ( authorizationMD5 ) ) ;
uploadAuthorization = ( adminAuthorization | | ( uploadAccountBase64MD5 . length ( ) ! = 0 & & uploadAccountBase64MD5 . equals ( authorizationMD5 ) ) ) ;
downloadAuthorization = ( adminAuthorization | | uploadAuthorization | | downloadAccountBase64MD5 . length ( ) = = 0 | | downloadAccountBase64MD5 . equals ( authorizationMD5 ) ) ;
} else { //userDB
2007-06-11 23:33:45 +02:00
adminAuthorization = entry . hasRight ( userDB . Entry . ADMIN_RIGHT ) ;
uploadAuthorization = entry . hasRight ( userDB . Entry . UPLOAD_RIGHT ) ;
downloadAuthorization = entry . hasRight ( userDB . Entry . DOWNLOAD_RIGHT ) ;
2005-10-19 13:51:24 +02:00
}
2005-04-07 21:19:42 +02:00
// do authentitcate processes by triggering the http authenticate method
2005-09-19 01:07:29 +02:00
if ( action . equals ( " authenticateAdmin " ) & & ! adminAuthorization ) {
2005-04-07 21:19:42 +02:00
prop . put ( " AUTHENTICATE " , " admin log-in " ) ;
return prop ;
}
2005-09-19 01:07:29 +02:00
if ( action . equals ( " authenticateUpload " ) & & ! uploadAuthorization ) {
2005-04-07 21:19:42 +02:00
prop . put ( " AUTHENTICATE " , " upload log-in " ) ;
return prop ;
}
2005-09-19 01:07:29 +02:00
if ( action . equals ( " authenticateDownload " ) & & ! downloadAuthorization ) {
2005-04-07 21:19:42 +02:00
prop . put ( " AUTHENTICATE " , " download log-in " ) ;
return prop ;
}
2005-09-19 01:07:29 +02:00
2005-04-07 21:19:42 +02:00
// work off actions
if ( action . equals ( " logout " ) ) {
if ( adminAuthorization ) {
prop . put ( " AUTHENTICATE " , " admin log-in " ) ;
return prop ;
} else if ( uploadAuthorization ) {
prop . put ( " AUTHENTICATE " , " upload log-in " ) ;
return prop ;
} else if ( downloadAuthorization ) {
prop . put ( " AUTHENTICATE " , " download log-in " ) ;
return prop ;
} else {
action = " " ;
}
2006-08-06 10:09:39 +02:00
} else if ( action . equals ( " downloadPassword " ) & & adminAuthorization ) {
2006-01-04 01:39:00 +01:00
switchboard . setConfig ( " downloadAccountBase64MD5 " , ( post . get ( " password " , " " ) . length ( ) = = 0 ) ? " " : serverCodings . encodeMD5Hex ( kelondroBase64Order . standardCoder . encodeString ( " download: " + post . get ( " password " , " " ) ) ) ) ;
2006-08-06 10:09:39 +02:00
} else if ( action . equals ( " uploadPassword " ) & & adminAuthorization ) {
2006-01-04 01:39:00 +01:00
switchboard . setConfig ( " uploadAccountBase64MD5 " , ( post . get ( " password " , " " ) . length ( ) = = 0 ) ? " " : serverCodings . encodeMD5Hex ( kelondroBase64Order . standardCoder . encodeString ( " upload: " + post . get ( " password " , " " ) ) ) ) ;
2006-08-06 10:09:39 +02:00
} else if ( action . equals ( " upload " ) & & ( uploadAuthorization | | adminAuthorization ) ) {
2005-09-19 01:07:29 +02:00
String filename = new File ( post . get ( " file " , " dummy " ) ) . getName ( ) ;
String description = post . get ( " description " , " " ) ;
pos = filename . lastIndexOf ( " \\ " ) ;
if ( pos > = 0 ) { filename = filename . substring ( pos + 1 ) ; }
final File newfile = new File ( dir , filename ) ;
final File newfilemd5 = new File ( dir , filename + " .md5 " ) ;
2005-12-07 00:51:29 +01:00
final byte [ ] binary = ( byte [ ] ) post . get ( " file$file " , new byte [ 0 ] ) ;
2005-04-07 21:19:42 +02:00
try {
serverFileUtils . write ( binary , newfile ) ;
2006-10-19 23:14:37 +02:00
byte [ ] md5 = serverCodings . encodeMD5Raw ( newfile ) ;
String md5s = serverCodings . encodeHex ( md5 ) ;
2006-01-10 17:48:59 +01:00
serverFileUtils . write ( ( md5s + " \ n " + description ) . getBytes ( " UTF-8 " ) , newfilemd5 ) ; // generate md5
2005-09-19 01:07:29 +02:00
2005-04-07 21:19:42 +02:00
// index file info
if ( post . get ( " indexing " , " " ) . equals ( " on " ) ) {
2007-10-01 14:30:23 +02:00
final String urlstring = yacyhURL ( yacyCore . seedDB . mySeed ( ) , filename , md5s ) ;
2005-09-19 01:07:29 +02:00
final String phrase = filename . replace ( '.' , ' ' ) . replace ( '_' , ' ' ) . replace ( '-' , ' ' ) ;
2006-10-19 23:14:37 +02:00
indexPhrase ( switchboard , urlstring , phrase , description , md5 ) ;
2005-04-07 21:19:42 +02:00
}
} catch ( IOException e ) { }
2006-08-06 10:09:39 +02:00
} else if ( action . equals ( " newdir " ) & & ( uploadAuthorization | | adminAuthorization ) ) {
2005-09-19 01:07:29 +02:00
final String newdirname = post . get ( " directory " , " EmptyDir " ) ;
if ( newdirname ! = null & & newdirname . length ( ) > 0 ) {
final File newdir = new File ( dir , newdirname ) ;
2005-04-07 21:19:42 +02:00
newdir . mkdir ( ) ;
}
2006-08-06 10:09:39 +02:00
} else if ( action . equals ( " delete " ) & & adminAuthorization ) {
2005-04-07 21:19:42 +02:00
String filename = post . get ( " file " , " foo " ) ;
2005-09-19 01:07:29 +02:00
final File file = new File ( dir , filename ) ;
2005-04-07 21:19:42 +02:00
if ( file . exists ( ) ) {
2005-09-19 01:07:29 +02:00
final File filemd5 = new File ( dir , post . get ( " file " , " foo " ) + " .md5 " ) ;
2005-04-07 21:19:42 +02:00
// read md5 and phrase
String md5s = " " ;
String description = " " ;
if ( filemd5 . exists ( ) ) try {
md5s = new String ( serverFileUtils . read ( filemd5 ) ) ;
2005-09-19 01:07:29 +02:00
pos = md5s . indexOf ( '\n' ) ;
if ( pos > = 0 ) {
description = md5s . substring ( pos + 1 ) ;
md5s = md5s . substring ( 0 , pos ) ;
2005-04-07 21:19:42 +02:00
}
} catch ( IOException e ) { }
// delete file(s)
if ( file . isDirectory ( ) ) {
2005-09-19 01:07:29 +02:00
final String [ ] content = file . list ( ) ;
2005-04-07 21:19:42 +02:00
for ( int i = 0 ; i < content . length ; i + + ) ( new File ( file , content [ i ] ) ) . delete ( ) ;
file . delete ( ) ;
} else if ( file . isFile ( ) ) {
file . delete ( ) ;
if ( filemd5 . exists ( ) ) filemd5 . delete ( ) ;
}
// delete index
2007-10-01 14:30:23 +02:00
final String urlstring = yacyhURL ( yacyCore . seedDB . mySeed ( ) , filename , md5s ) ;
2005-09-19 01:07:29 +02:00
final String phrase = filename . replace ( '.' , ' ' ) . replace ( '_' , ' ' ) . replace ( '-' , ' ' ) ;
2005-04-07 21:19:42 +02:00
deletePhrase ( switchboard , urlstring , phrase , description ) ;
}
}
2005-09-19 01:07:29 +02:00
2005-04-07 21:19:42 +02:00
// if authorized, generate directory tree listing
if ( ( adminAuthorization ) | | ( uploadAuthorization ) | | ( downloadAuthorization ) ) {
// generate dir listing
2006-08-06 16:38:07 +02:00
md5DirFileFilter fileFilter = new md5DirFileFilter ( ) ;
final File [ ] list = dir . listFiles ( fileFilter ) ;
// sorting the dir list
dirlistComparator comparator = new dirlistComparator ( ) ;
Arrays . sort ( list , comparator ) ;
2005-04-07 21:19:42 +02:00
String md5s , description ;
2005-09-19 01:07:29 +02:00
// tree += "<span class=\"tt\">path = " + path + "</span><br><br>";
2006-08-06 10:09:39 +02:00
if ( list ! = null ) {
int filecount = 0 , fileIdx = 0 ;
2007-07-23 02:50:57 +02:00
prop . put ( " path " , path ) ;
2006-08-06 10:09:39 +02:00
2005-09-19 01:07:29 +02:00
boolean dark = false ;
for ( int i = 0 ; i < list . length ; i + + ) {
2006-08-06 16:38:07 +02:00
filecount + + ;
File f = list [ i ] ;
String fileName = f . getName ( ) ;
// changing table row color
prop . put ( " dirlist_ " + fileIdx + " _dark " , dark ? 1 : 0 ) ;
dark = ! dark ;
// reading the content of the md5 file that belongs
// to the file
File fmd5 = new File ( dir , fileName + " .md5 " ) ;
try {
if ( fmd5 . exists ( ) ) {
md5s = new String ( serverFileUtils . read ( fmd5 ) ) ;
pos = md5s . indexOf ( '\n' ) ;
if ( pos > = 0 ) {
// the second line contains an optional description
description = md5s . substring ( pos + 1 ) ;
// the first line contains the md5 sum of the file
md5s = md5s . substring ( 0 , pos ) ;
2005-09-19 01:07:29 +02:00
} else {
description = " " ;
2006-08-06 16:38:07 +02:00
}
} else {
// generate md5 on-the-fly
md5s = serverCodings . encodeMD5Hex ( f ) ;
2005-09-19 01:07:29 +02:00
description = " " ;
2006-08-06 16:38:07 +02:00
serverFileUtils . write ( ( md5s + " \ n " + description ) . getBytes ( " UTF-8 " ) , fmd5 ) ;
2005-09-19 01:07:29 +02:00
}
2006-08-06 16:38:07 +02:00
} catch ( IOException e ) {
md5s = " " ;
description = " " ;
}
// last modification date if the entry
prop . put ( " dirlist_ " + fileIdx + " _dir_date " , dateString ( new Date ( f . lastModified ( ) ) ) ) ;
2007-03-23 07:25:21 +01:00
prop . put ( " dirlist_ " + fileIdx + " _dir_rfc822date " , httpc . dateString ( new Date ( f . lastModified ( ) ) ) ) ;
2006-10-24 14:13:46 +02:00
prop . put ( " dirlist_ " + fileIdx + " _dir_timestamp " , Long . toString ( f . lastModified ( ) ) ) ;
2006-08-06 16:38:07 +02:00
// the entry name
2007-07-23 02:50:57 +02:00
prop . put ( " dirlist_ " + fileIdx + " _dir_name " , fileName ) ;
2006-08-06 16:38:07 +02:00
if ( f . isDirectory ( ) ) {
// the entry is a directory
prop . put ( " dirlist_ " + fileIdx + " _dir " , 1 ) ;
2007-10-01 14:30:23 +02:00
prop . put ( " dirlist_ " + fileIdx + " _dir_URL " , " http:// " + yacyCore . seedDB . mySeed ( ) . getPublicAddress ( ) + path + fileName + " / " ) ;
2006-08-06 16:38:07 +02:00
} else {
// determine if we should display the description string or a preview image
2007-07-15 14:55:41 +02:00
boolean showImage = /* (description.length() == 0) && */ ( fileName . endsWith ( " .jpg " ) | | fileName . endsWith ( " .gif " ) | | fileName . endsWith ( " .png " ) | | fileName . endsWith ( " .ico " ) | | fileName . endsWith ( " .bmp " ) ) ;
2006-08-06 16:38:07 +02:00
// the entry is a file
prop . put ( " dirlist_ " + fileIdx + " _dir " , 0 ) ;
// the file size
2006-10-24 14:13:46 +02:00
prop . put ( " dirlist_ " + fileIdx + " _dir_size " , serverMemory . bytesToString ( f . length ( ) ) ) ;
prop . put ( " dirlist_ " + fileIdx + " _dir_sizeBytes " , Long . toString ( f . length ( ) ) ) ;
2006-08-06 16:38:07 +02:00
// the unique url
2007-10-01 14:30:23 +02:00
prop . put ( " dirlist_ " + fileIdx + " _dir_yacyhURL " , yacyhURL ( yacyCore . seedDB . mySeed ( ) , fileName , md5s ) ) ;
prop . put ( " dirlist_ " + fileIdx + " _dir_URL " , " http:// " + yacyCore . seedDB . mySeed ( ) . getPublicAddress ( ) + path + fileName ) ;
2006-08-06 16:38:07 +02:00
// the md5 sum of the file
prop . put ( " dirlist_ " + fileIdx + " _dir_md5s " , md5s ) ;
// description mode: 0...image preview, 1...description text
prop . put ( " dirlist_ " + fileIdx + " _dir_descriptionMode " , showImage ? 0 : 1 ) ;
if ( showImage ) {
prop . put ( " dirlist_ " + fileIdx + " _dir_descriptionMode_image " , fileName ) ;
2007-03-23 07:25:21 +01:00
}
// always set the description tag (needed by rss and xml)
2007-07-23 02:50:57 +02:00
prop . put ( " dirlist_ " + fileIdx + " _dir_descriptionMode_text " , description ) ;
2005-04-07 21:19:42 +02:00
}
2006-08-06 16:38:07 +02:00
prop . put ( " dirlist_ " + fileIdx + " _adminAuthorization " , adminAuthorization ? 1 : 0 ) ;
prop . put ( " dirlist_ " + fileIdx + " _adminAuthorization_name " , fileName ) ;
fileIdx + + ;
2005-04-07 21:19:42 +02:00
}
2006-08-06 16:38:07 +02:00
2006-08-06 10:09:39 +02:00
prop . put ( " dirlist " , filecount ) ;
prop . put ( " emptydir " , filecount = = 0 ? 1 : 0 ) ;
2005-04-07 21:19:42 +02:00
}
2006-08-06 10:09:39 +02:00
prop . put ( " authenticated " , 1 ) ;
} else {
prop . put ( " authenticated " , 0 ) ;
2005-04-07 21:19:42 +02:00
}
2006-08-06 10:09:39 +02:00
2005-04-07 21:19:42 +02:00
if ( adminAuthorization ) {
2006-08-06 16:38:07 +02:00
prop . put ( " ident " , 0 ) ;
prop . put ( " logout " , 0 ) ;
prop . put ( " account " , 0 ) ;
prop . put ( " service " , 0 ) ;
prop . put ( " info " , 0 ) ;
2005-04-07 21:19:42 +02:00
} else if ( uploadAuthorization ) {
2006-08-06 16:38:07 +02:00
prop . put ( " ident " , 1 ) ;
prop . put ( " logout " , 1 ) ;
prop . put ( " account " , 1 ) ;
prop . put ( " service " , 0 ) ;
prop . put ( " info " , 1 ) ;
2005-04-07 21:19:42 +02:00
} else if ( downloadAuthorization ) {
2006-08-06 16:38:07 +02:00
prop . put ( " ident " , 2 ) ;
prop . put ( " logout " , 2 ) ;
prop . put ( " account " , 2 ) ;
prop . put ( " service " , 1 ) ;
prop . put ( " info " , 2 ) ;
2005-04-07 21:19:42 +02:00
} else {
2006-08-06 16:38:07 +02:00
prop . put ( " ident " , 3 ) ;
prop . put ( " logout " , 3 ) ;
prop . put ( " account " , 3 ) ;
prop . put ( " service " , 2 ) ;
prop . put ( " info " , 3 ) ;
2005-04-07 21:19:42 +02:00
}
2006-08-06 16:38:07 +02:00
// return rewrite properties
2005-09-19 01:07:29 +02:00
return prop ;
2005-04-07 21:19:42 +02:00
}
public static String yacyhURL ( yacySeed seed , String filename , String md5 ) {
return " http://share. " + seed . getHexHash ( ) + " .yacyh/ " + filename + " ?md5= " + md5 ;
}
2005-09-19 01:07:29 +02:00
2006-10-19 23:14:37 +02:00
public static void indexPhrase ( plasmaSwitchboard switchboard , String urlstring , String phrase , String descr , byte [ ] md5 ) {
2005-04-07 21:19:42 +02:00
try {
2007-09-05 11:01:35 +02:00
final yacyURL url = new yacyURL ( urlstring , null ) ;
2006-11-28 16:00:15 +01:00
final plasmaCondenser condenser = new plasmaCondenser ( new ByteArrayInputStream ( ( " yacyshare. " + phrase + " . " + descr ) . getBytes ( ) ) , " UTF-8 " ) ;
2007-08-15 13:36:59 +02:00
final indexURLEntry newEntry = new indexURLEntry (
2006-10-19 23:14:37 +02:00
url ,
" YaCyShare: " + descr ,
2007-10-01 14:30:23 +02:00
yacyCore . seedDB . mySeed ( ) . getName ( ) ,
2006-10-19 23:14:37 +02:00
" " , // tags
" " , // ETag
new Date ( ) , // modification
new Date ( ) , // loadtime
new Date ( ) , // freshtime
" AAAAAAAAAAAA " , // referrer
md5 , // md5
2007-10-19 06:13:46 +02:00
phrase . length ( ) , // size
2006-10-19 23:14:37 +02:00
condenser . RESULT_NUMB_WORDS , // word count
2007-09-05 11:01:35 +02:00
plasmaHTCache . DT_SHARE , // doctype
2006-11-23 03:16:30 +01:00
new kelondroBitfield ( 4 ) ,
2006-10-19 23:14:37 +02:00
" ** " , // language
0 , 0 , 0 , 0 , 0 , 0
2005-04-07 21:19:42 +02:00
) ;
2006-12-05 03:47:51 +01:00
switchboard . wordIndex . loadedURL . store ( newEntry ) ;
switchboard . wordIndex . loadedURL . stack (
2006-03-17 11:16:07 +01:00
newEntry ,
" ____________ " , /*initiator*/
2007-10-01 14:30:23 +02:00
yacyCore . seedDB . mySeed ( ) . hash , /*executor*/
2006-03-17 11:16:07 +01:00
5 /*process case*/
) ;
2007-09-05 11:01:35 +02:00
/*final int words =*/ switchboard . wordIndex . addPageIndex ( url , new Date ( ) , phrase . length ( ) + descr . length ( ) + 13 , null , condenser , " ** " , plasmaHTCache . DT_SHARE , 0 , 0 ) ;
2005-04-07 21:19:42 +02:00
} catch ( IOException e ) { }
}
public static void deletePhrase ( plasmaSwitchboard switchboard , String urlstring , String phrase , String descr ) {
try {
2007-09-05 11:01:35 +02:00
final String urlhash = ( new yacyURL ( urlstring , null ) ) . hash ( ) ;
2006-12-06 14:13:55 +01:00
final Iterator words = plasmaCondenser . getWords ( ( " yacyshare " + phrase + " " + descr ) . getBytes ( " UTF-8 " ) , " UTF-8 " ) . keySet ( ) . iterator ( ) ;
String word ;
2006-01-22 01:07:00 +01:00
while ( words . hasNext ( ) ) {
2006-12-06 14:13:55 +01:00
word = ( String ) words . next ( ) ;
switchboard . wordIndex . removeEntry ( plasmaCondenser . word2hash ( word ) , urlhash ) ;
2006-01-22 01:07:00 +01:00
}
2006-12-05 03:47:51 +01:00
switchboard . wordIndex . loadedURL . remove ( urlhash ) ;
2005-04-07 21:19:42 +02:00
} catch ( Exception e ) {
2005-08-31 00:05:46 +02:00
serverLog . logSevere ( " DIR " , " INTERNAL ERROR in dir.deletePhrase " , e ) ;
2005-04-07 21:19:42 +02:00
}
}
2005-09-19 01:07:29 +02:00
2005-04-07 21:19:42 +02:00
}