Add web interface. It defaults to port 8000.
authorbdemsky <bdemsky>
Tue, 22 May 2007 04:30:54 +0000 (04:30 +0000)
committerbdemsky <bdemsky>
Tue, 22 May 2007 04:30:54 +0000 (04:30 +0000)
17 files changed:
Robust/src/Analysis/TaskStateAnalysis/FlagState.java
Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java
Robust/src/Analysis/TaskStateAnalysis/TaskNode.java
Robust/src/IR/State.java
Robust/src/Interface/HTTPHeader.java [new file with mode: 0644]
Robust/src/Interface/HTTPResponse.java [new file with mode: 0644]
Robust/src/Interface/HTTPServices.java [new file with mode: 0644]
Robust/src/Interface/HashStrings.java [new file with mode: 0644]
Robust/src/Interface/IdentityRelation.java [new file with mode: 0644]
Robust/src/Interface/Imap.java [new file with mode: 0644]
Robust/src/Interface/JhttpServer.java [new file with mode: 0644]
Robust/src/Interface/JhttpWorker.java [new file with mode: 0644]
Robust/src/Interface/LogFile.java [new file with mode: 0644]
Robust/src/Interface/WebInterface.java [new file with mode: 0644]
Robust/src/Main/Main.java
Robust/src/Makefile
Robust/src/buildscript

index b9890f645623c52adcba0af8299b10398b98b7ce..682333ff618965cafb2c95d2cd4724f454f66906 100644 (file)
@@ -22,14 +22,6 @@ public class FlagState extends GraphNode {
     private final ClassDescriptor cd;
     private final Hashtable<TagDescriptor,Integer> tags;
 
-    public void setOption(String option) {
-       this.nodeoption=","+option;
-    }
-
-    public void setMerge() {
-       merge=true;
-    }
-
     /** Class constructor
      *  Creates a new flagstate with all flags set to false.
      * @param cd ClassDescriptor
index 224738c0d4bdda371109c0ed2aab867cea401a55..fbdcfcdd931d69a8510843a7fb0f7042c2282e46 100644 (file)
@@ -84,7 +84,9 @@ public class TaskGraph {
                    for (Iterator it_edges=fs.edges();it_edges.hasNext();){
                        TaskNode target=new TaskNode(((FEdge)it_edges.next()).getLabel());
                        target=(TaskNode)canonicalizeTaskNode(tasknodes,target);
-                       tn.addEdge(new TEdge(target));
+                       TEdge tedge=new TEdge(target);
+                       //                      if (!tn.edges.contains(tedge))
+                           tn.addEdge(new TEdge(target));
                    }
                }
            } while(it_inedges.hasNext());
index babae4b11c7af83ca04e5bad64ab11d52f264e52..2d5eec3504ba5cae177dd5afc306c3eafe55170e 100644 (file)
@@ -9,14 +9,10 @@ import Util.GraphNode;
 
 public class TaskNode extends GraphNode {
        
-       private final String name;
-       private int uid;
+    private final String name;
+    private int uid;
     private static int nodeid=0;
     
-    public void setOption(String option) {
-       this.nodeoption=","+option;
-    }
-
     /**Class Constructor
      * Creates a new TaskNode using the TaskDescriptor.
      * @param tasknode TaskDescriptor
index ed3e5979eeb8a23224870b91477d2ac3e3185a73..eadd05f2ebc104540e141d7c34d85d2c0c0aa670 100644 (file)
@@ -22,6 +22,7 @@ public class State {
 
     /** Boolean flag which indicates whether compiler is compiling a task-based
      * program. */
+    public boolean WEBINTERFACE;
     public boolean TASK;
     public boolean TASKSTATE=false;
     public boolean THREAD=false;
diff --git a/Robust/src/Interface/HTTPHeader.java b/Robust/src/Interface/HTTPHeader.java
new file mode 100644 (file)
index 0000000..db7d206
--- /dev/null
@@ -0,0 +1,110 @@
+package Interface;
+//****************************************************************************
+// Programmer: Duane M. Gran, ragnar@cs.bsu.edu
+// Program:    JhttpServer
+// Date:       April 24, 1998
+//****************************************************************************
+
+
+import java.net.*;
+import java.util.*;
+import java.io.*;
+
+//****************************************************************************
+// Class:   httpResponse
+// Purpose: constructs the header to be returned by the server
+//****************************************************************************
+
+public class HTTPHeader{
+
+  // make a hashtable of return codes to messages
+  static private HashStrings rc = new HashStrings();
+  static
+  {
+    rc.put("200", "OK");
+    rc.put("403", "Fobidden");
+    rc.put("404", "Not found");
+    rc.put("501", "Method not implemented");
+  }
+
+  // hashtable of content type matchings
+  static private HashStrings ct = new HashStrings();   // p. 817
+  static
+  {
+    ct.put("txt",   "text/plain");
+    ct.put("text",  "text/plain");
+    ct.put("log",   "text/plain");
+    ct.put("htm",   "text/html");
+    ct.put("html",  "text/html");
+    ct.put("gif",   "image/gif");
+    ct.put("jpg",   "image/jpg");
+    ct.put("jpeg",  "image/jpg");
+    ct.put("jpe",   "image/jpg");
+    ct.put("mpg",   "video/mpeg");
+    ct.put("mpeg",  "video/mpeg");
+    ct.put("mpe",   "video/mpeg");
+    ct.put("qt",    "video/quicktime");
+    ct.put("mov",   "video/quicktime");
+    ct.put("au",    "audio/basic");
+    ct.put("snd",   "audio/basic");
+    ct.put("wav",   "audio/x-wave");
+    ct.put("class", "application/octet-stream");
+    ct.put("ps", "application/postscript");
+  }
+  
+//*************************************************************************
+// Constructor: send_header(int, String, int)
+// Purpose:     Send an HTTP header
+//*************************************************************************
+
+  static public void send_header(BufferedWriter out, int returnCode,
+                                  String filename, long fileLength){
+      String contentType  = getContentTypeFor(filename);
+      String returnString = (String) rc.get(String.valueOf(returnCode));
+      String header;
+
+      header = "HTTP/1.0 " + returnCode + " " + returnString + "\n" +
+         "Date: " + "1/1/01" + "\n" +                   // date
+         "Expires: 1/1/00\n"+
+         "Allow: GET\n" +                               // allowed methods
+         "MIME-Version: 1.0\n" +                        // mime version
+         "Server : SpinWeb Custom HTTP Server\n" +      // server type
+         "Content-Type: " + contentType + "\n" +        // type
+         "Content-Length: "+ fileLength + "\n\n";       // length
+      try{
+         out.write(header,0,header.length());
+      }
+      catch(IOException e){
+         ; // do nothing!
+      }
+  }
+
+//*************************************************************************
+// Method:  getContentTypeFor(String)
+// Purpose: Looks up the content type (MIME) in a hashtable for the given
+//          file suffix.  It removes any anchors (#) in case the string is
+//          a URL and then operates on the name without path.
+//*************************************************************************
+  
+  static private String getContentTypeFor(String filename)
+  {
+    int position = filename.lastIndexOf('#');
+    if (position != -1)
+      filename = filename.substring(0, position - 1);
+      
+    File f      = new File(filename);
+    String name = f.getName();         // name w/o directory
+
+    position = name.lastIndexOf('.');
+    
+    String contentType;
+
+    if (position == -1)  // if no extension, txt is assigned by default
+       contentType = "txt";    
+    else  
+       contentType = name.substring(position + 1);
+    
+    return (String) ct.get(contentType);
+  } 
+
+}
diff --git a/Robust/src/Interface/HTTPResponse.java b/Robust/src/Interface/HTTPResponse.java
new file mode 100644 (file)
index 0000000..74c532f
--- /dev/null
@@ -0,0 +1,7 @@
+package Interface;
+
+
+public class HTTPResponse{
+    public int returnCode;
+    public long sentBytes;
+}
diff --git a/Robust/src/Interface/HTTPServices.java b/Robust/src/Interface/HTTPServices.java
new file mode 100644 (file)
index 0000000..be380a0
--- /dev/null
@@ -0,0 +1,89 @@
+package Interface;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+public class HTTPServices{
+
+    static private String webRoot = ".";
+
+    static private Reader get_reader(String fileName,HTTPResponse resp) throws IOException{
+       try{
+//         if(fileName.equals("/daytime")){
+//             String date_str = (new Date()).toString();
+//             resp.sentBytes = date_str.length();
+//             return
+//                 new StringReader(date_str);
+//         }
+           
+           if(fileName.equals("/viewlog"))
+               fileName = LogFile.log_file_name;
+           else
+               fileName = webRoot + fileName;
+           
+           File f = new File(fileName);
+           resp.sentBytes = f.length();
+           return new FileReader(f);
+       }
+       catch(IOException e){
+           resp.returnCode = 501;
+           return
+               new StringReader("Error accessing " + fileName);
+       }
+    }
+
+    public static void GET_handler(String fileName, BufferedWriter out,HTTPResponse resp){
+       
+       BufferedReader reader  = null;
+       char buffer[];
+       int size;
+
+       if((reader = HEAD_handler_int(fileName,out,resp)) == null) return;
+
+       buffer = new char[1024];
+
+       try{
+           while((size = reader.read(buffer,0,buffer.length)) != -1)
+               out.write(buffer,0,size);
+           reader.close();
+       }
+       catch(IOException e){
+           e.printStackTrace();
+           resp.returnCode = 501; // error during transmision
+       }
+
+    }
+
+    public static void POST_handler(String fileName, BufferedWriter out, HTTPResponse resp){
+       GET_handler(fileName,out,resp);
+    }
+
+    static private BufferedReader HEAD_handler_int(String fileName,
+                                                   BufferedWriter out,HTTPResponse resp){
+       BufferedReader reader = null;
+
+       try{
+           reader = new BufferedReader(get_reader(fileName, resp));
+           resp.returnCode = 200;
+       }
+       catch(IOException e){
+           resp.returnCode = 404; // file not found
+       }
+
+       if(resp.returnCode == 200)
+           HTTPHeader.send_header(out, resp.returnCode, fileName, resp.sentBytes);
+       else{
+           HTTPHeader.send_header(out, resp.returnCode, fileName, 0);
+           return null;
+       }
+       
+       return reader;
+    }
+       
+
+    public static void HEAD_handler(String fileName, 
+                                  BufferedWriter out, HTTPResponse resp){
+       HEAD_handler_int(fileName,out,resp);
+    }
+}
+
diff --git a/Robust/src/Interface/HashStrings.java b/Robust/src/Interface/HashStrings.java
new file mode 100644 (file)
index 0000000..6706578
--- /dev/null
@@ -0,0 +1,39 @@
+package Interface;
+
+class HashStrings {
+    Pair p[]; // entries in the hash table
+    int f;    // number of full entries
+    public HashStrings() { p = new Pair[38]; f = 0; }
+
+    public void put(String key, String value) {
+       int n = p.length;
+       if (f  == n-1) return; // cheese -- a diary product
+       int i = key.hashCode() % n;
+       while (p[i] != null) {
+           if (key.equals(p[i].key)) {
+               p[i] = new Pair(key, value);
+               return;
+           }
+           i = (i+1) % n;
+       }
+       p[i] = new Pair(key, value);
+       f = f + 1;
+    }
+
+    public String get(String key) {
+       int n = p.length;
+       int i = key.hashCode() % n;
+       while (p[i] != null) {
+           if (key.equals(p[i].key))
+               return p[i].value;
+           i = (i+1) % n;
+       }
+       return null;
+    }
+
+}
+
+class Pair {
+    String key, value;
+    Pair (String key, String value) { this.key = key; this.value = value; }
+}
diff --git a/Robust/src/Interface/IdentityRelation.java b/Robust/src/Interface/IdentityRelation.java
new file mode 100644 (file)
index 0000000..04d2888
--- /dev/null
@@ -0,0 +1,27 @@
+package Interface;
+class IdentityRelation{
+    String fieldname1;
+    String fieldname2;
+
+    public IdentityRelation(String fieldname1,String fieldname2) {
+       this.fieldname1=fieldname1;
+       this.fieldname2=fieldname2;
+    }
+    public String toString() {
+       return fieldname1+"."+fieldname2;
+    }
+
+    public int hashCode() {
+       return fieldname1.hashCode()^fieldname2.hashCode();
+    }
+
+    public boolean equals(Object obj) {
+       if (obj instanceof IdentityRelation) {
+           IdentityRelation ir=(IdentityRelation) obj;
+           if (fieldname1.equals(ir.fieldname1)&&
+               fieldname2.equals(ir.fieldname2))
+               return true;
+       }
+       return false;
+    }
+}
diff --git a/Robust/src/Interface/Imap.java b/Robust/src/Interface/Imap.java
new file mode 100644 (file)
index 0000000..33763fd
--- /dev/null
@@ -0,0 +1,148 @@
+package Interface;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+class Imap {
+    private Rectangle[] rectangles;
+    private Point[] points;
+    long THRESHOLD=400;
+
+    public Imap(String filename) {
+       FileReader fr=null;
+       try {
+           fr=new FileReader(filename);
+           parseFile(fr);
+           fr.close();
+       } catch (IOException e) {
+           System.out.println(e);
+           System.exit(-1);
+       }
+    }
+    static class Rectangle {
+       String label;
+       int x1,y1,x2,y2;
+       public Rectangle(String label, int x1,int y1, int x2, int y2) {
+           this.label=label;
+           this.x1=x1;
+           this.y1=y1;
+           this.x2=x2;
+           this.y2=y2;
+       }
+    }
+
+    String parseclick(int x,int y) {
+       System.out.println(x+","+y);
+       for(int i=0;i<rectangles.length;i++) {
+           Rectangle r=rectangles[i];
+           if ((r.x1<=x)&&(r.y1>=y)&&
+               (r.x2>=x)&&(r.y2<=y))
+               return r.label;
+       }
+       long mindistance=Long.MAX_VALUE;
+       int minindex=-1;
+       for(int i=0;i<points.length;i++) {
+           Point p=points[i];
+           long dx=p.x-x;
+           long dy=p.y-y;
+           if ((dx*dx+dy*dy)<mindistance) {
+               mindistance=dx*dx+dy*dy;
+               minindex=i;
+           }
+       }
+       if (mindistance>THRESHOLD)
+           return null;
+       else
+           return points[minindex].label;
+    }
+
+    static class Point {
+       String label;
+       int x,y;
+       public Point(String label, int x,int y) {
+           this.label=label;
+           this.x=x;
+           this.y=y;
+       }
+    }
+
+    void parseFile(FileReader fr) {
+       int firstchar=0;
+       ArrayList rectangles=new ArrayList();
+       ArrayList points=new ArrayList();
+       while(true) {
+           try {
+               firstchar=fr.read();
+           } catch (Exception e) {
+               e.printStackTrace();
+               System.exit(-1);
+           }
+           /* EOF?*/
+           if (firstchar==-1)
+               break;
+           switch(firstchar) {
+               case'b':
+                   case'#':
+                   while(firstchar!='\n') {
+                       try {
+                           firstchar=fr.read();
+                       } catch (IOException e) {
+                           e.printStackTrace();
+                           System.exit(-1);
+                       }
+                   }
+               break;
+               case'r':
+                   {
+                       nexttoken(fr,false);
+                       String label=nexttoken(fr,false);
+                       String x1=nexttoken(fr,true);
+                       String y1=nexttoken(fr,true);
+                       String x2=nexttoken(fr,true);
+                       String y2=nexttoken(fr,true);
+                       Rectangle r=new Rectangle(label,Integer.parseInt(x1),Integer.parseInt(y1),
+                                                 Integer.parseInt(x2),Integer.parseInt(y2));
+                       rectangles.add(r);
+                   }
+               break;
+               case'p':
+                   {
+                       nexttoken(fr,false);
+                       String label=nexttoken(fr,false);
+                       String x=nexttoken(fr,true);
+                       String y=nexttoken(fr,true);
+                       Point p=new Point(label,Integer.parseInt(x),Integer.parseInt(y));
+                       points.add(p);
+                   }
+               break;
+           }
+       }
+       this.rectangles=(Rectangle[]) rectangles.toArray(new Rectangle[rectangles.size()]);
+       this.points=(Point[]) points.toArray(new Point[points.size()]);
+    }
+
+    String nexttoken(java.io.InputStreamReader isr,boolean commas) {
+       String string="";
+       int c=0;
+       boolean looped=false;
+       while(true) {
+           try {
+               c=isr.read();
+           } catch (IOException e) {
+               e.printStackTrace();
+               System.exit(-1);
+           }
+           if ((c==' ')||(c=='\n')||(commas&&c==',')) {
+               if (!looped) {
+                   looped=true;
+                   continue;
+               }
+               return string;
+           }
+           string=string+new String(new char[]{(char)c});
+           looped=true;
+       }
+    }
+
+}
+
diff --git a/Robust/src/Interface/JhttpServer.java b/Robust/src/Interface/JhttpServer.java
new file mode 100644 (file)
index 0000000..9cf6726
--- /dev/null
@@ -0,0 +1,49 @@
+package Interface;
+
+//****************************************************************************
+// Programmer: Duane M. Gran, ragnar@cs.bsu.edu
+// Program:    JhttpServer
+// Date:       April 24, 1998
+//****************************************************************************
+
+import java.net.*;
+import java.io.*;
+
+public class JhttpServer extends Thread{
+
+    private ServerSocket server;
+    private WebInterface webinterface;
+
+//****************************************************************************
+// Constructor: JhttpServer(int)
+//****************************************************************************
+    public JhttpServer(int port, WebInterface webinterface)
+    {
+       System.out.println("starting...");
+       this.webinterface=webinterface;
+       try{
+           System.out.println("creating the port");
+           server = new ServerSocket(port);
+       }
+       catch (IOException e){
+           System.err.println(e);
+           System.exit(1);
+       }
+    }
+
+    private void startWorker(Socket client) throws Exception {
+       (new JhttpWorker(client,false,webinterface)).start();
+    }
+
+    public void run(){
+       // infinite loop 
+       while (true){
+           try{
+               startWorker(server.accept());
+           }
+           catch (Exception e){
+               System.err.println(e);
+           }
+       }
+    }
+}
diff --git a/Robust/src/Interface/JhttpWorker.java b/Robust/src/Interface/JhttpWorker.java
new file mode 100644 (file)
index 0000000..f2f8bfe
--- /dev/null
@@ -0,0 +1,192 @@
+package Interface;
+//****************************************************************************
+// Programmer: Duane M. Gran, ragnar@cs.bsu.edu
+// Program:    JhttpServer
+// Date:       April 24, 1998
+//****************************************************************************
+
+
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+//****************************************************************************
+// Class:   JhttpWorker
+// Purpose: Takes an HTTP request and executes it in a separate thread
+//****************************************************************************
+
+public class JhttpWorker extends Thread{
+    public  String fileName = null;
+    public  String methodType = null;
+    public  String httpVersion = "http/1.0";
+    private Socket client;
+    public  int    fileLength, returnCode;
+    private boolean logging;
+    private WebInterface webinterface;
+
+    public JhttpWorker(Socket client, boolean logging, WebInterface webinterface) {
+       this.client=client;
+       this.logging=logging;
+       this.webinterface=webinterface;
+    }
+    
+    public void run(){ 
+       HTTPResponse resp = new HTTPResponse();
+
+       BufferedReader  in = null;
+       BufferedWriter out = null;
+
+       resp.returnCode = 200;
+       resp.sentBytes = 0;
+
+       try{
+
+           in = new BufferedReader(
+                  new InputStreamReader(
+                   client.getInputStream()));
+
+           out = new BufferedWriter(
+                  new OutputStreamWriter(
+                   client.getOutputStream()));
+       }
+       catch(IOException e){
+           // I'm not too good at HTTP. Normally, we should put some
+           // error code here. Anyway, I have assumed that an error
+           // is equivalent to an unhandled request / method (501)
+           resp.returnCode = 501; 
+       }
+
+       if(resp.returnCode == 200){
+           // call the appropriate hanndler
+           switch(method(in)){
+           case 0:
+               if (webinterface.specialRequest(fileName)) {
+                   String newfile=webinterface.handleresponse(fileName, out, resp);
+                   if (newfile!=null) {
+                       HTTPServices.GET_handler(newfile, out, resp);
+                   }
+               } else
+                   HTTPServices.GET_handler(fileName, out, resp);
+               break;
+           case 1:
+               HTTPServices.HEAD_handler(fileName, out, resp);
+               break;
+           case 2:
+               HTTPServices.POST_handler(fileName, out, resp);
+               break;
+           default:
+               resp.returnCode = 501; //error
+           }
+           
+           try{
+               out.flush();
+               if (logging)
+                   LogFile.write_log(client,methodType,fileName,httpVersion,
+                                     resp.returnCode,resp.sentBytes);
+
+               out.close();
+               in.close();
+               client.close();
+           }
+           catch(IOException e){
+               ; // do nothing
+           }
+       }
+
+       //      System.out.println(fileName + " is going to finish"); // debug 
+    }
+  
+//*****************************************************************************
+// Function: method()
+// Purpose:  Open an InputStream and parse the request made.  
+// Note:     Regardless of what method is requested, right now it performs a
+//           GET operation.
+// Calls:    
+// Returns:  Boolean value for success or failure
+//*****************************************************************************
+
+  private int method(BufferedReader in){
+      int ret = -1;
+
+      try{
+         String line;
+         
+         // read just the first line
+         line = in.readLine();
+         // only spaces used
+         StringTokenizer tok = new StringTokenizer(line, " ");  
+         if (tok.hasMoreTokens())  // make sure there is a request
+             {
+                 String str = tok.nextToken();
+          
+                 if ( str.equals("GET") ){
+                     ret = 0;
+                     methodType = "GET";
+                 }
+                 else if ( str.equals("HEAD") ){
+                     ret = 1;
+                     methodType = "HEAD";
+                 }
+                 else if ( str.equals("POST") ){
+                     ret = 2;
+                     methodType = "POST";
+                 }
+                 else{
+                     System.out.println("501 - unsupported request:" +str);
+                     return -1;
+                 } 
+             }      
+         else{
+             // System.out.println("Request from browser was empty!");
+             return -1;
+         }
+         
+         // get the filename
+         if (tok.hasMoreTokens())
+             {
+                 fileName = tok.nextToken();
+                 if(fileName.equals("/"))
+                     {
+                         fileName = "/index.html";
+                     }
+             }
+         else
+             {
+                 // this is weird... why am i taking the first character of
+                 // the filename if there are no more tokens?
+                 // - catch should take care of this
+                 fileName = fileName.substring(1);
+             }  
+         
+         // read the http version number
+         // - right now nothing is done with this information
+         if (tok.hasMoreTokens())
+             {
+                 httpVersion = tok.nextToken();
+             }
+         else
+             {
+                 httpVersion = "http/1.0";              // default
+             }
+         
+         // read remainder of the browser's header
+         // - nothing done right now with this info... placeholder
+         while((line = in.readLine()) != null)
+             {
+                 StringTokenizer token = new StringTokenizer(line," ");
+                 
+                 // do processing here
+                 if(!token.hasMoreTokens())
+                     { 
+                         break;          
+                     }
+             }
+      }
+      catch(Exception e){
+         System.err.println(e);
+         return -1;
+      }
+      
+    return ret;
+  }
+}
diff --git a/Robust/src/Interface/LogFile.java b/Robust/src/Interface/LogFile.java
new file mode 100644 (file)
index 0000000..667b548
--- /dev/null
@@ -0,0 +1,73 @@
+package Interface;
+//****************************************************************************
+// Programmer: Duane M. Gran, ragnar@cs.bsu.edu
+// Program:    JhttpServer
+// Date:       April 24, 1998
+//****************************************************************************
+
+
+
+import java.io.*;
+import java.util.*;
+import java.text.SimpleDateFormat;
+import java.net.*;
+
+//****************************************************************************
+// Class:   logFile
+// Purpose: Handle the behavior for logging connections.  The methods simply
+//          add to the private data fields.  Has implementation for standard
+//          output, as well as output to file.
+//
+//          An example log entry looks like:
+//
+// 1.2.3.4 - - [29/JAN/1998:21:40:30 -06] "GET /file.html HTTP/1.0" 200 472
+//
+//****************************************************************************
+
+public class LogFile
+{
+    static public final String log_file_name = "server.log";
+
+    static public String write_log(Socket s, String Method, String URI,
+                                  String Protocol, 
+                                  int ReturnCode, long BytesSent){
+
+       // Socket.toString() calls (indirectly) some Hashtable.get
+       // method  - I tool care of it!
+
+       /*
+       String addr = s.toString();     
+       String Address = addr.substring(addr.indexOf('/') + 1,
+                                       addr.indexOf(','));
+       */
+
+       //      SimpleDateFormat sdf =
+       //          new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");  // RFC 1123
+       //      sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+       //      String Date = sdf.format(new Date());
+
+       String Entry = 
+           /* Address + */ " - - [" +                      // IP address
+           "Date" + "] \"" +                         // date
+           Method + " " +                            // get, post, head
+           URI + " " +                               // filename
+           Protocol + "\" " +                        // http/1.?
+           ReturnCode + " " +      // 200-500
+           BytesSent + "\n";       // bytes sent
+
+       try{
+           BufferedWriter out = new BufferedWriter(
+                                new OutputStreamWriter(
+                                new FileOutputStream(log_file_name, true)));
+           
+           out.write(Entry,0,Entry.length());
+           out.flush();
+           out.close();
+       }
+       catch (IOException e){
+           System.err.println("Gicu " + e);
+       }
+
+       return Entry;
+    }
+}
diff --git a/Robust/src/Interface/WebInterface.java b/Robust/src/Interface/WebInterface.java
new file mode 100644 (file)
index 0000000..6b3a983
--- /dev/null
@@ -0,0 +1,108 @@
+package Interface;
+import java.io.*;
+import Analysis.TaskStateAnalysis.*;
+import IR.*;
+import java.util.*;
+
+public class WebInterface {
+    TaskAnalysis taskanalysis;
+    TaskGraph taskgraph;
+    State state;
+    Hashtable taskmap;
+    Hashtable taskgraphmap;
+
+    public WebInterface(State state, TaskAnalysis taskanalysis, TaskGraph taskgraph) {
+       this.state=state;
+       this.taskanalysis=taskanalysis;
+       this.taskgraph=taskgraph;
+       taskmap=new Hashtable();
+       taskgraphmap=new Hashtable();
+    }
+    
+    public boolean specialRequest(String filename) {
+       System.out.println(filename);
+       if (filename.equals("/index.html"))
+           return true;
+       if (taskmap.containsKey(filename))
+           return true;
+       if (taskgraphmap.containsKey(filename))
+           return true;
+       return false;
+    }
+
+    public String handleresponse(String filename, BufferedWriter out, HTTPResponse resp) {
+       if (filename.equals("/index.html"))
+           return indexpage(out, resp);
+       if (taskmap.containsKey(filename))
+           return flagstate((ClassDescriptor) taskmap.get(filename), out, resp);
+       if (taskgraphmap.containsKey(filename))
+           return taskstate((ClassDescriptor) taskgraphmap.get(filename), out, resp);
+       return "NORESP";
+    }
+
+    private String flagstate(ClassDescriptor cd, BufferedWriter out, HTTPResponse resp) {
+       Set objects=taskanalysis.getFlagStates(cd);
+       File file=new File(cd.getSymbol()+".dot");
+       try {
+           //Generate jpg
+           Runtime r=Runtime.getRuntime();
+           FileOutputStream dotstream=new FileOutputStream(file,false);
+           FlagState.DOTVisitor.visit(dotstream, objects);
+           dotstream.close();
+           Process p=r.exec("dot -Tjpg "+cd.getSymbol()+".dot -o"+cd.getSymbol()+".jpg");
+           p.waitFor();
+           p=r.exec("dot -Tps "+cd.getSymbol()+".dot -o"+cd.getSymbol()+".ps");
+           p.waitFor();
+
+           PrintWriter pw=new PrintWriter(out);
+           pw.println("<a href=\"/"+ cd.getSymbol()+".ps\">ps</a><br>");
+           pw.println("<img src=\"/"+ cd.getSymbol()+".jpg\">");
+           pw.flush();
+       } catch (Exception e) {e.printStackTrace();System.exit(-1);}
+       return null;
+    }
+
+    private String taskstate(ClassDescriptor cd, BufferedWriter out, HTTPResponse resp) {
+       Set objects=taskgraph.getTaskNodes(cd);
+       File file=new File(cd.getSymbol()+"-t.dot");
+       try {
+           //Generate jpg
+           Runtime r=Runtime.getRuntime();
+           FileOutputStream dotstream=new FileOutputStream(file,false);
+           FlagState.DOTVisitor.visit(dotstream, objects);
+           dotstream.close();
+           Process p=r.exec("dot -Tjpg "+cd.getSymbol()+"-t.dot -o"+cd.getSymbol()+"-t.jpg");
+           p.waitFor();
+           p=r.exec("dot -Tps "+cd.getSymbol()+".dot -o"+cd.getSymbol()+"-t.ps");
+           p.waitFor();
+
+           PrintWriter pw=new PrintWriter(out);
+           pw.println("<a href=\"/"+ cd.getSymbol()+"-t.ps\">ps</a><br>");
+           pw.println("<img src=\"/"+ cd.getSymbol()+"-t.jpg\">");
+           pw.flush();
+       } catch (Exception e) {e.printStackTrace();System.exit(-1);}
+       return null;
+    }
+
+
+    private String indexpage(BufferedWriter out, HTTPResponse resp) {
+       PrintWriter pw=new PrintWriter(out);
+       for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator();it_classes.hasNext();) {
+           ClassDescriptor cd=(ClassDescriptor) it_classes.next();
+           if (taskanalysis.getFlagStates(cd)!=null) {
+               pw.println("<a href=\""+cd.getSymbol()+".html\">"+ cd.getSymbol() +"</a>");
+               pw.println("<br>");
+               taskmap.put("/"+cd.getSymbol()+".html", cd);
+           }
+           if (taskgraph.getTaskNodes(cd)!=null) {
+               pw.println("<a href=\""+cd.getSymbol()+"-t.html\">"+ cd.getSymbol() +"</a>");
+               pw.println("<br>");
+               taskgraphmap.put("/"+cd.getSymbol()+"-t.html", cd);
+           }
+
+       }
+       pw.flush();
+       return null;
+    }
+
+}
index ce1a215590b0bced2826f543a777ff36c3fde9f3..62e36426a2d063a0beed26a094e1eccda9fe68b0 100644 (file)
@@ -14,6 +14,7 @@ import Analysis.TaskStateAnalysis.TaskAnalysis;
 import Analysis.TaskStateAnalysis.TaskGraph;
 import Analysis.CallGraph.CallGraph;
 import Analysis.TaskStateAnalysis.TagAnalysis;
+import Interface.*;
 
 public class Main {
 
@@ -43,6 +44,8 @@ public class Main {
              state.TASKSTATE=true;
          else if (option.equals("-thread"))
              state.THREAD=true;
+         else if (option.equals("-webinterface"))
+             state.WEBINTERFACE=true;
          else if (option.equals("-instructionfailures"))
              state.INSTRUCTIONFAILURE=true;
          else if (option.equals("-help")) {
@@ -57,6 +60,7 @@ public class Main {
              System.out.println("-thread -- threads");
              System.out.println("-instructionfailures -- insert code for instruction level failures");
              System.out.println("-taskstate -- do task state analysis");
+             System.out.println("-webinterface -- enable web interface");
              System.out.println("-help -- print out help");
              System.exit(0);
          } else {
@@ -107,15 +111,25 @@ public class Main {
       BuildFlat bf=new BuildFlat(state,tu);
       bf.buildFlat();
 
+      CallGraph callgraph=null;
+      TagAnalysis taganalysis=null;
+      TaskGraph tg=null;
+      TaskAnalysis ta=null;
+
       if (state.TASKSTATE) {
-         CallGraph callgraph=new CallGraph(state);
-         TagAnalysis taganalysis=new TagAnalysis(state, callgraph);
-         TaskAnalysis ta=new TaskAnalysis(state, taganalysis);
+         callgraph=new CallGraph(state);
+         taganalysis=new TagAnalysis(state, callgraph);
+         ta=new TaskAnalysis(state, taganalysis);
          ta.taskAnalysis();
-         TaskGraph tg=new TaskGraph(state, ta);
+         tg=new TaskGraph(state, ta);
          tg.createDOTfiles();
       }
-      
+
+      if (state.WEBINTERFACE) {
+         WebInterface wi=new WebInterface(state, ta, tg);
+         JhttpServer serve=new JhttpServer(8000,wi);
+         serve.run();
+      }
       
       
       BuildCode bc=new BuildCode(state, bf.getMap(), tu);
index bf77e642934f5c62f67ad6cd23dd42c67ffbee27..f353ea7cb653f7c1ca54a68982d9ad6c3a3d227f 100644 (file)
@@ -54,7 +54,13 @@ Analysis/TaskStateAnalysis/TaskAnalysis.class                                \
 Analysis/TaskStateAnalysis/TaskNode.class                              \
 Analysis/TaskStateAnalysis/TaskGraph.class                             \
 Analysis/CallGraph/CallGraph.class Util/Edge.class                     \
-Util/GraphNode.class Util/Relation.class
+Util/GraphNode.class Util/Relation.class Util/Namer.class              \
+Interface/WebInterface.class Interface/HTTPHeader.class                        \
+Interface/JhttpWorker.class Interface/HTTPResponse.class               \
+Interface/LogFile.class Interface/HTTPServices.class                   \
+Interface/Pair.class Interface/HashStrings.class                       \
+Interface/JhttpServer.class
+
 
 
 all: Parse/Sym.class Parse/Parser.class $(CLASSFILES) javadoc
index 3253937f22da7f509241d5ae964d1947d16be453..65f65929312102004b05fd829bbbcd4c1523f7bf 100755 (executable)
@@ -7,6 +7,7 @@ echo -recover compile task code
 echo -specdir directory
 echo -taskstate do task state analysis
 echo -debug generate debug symbols
+echo -webinterface enable web interface
 echo -runtimedebug printout runtime debug messages
 echo "-thread use support for multiple threads"
 echo "-optimize call gcc with -O9 (optimize)"
@@ -61,6 +62,9 @@ elif [[ $1 = '-recover' ]]
 then
 RECOVERFLAG=true
 JAVAOPTS="$JAVAOPTS -task"
+elif [[ $1 = '-webinterface' ]]
+then
+JAVAOPTS="$JAVAOPTS -webinterface"
 elif [[ $1 = '-instructionfailures' ]]
 then
 JAVAOPTS="$JAVAOPTS -instructionfailures"