6 import java.rmi.registry.*;
\r
10 static private BufferedReader $con = null;
\r
11 static private HashMap $cache = null;
\r
12 static private Nameserver.MyDNS $root = null;
\r
13 static private Registry $reg = null;
\r
14 static private Properties $prop = new Properties();
\r
17 static public void main(String[] $args)throws Exception{
\r
18 $con = new BufferedReader (new InputStreamReader(System.in));
\r
19 $cache = new HashMap();
\r
21 InputStream $in = ClassLoader.getSystemResourceAsStream("registry.properties");
\r
23 System.err.println("ERROR: Properties file not found!");
\r
30 $reg = LocateRegistry.getRegistry($prop.getProperty("registry.host"), Integer.parseInt($prop.getProperty("registry.port")));
\r
31 $root = (Nameserver.MyDNS) $reg.lookup("rmi://"+$prop.getProperty("registry.host")+":"+$prop.getProperty("registry.port")+"/"+$prop.getProperty("ro_id"));
\r
33 while($con != null)try{
\r
34 System.out.println("Enter url (or '!exit' or !cc)");
\r
35 auswertung($con.readLine().trim());
\r
36 }catch(Exception $e){$e.printStackTrace();} //Eingaben auswerten
\r
39 static public void auswertung(String $eingraw)throws Exception{
\r
40 if($eingraw.equals("") || $eingraw == null)return; // Ignore null-commands
\r
41 String[] $eing = $eingraw.split("\\s+"); //regex: whitespace character one and more
\r
43 if($eing[0].equalsIgnoreCase("!exit")){
\r
46 if($eing[0].equalsIgnoreCase("!cc")){
\r
47 $cache = new HashMap();
\r
50 try{getFile($eingraw.trim());}catch(Exception $e){System.out.println($e.getMessage());}
\r
53 static public void getFile(String $addr)throws Exception{
\r
54 System.out.println("reqest File:"+$addr);
\r
55 if($addr.charAt(0)=='/'){
\r
56 System.out.println("Hostname not given!");
\r
59 if($addr.indexOf('/')== -1){
\r
60 System.out.println("File not given!");
\r
63 String $tempa[] = $addr.split("/");
\r
64 String $hostp[] = $tempa[0].split("\\.");
\r
65 String $path = $addr.replaceFirst($tempa[0],"");
\r
67 System.out.println($tempa[0]);
\r
68 System.out.println($path);
\r
70 //requestor is allways starting at root, requested allways at last hostpart
\r
71 Nameserver.MyBase $requestto = $root;
\r
72 String $requested = "";
\r
74 for(int $i = $hostp.length-1; $i >= 0; $i--){ //do not request last part - as it is the fileserver!
\r
75 Nameserver.MyBase $tempobj = (Nameserver.MyBase)$cache.get($hostp[$i]+"."+$requested);
\r
76 if($tempobj == null){ //object not cached - request!
\r
77 if($requestto.getMyType() != 1){
\r
78 System.out.println("Never look for a penis on a girls body. Your requested host ist not a Nameserver: "+$requested+". Your requested hostname:"+$tempa[0]);
\r
82 $tempobj = (Nameserver.MyBase)((Nameserver.MyDNS)$requestto).getServiceRecord($hostp[$i]);
\r
83 $cache.put($hostp[$i]+"."+$requested, $tempobj);
\r
85 $requestto = $tempobj;
\r
86 $requested = $hostp[$i]+"."+$requested;
\r
89 System.out.println($reqcnt+" reqests done to find: "+$requested);
\r
90 if($requestto.getMyType() != 2){
\r
91 System.out.println("Never look for a penis on a girls body. Your requested host ist not a Fileserver: "+ $requested);
\r
94 System.out.println(((Fileserver.MyFS)$requestto).readFile($path));
\r