# HG changeset patch # User xitiomet # Date 1322260386 18000 # Node ID 9e22d72dc6793d145421612b421af8839b633002 # Parent f622dfb6866b81f99b035cb8499105ee455dc534 atom and headers diff -r f622dfb6866b81f99b035cb8499105ee455dc534 -r 9e22d72dc6793d145421612b421af8839b633002 Makefile --- a/Makefile Tue Nov 15 01:41:34 2011 -0500 +++ b/Makefile Fri Nov 25 17:33:06 2011 -0500 @@ -11,6 +11,9 @@ # Where to begin.... all: placebohttp +production: + rsync -avz --exclude '.hg' . xitiomet@nebulous.it:/opt/placebohttp/ + # Mac osx: jvm cp -R res/osx_app/PlaceboHTTP/ ./PlaceboHTTP.app/ @@ -25,7 +28,7 @@ # Alternate build using the java vm jvm: mkdir jvm-build - $(JAVAC) src/*.java src/org/json/*.java src/org/openstatic/http/*.java src/org/openstatic/util/*.java src/org/openstatic/placebo/*.java src/org/openstatic/smtp/*.java src/org/openstatic/placebo/plugins/*.java -d jvm-build + $(JAVAC) src/*.java src/org/json/*.java src/org/openstatic/http/*.java src/org/openstatic/util/*.java src/org/openstatic/placebo/*.java src/org/openstatic/smtp/*.java src/org/openstatic/data/*.java src/org/openstatic/placebo/plugins/*.java -d jvm-build $(JAR) -cvmf res/manifest.mf placebohttp.jar -C jvm-build org -C jvm-build PlaceboBase.class www LICENSE # Executable Rule for GCJ diff -r f622dfb6866b81f99b035cb8499105ee455dc534 -r 9e22d72dc6793d145421612b421af8839b633002 src/org/openstatic/data/AtomEntry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openstatic/data/AtomEntry.java Fri Nov 25 17:33:06 2011 -0500 @@ -0,0 +1,83 @@ +package org.openstatic.data; + +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class AtomEntry +{ + public String title; + public String atom_id; + public String updated; + public Node entry_node; + + public AtomEntry(Node entry_node) + { + this.entry_node = entry_node; + this.title = getTagValue("title"); + } + + public String getTagValue(String name) + { + try + { + Element entryElmnt = (Element) this.entry_node; + NodeList titleNodeList = entryElmnt.getElementsByTagName(name); + Element titleElmnt = (Element) titleNodeList.item(0); + NodeList title = titleElmnt.getChildNodes(); + return ((Node) title.item(0)).getNodeValue(); + } catch (Exception e) { + return null; + } + } + + public String getTagValue(String ns, String name) + { + try + { + Element entryElmnt = (Element) this.entry_node; + NodeList titleNodeList = entryElmnt.getElementsByTagNameNS(ns, name); + Element titleElmnt = (Element) titleNodeList.item(0); + NodeList title = titleElmnt.getChildNodes(); + return ((Node) title.item(0)).getNodeValue(); + } catch (Exception e) { + return null; + } + } + + public String getTagAttribute(String tag, String name) + { + try + { + Element entryElmnt = (Element) this.entry_node; + NodeList titleNodeList = entryElmnt.getElementsByTagName(tag); + Element titleElmnt = (Element) titleNodeList.item(0); + return titleElmnt.getAttribute(name); + } catch (Exception e) { + return null; + } + } + + public String getTagAttribute(String ns, String tag, String name) + { + try + { + Element entryElmnt = (Element) this.entry_node; + NodeList titleNodeList = entryElmnt.getElementsByTagNameNS(ns, tag); + Element titleElmnt = (Element) titleNodeList.item(0); + return titleElmnt.getAttribute(name); + } catch (Exception e) { + return null; + } + } + + public String getTitle() + { + return this.title; + } + + public void setTitle(String title) + { + this.title = title; + } +} diff -r f622dfb6866b81f99b035cb8499105ee455dc534 -r 9e22d72dc6793d145421612b421af8839b633002 src/org/openstatic/data/AtomFeed.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openstatic/data/AtomFeed.java Fri Nov 25 17:33:06 2011 -0500 @@ -0,0 +1,59 @@ +package org.openstatic.data; + +import java.util.Vector; +import java.util.Enumeration; + +import java.io.InputStream; + +import java.net.URL; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class AtomFeed +{ + private Vector entries; + + public AtomFeed(String url) throws Exception + { + this(new URL(url)); + } + + public AtomFeed(URL url) throws Exception + { + this(url.openStream()); + } + + public AtomFeed(InputStream is) + { + this.entries = new Vector(); + try + { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(is); + doc.getDocumentElement().normalize(); + NodeList nodeLst = doc.getElementsByTagName("entry"); + for (int s = 0; s < nodeLst.getLength(); s++) + { + Node entryNode = nodeLst.item(s); + if (entryNode.getNodeType() == Node.ELEMENT_NODE) + { + AtomEntry ae = new AtomEntry(entryNode); + this.entries.add(ae); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public Enumeration getFeed() + { + return this.entries.elements(); + } +} diff -r f622dfb6866b81f99b035cb8499105ee455dc534 -r 9e22d72dc6793d145421612b421af8839b633002 src/org/openstatic/http/HttpRequest.java --- a/src/org/openstatic/http/HttpRequest.java Tue Nov 15 01:41:34 2011 -0500 +++ b/src/org/openstatic/http/HttpRequest.java Fri Nov 25 17:33:06 2011 -0500 @@ -23,6 +23,7 @@ import java.io.InputStream; import java.util.Date; import java.util.Enumeration; +import java.util.Hashtable; import org.json.*; @@ -201,7 +202,7 @@ { return this.post_data.keys(); } - + public void sendResponse(HttpResponse response) { InputStream data = response.getData(); @@ -216,6 +217,14 @@ { socketWrite("Set-Cookie: " + this.set_cookie + "\r\n"); } + Hashtable prop = response.getHeaders(); + for(Enumeration names = prop.keys(); names.hasMoreElements(); ) + { + String c_name = names.nextElement(); + String c_value = prop.get(c_name); + socketWrite(c_name + ": " + c_value + "\r\n"); + } + socketWrite("\r\n"); if (data != null) { diff -r f622dfb6866b81f99b035cb8499105ee455dc534 -r 9e22d72dc6793d145421612b421af8839b633002 src/org/openstatic/http/HttpResponse.java --- a/src/org/openstatic/http/HttpResponse.java Tue Nov 15 01:41:34 2011 -0500 +++ b/src/org/openstatic/http/HttpResponse.java Fri Nov 25 17:33:06 2011 -0500 @@ -25,6 +25,7 @@ import java.net.URL; import java.net.URLConnection; import java.net.FileNameMap; +import java.util.Hashtable; import org.json.*; @@ -34,6 +35,7 @@ private String contentType; private String responseCode; private long dataLength; + private Hashtable headers; public HttpResponse() { @@ -41,6 +43,7 @@ this.contentType = "text/html"; this.responseCode = "200 OK"; this.dataLength = 0; + this.headers = new Hashtable(); } /** Determine the content type of a local file */ @@ -71,6 +74,12 @@ { this.contentType = type; } + + /** Set a header for the response */ + public void setHeader(String key, String value) + { + this.headers.put(key, value); + } /** Set the entire response body to a single string */ public void setData(String data) @@ -178,6 +187,12 @@ { return this.data; } + + /** Retrieve all headers as a Hashtable */ + public Hashtable getHeaders() + { + return this.headers; + } /** return the length of this response */ public long getDataLength() diff -r f622dfb6866b81f99b035cb8499105ee455dc534 -r 9e22d72dc6793d145421612b421af8839b633002 src/org/openstatic/smtp/SmtpMessage.java --- a/src/org/openstatic/smtp/SmtpMessage.java Tue Nov 15 01:41:34 2011 -0500 +++ b/src/org/openstatic/smtp/SmtpMessage.java Fri Nov 25 17:33:06 2011 -0500 @@ -50,21 +50,55 @@ this.from_domain = ad.nextToken(); } + public String getToUser() + { + return this.to; + } + + public String getToDomain() + { + return this.to_domain; + } + + public String getFromUser() + { + return this.from; + } + + public String getFromDomain() + { + return this.from_domain; + } + public void setBody(String body) { this.body = body; } + public String getBody() + { + return this.body; + } + public void setHeader(String key, String value) { this.headers.put(key, value); } + public Hashtable getHeaders() + { + return this.headers; + } + public JSONObject toJSONObject() throws JSONException { JSONObject jmsg = new JSONObject(); jmsg.put("to", this.to + "@" + this.to_domain); + jmsg.put("to_user", this.to); + jmsg.put("to_domain", this.to_domain); jmsg.put("from", this.from + "@" + this.from_domain); + jmsg.put("from_user", this.from); + jmsg.put("from_domain", this.from_domain); jmsg.put("body", this.body); JSONObject jheaders = new JSONObject(); for(Enumeration keys = this.headers.keys(); keys.hasMoreElements();) diff -r f622dfb6866b81f99b035cb8499105ee455dc534 -r 9e22d72dc6793d145421612b421af8839b633002 src/org/openstatic/smtp/SmtpRequestThread.java --- a/src/org/openstatic/smtp/SmtpRequestThread.java Tue Nov 15 01:41:34 2011 -0500 +++ b/src/org/openstatic/smtp/SmtpRequestThread.java Fri Nov 25 17:33:06 2011 -0500 @@ -90,12 +90,12 @@ this.myServer.logln(this.clientHostname, "-> " + cmd_line); if (cmd_line.contains(":") && !cmd_line.startsWith(" ")) { - StringTokenizer cs = new StringTokenizer(cmd_line, ": "); + StringTokenizer cs = new StringTokenizer(cmd_line, ":"); String key = cs.nextToken(); if (!key.equals("Received")) { String value = cs.nextToken(); - nm.setHeader(key,value); + nm.setHeader(key,value.trim()); } } }