start of new file
[IRC.git] / Robust / src / Benchmarks / Conglomerator / Tag / Lookup.java
1 public class Lookup extends Socket {
2     flag query;
3     flag initialstate;
4     flag done;
5
6     boolean exclusive;
7     String url;
8     String hostname;
9     String data;
10     String start;
11     String end;
12
13     public void doLookup() {
14         String query="GET /"+url+" HTTP/1.1\r\nConnection: close\r\nHost:"+hostname+"\r\n\r\n";
15         connect(hostname, 80);
16         write(query.getBytes());
17     }
18
19     public boolean Receive() {
20         byte[] buffer=new byte[1024];
21         int numchars=read(buffer);
22         if (numchars<=0) {
23             fix();
24             close();
25             return true;
26         }
27         String str=new String(buffer, 0, numchars);
28         if (data==null) {
29             data=str;
30         } else
31             data=data+str;
32         return false;
33     }
34                 
35     public void fix() {
36         int istart=data.indexOf(start);
37         int iend=data.indexOf(end);
38         if (exclusive)
39             data=data.substring(istart+start.length(), iend);
40         else
41             data=data.substring(istart, iend+end.length());
42         String m1="src=\"/";
43         String m2="src=\'/";
44         String m3="href=\"/";
45         boolean cnt=true;
46         while(cnt) {
47             if (data.indexOf(m1)!=-1) {
48                 int index=data.indexOf(m1)-1;
49                 data=data.substring(0,index+m1.length())+"http://"+hostname+data.substring(index+m1.length(),data.length());
50             } else if (data.indexOf(m2)!=-1) {
51                 int index=data.indexOf(m2)-1;
52                 data=data.substring(0,index+m2.length())+"http://"+hostname+data.substring(index+m2.length(),data.length());
53             } else if (data.indexOf(m3)!=-1) {
54                 int index=data.indexOf(m3)-1;
55                 data=data.substring(0,index+m3.length())+"http://"+hostname+data.substring(index+m3.length(),data.length());
56             } else cnt=false;
57         }
58         
59     }   
60         
61
62 }