codethief / virtualme (http://codeartists.org/)
No description has been added.
$ hg clone http://bitbucket.org/codethief/virtualme/
| commit 4: | 12a7abe003c1 |
| parent 3: | 07f04e45067a |
| branch: | default |
Changed (Δ7.0 KB):
.project (17 lines added, 0 lines removed)
docs/intents.txt (14 lines added, 0 lines removed)
docs/protocol.xml
docs/protocol/scenarios/client-server.xml (14 lines added, 14 lines removed)
protocol/client-server.xsd (116 lines added, 0 lines removed)
src/core/ConnectionReader.java (11 lines added, 0 lines removed)
src/core/RequestDispatcher.java (13 lines added, 0 lines removed)
src/core/client/ClientReader.java (81 lines added, 0 lines removed)
src/core/helpers/VersionCompare.java (44 lines added, 0 lines removed)
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>virtual.me</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
</buildSpec> |
|
14 |
<natures> |
|
15 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
16 |
</natures> |
|
17 |
</projectDescription> |
Up to file-list docs/intents.txt:
1 |
========Intents======== |
|
2 |
||
3 |
Zwei (drei) Möglichkeiten Intents zu implementieren: |
|
4 |
||
5 |
1. |
|
6 |
- <intent>-Tag mit Name und ID |
|
7 |
- beliebiger Namespace, von Name (d.h. Intent) abhängig |
|
8 |
- Standard-Intents in |
|
9 |
http://codeartists.org/virtualme/protocol/1.0/intents/xxx definiert |
|
10 |
- Kindelemente im Intent-Namespace definiert |
|
11 |
||
12 |
2. |
|
13 |
- <stream> enthält beliebige Elemente des Namespaces |
|
14 |
http://codeartists.org/virtualme/protocol/1.0/intents |
Up to file-list docs/protocol/scenarios/client-server.xml:
2 |
2 |
|
3 |
3 |
<!-- Client -> Server: --> |
4 |
4 |
|
5 |
<stream protocol-version="1.0" xmlns="http://codeartists.org/virtual |
|
5 |
<stream protocol-version="1.0" xmlns="http://codeartists.org/virtualme/protocol/client-server"> |
|
6 |
6 |
<hello> |
7 |
7 |
<software name="virtualWebInterface" version="0.1" release="alpha" /> |
8 |
8 |
|
18 |
18 |
</disallowed-notifications> |
19 |
19 |
</hello> |
20 |
20 |
|
21 |
<intent id="3f4xy7g" name="register" xmlns:register="http://codeartists.org/virtual.me/protocol/intents/register"> |
|
22 |
<register:user name="codethief" host="codeartists.org" /> |
|
23 |
<register:pass type="password"> |
|
24 |
<register:password1>test</register:password1> |
|
25 |
<register:password2>test</register:password2> |
|
26 |
</register:pass> |
|
27 |
<!-- <register:pass type="public-key"> ... </register:pass> --> |
|
28 |
</intent> |
|
21 |
<register> |
|
22 |
<user name="codethief" host="codeartists.org" /> |
|
23 |
<pass type="password"> |
|
24 |
<password1>test</password1> |
|
25 |
<password2>test</password2> |
|
26 |
</pass> |
|
27 |
<!-- <pass type="public-key"> ... </pass> --> |
|
28 |
</register> |
|
29 |
29 |
|
30 |
<intent id="65xb4gh" name="authenticate" xmlns:authenticate="http://codeartists.org/virtual.me/protocol/intents/authenticate"> |
|
31 |
<authenticate:user name="codethief" host="codeartists.org" /> |
|
32 |
<authenticate:pass>test</authenticate:pass> |
|
33 |
<authenticate:resource>home</authenticate:resource> |
|
34 |
< |
|
30 |
<authenticate> |
|
31 |
<user name="codethief" host="codeartists.org" /> |
|
32 |
<pass>test</pass> |
|
33 |
<resource>home</resource> |
|
34 |
</authenticate> |
|
35 |
35 |
|
36 |
36 |
|
37 |
37 |
<intent id="25a4zfj" name="upload" xmlns:upload="http://codeartists.org/virtual.me/protocol/intents/upload"> |
Up to file-list protocol/client-server.xsd:
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
||
3 |
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" |
|
4 |
xmlns="http://codeartists.org/virtualme/protocol/1.0" |
|
5 |
targetNamespace="http://codeartists.org/virtualme/protocol/1.0" |
|
6 |
elementFormDefault="qualified"> |
|
7 |
||
8 |
||
9 |
<!-- Elements --> |
|
10 |
<xs:element name="stream"> |
|
11 |
<xs:complexType> |
|
12 |
<xs:sequence> |
|
13 |
<xs:element ref="hello" minOccurs="1" maxOccurs="1"/> |
|
14 |
||
15 |
<xs:choice> |
|
16 |
<xs:sequence> |
|
17 |
<xs:element ref="register"/> |
|
18 |
<xs:element ref="authenticate" minOccurs="0" maxOccurs="unbounded"/> |
|
19 |
</xs:sequence> |
|
20 |
<xs:element ref="authenticate" minOccurs="1" maxOccurs="unbounded"/> |
|
21 |
</xs:choice> |
|
22 |
||
23 |
<xs:element ref="intent" minOccurs="0" maxOccurs="unbounded"/> |
|
24 |
</xs:sequence> |
|
25 |
||
26 |
<xs:attribute name="protocol-version" type="version-number" use="required"/> |
|
27 |
</xs:complexType> |
|
28 |
</xs:element> |
|
29 |
||
30 |
||
31 |
<xs:element name="hello"> |
|
32 |
<xs:complexType> |
|
33 |
<xs:sequence> |
|
34 |
<xs:element name="software"> |
|
35 |
<xs:complexType> |
|
36 |
<xs:attribute name="name" type="xs:string" use="required"/> |
|
37 |
<xs:attribute name="version" type="version-number"/> |
|
38 |
<xs:attribute name="release" type="xs:string"/> |
|
39 |
</xs:complexType> |
|
40 |
</xs:element> |
|
41 |
</xs:sequence> |
|
42 |
</xs:complexType> |
|
43 |
</xs:element> |
|
44 |
||
45 |
||
46 |
<xs:element name="user"> |
|
47 |
<xs:complexType> |
|
48 |
<xs:attribute name="name" type="xs:string"/> |
|
49 |
<xs:attribute name="host" type="xs:string"/> |
|
50 |
</xs:complexType> |
|
51 |
</xs:element> |
|
52 |
||
53 |
||
54 |
<xs:element name="register"> |
|
55 |
<xs:complexType> |
|
56 |
<xs:sequence> |
|
57 |
<xs:element ref="user"/> |
|
58 |
<xs:element name="password" type="xs:string" minOccurs="1" maxOccurs="1"/> |
|
59 |
<xs:element name="public-key" type="xs:string" minOccurs="0" maxOccurs="1"/> |
|
60 |
</xs:sequence> |
|
61 |
</xs:complexType> |
|
62 |
</xs:element> |
|
63 |
||
64 |
<xs:element name="authenticate"> |
|
65 |
<xs:complexType> |
|
66 |
<xs:sequence> |
|
67 |
||
68 |
<xs:element ref="user"/> |
|
69 |
||
70 |
<xs:choice> |
|
71 |
<xs:element name="password" type="xs:string"/> |
|
72 |
<xs:element name="key-encrypted"> |
|
73 |
<xs:complexType> |
|
74 |
<xs:simpleContent> |
|
75 |
<xs:extension base="xs:string"> |
|
76 |
<xs:attribute name="plain-value" type="xs:string" use="optional" |
|
77 |
/> |
|
78 |
</xs:extension> |
|
79 |
</xs:simpleContent> |
|
80 |
</xs:complexType> |
|
81 |
</xs:element> |
|
82 |
</xs:choice> |
|
83 |
||
84 |
</xs:sequence> |
|
85 |
</xs:complexType> |
|
86 |
</xs:element> |
|
87 |
||
88 |
||
89 |
<xs:element name="intent"> |
|
90 |
<xs:complexType> |
|
91 |
<xs:sequence> |
|
92 |
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="http://codeartists.org/virtualme/protocol/1.0/intents"/> |
|
93 |
</xs:sequence> |
|
94 |
||
95 |
<xs:attribute name="id" type="xs:string" use="required"/> |
|
96 |
<xs:attribute name="name" type="xs:string" use="required"/> |
|
97 |
</xs:complexType> |
|
98 |
</xs:element> |
|
99 |
||
100 |
||
101 |
||
102 |
||
103 |
||
104 |
||
105 |
||
106 |
||
107 |
||
108 |
||
109 |
<!-- Types --> |
|
110 |
<xs:simpleType name="version-number"> |
|
111 |
<xs:restriction base="xs:string"> |
|
112 |
<xs:pattern value="([0-9]+)(\.([0-9]+))+"/> |
|
113 |
</xs:restriction> |
|
114 |
</xs:simpleType> |
|
115 |
||
116 |
</xs:schema> |
Up to file-list src/core/ConnectionReader.java:
1 |
package core; |
|
2 |
||
3 |
import org.xml.sax.helpers.DefaultHandler; |
|
4 |
||
5 |
public abstract class ConnectionReader<T extends Connection> extends DefaultHandler { |
|
6 |
protected T conn; |
|
7 |
||
8 |
public ConnectionReader(T conn) { |
|
9 |
this.conn = conn; |
|
10 |
} |
|
11 |
} |
Up to file-list src/core/RequestDispatcher.java:
1 |
package core; |
|
2 |
||
3 |
import java.net.ServerSocket; |
|
4 |
||
5 |
public abstract class RequestDispatcher extends Thread { |
|
6 |
protected ServerProcess serv; |
|
7 |
protected ServerSocket ssock; |
|
8 |
||
9 |
public RequestDispatcher(ServerProcess serv, ServerSocket ssock) { |
|
10 |
this.serv = serv; |
|
11 |
this.ssock = ssock; |
|
12 |
} |
|
13 |
} |
Up to file-list src/core/client/ClientReader.java:
1 |
package core.client; |
|
2 |
||
3 |
import org.xml.sax.*; |
|
4 |
||
5 |
import core.ConnectionReader; |
|
6 |
import core.helpers.VersionCompare; |
|
7 |
||
8 |
public class ClientReader extends ConnectionReader<ClientConnection> { |
|
9 |
public static final String PROTOCOL_VERSION = "1.0"; |
|
10 |
||
11 |
public ClientReader(ClientConnection conn) { |
|
12 |
super(conn); |
|
13 |
} |
|
14 |
||
15 |
@Override |
|
16 |
public void startDocument() throws SAXException { |
|
17 |
conn.send("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); |
|
18 |
||
19 |
conn.send("<stream protocol-version=\"" + PROTOCOL_VERSION + "\">"); |
|
20 |
conn.send("\t<hello>"); |
|
21 |
conn.send("\t\t<software name=\"kakou server\" version=\"0.1\" release=\"Alpha\" />"); |
|
22 |
conn.send("\t</hello>"); |
|
23 |
} |
|
24 |
||
25 |
@Override |
|
26 |
public void endDocument() throws SAXException { |
|
27 |
||
28 |
} |
|
29 |
||
30 |
||
31 |
@Override |
|
32 |
public void startElement(String URI, String localName, String qName, |
|
33 |
Attributes attributes) throws SAXException { |
|
34 |
||
35 |
String name = (!localName.equals("")) ? localName : qName; |
|
36 |
||
37 |
if(name.equals("stream")) { |
|
38 |
if(!VersionCompare.meetsRequirement(attributes.getValue("protocol-version"), PROTOCOL_VERSION)) { |
|
39 |
conn.send("<protocol-mismatch />"); |
|
40 |
endDocument(); |
|
41 |
} |
|
42 |
} |
|
43 |
else if(name.equals("hello")) { |
|
44 |
||
45 |
} |
|
46 |
else if(name.equals("intent")) { |
|
47 |
||
48 |
} |
|
49 |
} |
|
50 |
||
51 |
@Override |
|
52 |
public void endElement(String URI, String localName, String qName) |
|
53 |
throws SAXException { |
|
54 |
||
55 |
String name = (!localName.equals("")) ? localName : qName; |
|
56 |
||
57 |
if(name.equals("stream")) { |
|
58 |
conn.send("</stream>"); |
|
59 |
conn.close(); |
|
60 |
} |
|
61 |
else if(name.equals("hello")) { |
|
62 |
||
63 |
} |
|
64 |
else if(name.equals("intent")) { |
|
65 |
||
66 |
} |
|
67 |
} |
|
68 |
||
69 |
||
70 |
@Override |
|
71 |
public void error(SAXParseException e) throws SAXException { |
|
72 |
conn.send("<xml-error>" + e.getMessage() + "</xml-error>"); |
|
73 |
} |
|
74 |
||
75 |
@Override |
|
76 |
public void fatalError(SAXParseException e) throws SAXException { |
|
77 |
error(e); |
|
78 |
endDocument(); |
|
79 |
} |
|
80 |
||
81 |
} |
Up to file-list src/core/helpers/VersionCompare.java:
1 |
package core.helpers; |
|
2 |
||
3 |
public class VersionCompare { |
|
4 |
public enum Result { |
|
5 |
EQUAL, |
|
6 |
GREATER, |
|
7 |
LOWER |
|
8 |
} |
|
9 |
||
10 |
// Compares the first version string v1 to the second one (v2). |
|
11 |
public static Result cmp(String v1, String v2) { |
|
12 |
int value1 = computeIntValue(v1.split("\\.")); |
|
13 |
int value2 = computeIntValue(v2.split("\\.")); |
|
14 |
||
15 |
if(value1 == value2) { |
|
16 |
return Result.EQUAL; |
|
17 |
} |
|
18 |
else if(value1 > value2) { |
|
19 |
return Result.GREATER; |
|
20 |
} |
|
21 |
else { |
|
22 |
return Result.LOWER; |
|
23 |
} |
|
24 |
} |
|
25 |
||
26 |
||
27 |
public static int computeIntValue(String[] arr) { |
|
28 |
int value = 0; |
|
29 |
||
30 |
for(int i = 0; i < arr.length; i++) { |
|
31 |
value += Integer.parseInt(arr[i]) * Math.pow(10, -i); |
|
32 |
} |
|
33 |
||
34 |
return value; |
|
35 |
} |
|
36 |
||
37 |
||
38 |
public static boolean meetsRequirement(String version, String requirement) { |
|
39 |
Result res = cmp(version, requirement); |
|
40 |
||
41 |
return (res == Result.EQUAL || res == Result.GREATER); |
|
42 |
} |
|
43 |
||
44 |
} |
