siffer 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +65 -0
- data/Rakefile +64 -0
- data/bin/siffer +71 -0
- data/doc/SIF ImplementationSpecification.pdf +0 -0
- data/doc/rdoc/classes/Siffer.html +374 -0
- data/doc/rdoc/classes/Siffer/Agent.html +296 -0
- data/doc/rdoc/classes/Siffer/Container.html +286 -0
- data/doc/rdoc/classes/Siffer/Messages.html +141 -0
- data/doc/rdoc/classes/Siffer/Messages/Ack.html +216 -0
- data/doc/rdoc/classes/Siffer/Messages/Acl.html +160 -0
- data/doc/rdoc/classes/Siffer/Messages/Error.html +248 -0
- data/doc/rdoc/classes/Siffer/Messages/Message.html +359 -0
- data/doc/rdoc/classes/Siffer/Messages/Message/Header.html +181 -0
- data/doc/rdoc/classes/Siffer/Messages/Register.html +257 -0
- data/doc/rdoc/classes/Siffer/Messages/RequestBody.html +300 -0
- data/doc/rdoc/classes/Siffer/Messages/Status.html +269 -0
- data/doc/rdoc/classes/Siffer/Messaging.html +331 -0
- data/doc/rdoc/classes/Siffer/Protocol.html +388 -0
- data/doc/rdoc/classes/Siffer/Protocol/NonPostRequest.html +111 -0
- data/doc/rdoc/classes/Siffer/Protocol/UnknownPath.html +111 -0
- data/doc/rdoc/classes/Siffer/Registration.html +391 -0
- data/doc/rdoc/classes/Siffer/Request.html +209 -0
- data/doc/rdoc/classes/Siffer/RequestLogger.html +211 -0
- data/doc/rdoc/classes/Siffer/Response.html +182 -0
- data/doc/rdoc/classes/Siffer/Server.html +242 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/LICENSE.html +129 -0
- data/doc/rdoc/files/README_rdoc.html +184 -0
- data/doc/rdoc/files/lib/agent_rb.html +101 -0
- data/doc/rdoc/files/lib/container_rb.html +108 -0
- data/doc/rdoc/files/lib/messages/ack_rb.html +101 -0
- data/doc/rdoc/files/lib/messages/acl_rb.html +101 -0
- data/doc/rdoc/files/lib/messages/error_rb.html +101 -0
- data/doc/rdoc/files/lib/messages/message_rb.html +101 -0
- data/doc/rdoc/files/lib/messages/register_rb.html +101 -0
- data/doc/rdoc/files/lib/messages/request_body_rb.html +101 -0
- data/doc/rdoc/files/lib/messages/status_rb.html +101 -0
- data/doc/rdoc/files/lib/messages_rb.html +114 -0
- data/doc/rdoc/files/lib/messaging_rb.html +101 -0
- data/doc/rdoc/files/lib/protocol_rb.html +101 -0
- data/doc/rdoc/files/lib/registration_rb.html +101 -0
- data/doc/rdoc/files/lib/request_logger_rb.html +101 -0
- data/doc/rdoc/files/lib/request_rb.html +101 -0
- data/doc/rdoc/files/lib/response_rb.html +101 -0
- data/doc/rdoc/files/lib/server_rb.html +101 -0
- data/doc/rdoc/files/lib/siffer_rb.html +115 -0
- data/doc/rdoc/fr_class_index.html +47 -0
- data/doc/rdoc/fr_file_index.html +46 -0
- data/doc/rdoc/fr_method_index.html +96 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/lib/agent.rb +43 -0
- data/lib/container.rb +96 -0
- data/lib/messages.rb +7 -0
- data/lib/messages/ack.rb +43 -0
- data/lib/messages/acl.rb +25 -0
- data/lib/messages/error.rb +174 -0
- data/lib/messages/message.rb +71 -0
- data/lib/messages/register.rb +60 -0
- data/lib/messages/request_body.rb +66 -0
- data/lib/messages/status.rb +55 -0
- data/lib/messaging.rb +96 -0
- data/lib/protocol.rb +159 -0
- data/lib/registration.rb +87 -0
- data/lib/request.rb +25 -0
- data/lib/request_logger.rb +31 -0
- data/lib/response.rb +26 -0
- data/lib/server.rb +40 -0
- data/lib/siffer.rb +44 -0
- data/spec/agent_spec.rb +53 -0
- data/spec/cli_spec.rb +40 -0
- data/spec/container_spec.rb +103 -0
- data/spec/default_agent +6 -0
- data/spec/default_server +5 -0
- data/spec/message_specs/ack_spec.rb +28 -0
- data/spec/message_specs/error_spec.rb +24 -0
- data/spec/message_specs/header_spec.rb +25 -0
- data/spec/message_specs/message_spec.rb +57 -0
- data/spec/message_specs/register_spec.rb +86 -0
- data/spec/message_specs/request_body_spec.rb +58 -0
- data/spec/message_specs/status_spec.rb +25 -0
- data/spec/messaging_spec.rb +88 -0
- data/spec/protocol_spec.rb +49 -0
- data/spec/registration_spec.rb +33 -0
- data/spec/request_logger_spec.rb +15 -0
- data/spec/request_spec.rb +10 -0
- data/spec/response_spec.rb +24 -0
- data/spec/server_spec.rb +35 -0
- data/spec/spec_helper.rb +26 -0
- metadata +191 -0
data/doc/rdoc/index.html
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
|
5
|
+
|
6
|
+
<!--
|
7
|
+
|
8
|
+
Siffer == h3o(software) SIF
|
9
|
+
|
10
|
+
-->
|
11
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
12
|
+
<head>
|
13
|
+
<title>Siffer == h3o(software) SIF</title>
|
14
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
15
|
+
</head>
|
16
|
+
<frameset rows="20%, 80%">
|
17
|
+
<frameset cols="25%,35%,45%">
|
18
|
+
<frame src="fr_file_index.html" title="Files" name="Files" />
|
19
|
+
<frame src="fr_class_index.html" name="Classes" />
|
20
|
+
<frame src="fr_method_index.html" name="Methods" />
|
21
|
+
</frameset>
|
22
|
+
<frame src="files/README_rdoc.html" name="docwin" />
|
23
|
+
</frameset>
|
24
|
+
</html>
|
@@ -0,0 +1,208 @@
|
|
1
|
+
|
2
|
+
body {
|
3
|
+
font-family: Verdana,Arial,Helvetica,sans-serif;
|
4
|
+
font-size: 90%;
|
5
|
+
margin: 0;
|
6
|
+
margin-left: 40px;
|
7
|
+
padding: 0;
|
8
|
+
background: white;
|
9
|
+
}
|
10
|
+
|
11
|
+
h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
|
12
|
+
h1 { font-size: 150%; }
|
13
|
+
h2,h3,h4 { margin-top: 1em; }
|
14
|
+
|
15
|
+
a { background: #eef; color: #039; text-decoration: none; }
|
16
|
+
a:hover { background: #039; color: #eef; }
|
17
|
+
|
18
|
+
/* Override the base stylesheet's Anchor inside a table cell */
|
19
|
+
td > a {
|
20
|
+
background: transparent;
|
21
|
+
color: #039;
|
22
|
+
text-decoration: none;
|
23
|
+
}
|
24
|
+
|
25
|
+
/* and inside a section title */
|
26
|
+
.section-title > a {
|
27
|
+
background: transparent;
|
28
|
+
color: #eee;
|
29
|
+
text-decoration: none;
|
30
|
+
}
|
31
|
+
|
32
|
+
/* === Structural elements =================================== */
|
33
|
+
|
34
|
+
div#index {
|
35
|
+
margin: 0;
|
36
|
+
margin-left: -40px;
|
37
|
+
padding: 0;
|
38
|
+
font-size: 90%;
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
div#index a {
|
43
|
+
margin-left: 0.7em;
|
44
|
+
}
|
45
|
+
|
46
|
+
div#index .section-bar {
|
47
|
+
margin-left: 0px;
|
48
|
+
padding-left: 0.7em;
|
49
|
+
background: #ccc;
|
50
|
+
font-size: small;
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
div#classHeader, div#fileHeader {
|
55
|
+
width: auto;
|
56
|
+
color: white;
|
57
|
+
padding: 0.5em 1.5em 0.5em 1.5em;
|
58
|
+
margin: 0;
|
59
|
+
margin-left: -40px;
|
60
|
+
border-bottom: 3px solid #006;
|
61
|
+
}
|
62
|
+
|
63
|
+
div#classHeader a, div#fileHeader a {
|
64
|
+
background: inherit;
|
65
|
+
color: white;
|
66
|
+
}
|
67
|
+
|
68
|
+
div#classHeader td, div#fileHeader td {
|
69
|
+
background: inherit;
|
70
|
+
color: white;
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
div#fileHeader {
|
75
|
+
background: #057;
|
76
|
+
}
|
77
|
+
|
78
|
+
div#classHeader {
|
79
|
+
background: #048;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
.class-name-in-header {
|
84
|
+
font-size: 180%;
|
85
|
+
font-weight: bold;
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
div#bodyContent {
|
90
|
+
padding: 0 1.5em 0 1.5em;
|
91
|
+
}
|
92
|
+
|
93
|
+
div#description {
|
94
|
+
padding: 0.5em 1.5em;
|
95
|
+
background: #efefef;
|
96
|
+
border: 1px dotted #999;
|
97
|
+
}
|
98
|
+
|
99
|
+
div#description h1,h2,h3,h4,h5,h6 {
|
100
|
+
color: #125;;
|
101
|
+
background: transparent;
|
102
|
+
}
|
103
|
+
|
104
|
+
div#validator-badges {
|
105
|
+
text-align: center;
|
106
|
+
}
|
107
|
+
div#validator-badges img { border: 0; }
|
108
|
+
|
109
|
+
div#copyright {
|
110
|
+
color: #333;
|
111
|
+
background: #efefef;
|
112
|
+
font: 0.75em sans-serif;
|
113
|
+
margin-top: 5em;
|
114
|
+
margin-bottom: 0;
|
115
|
+
padding: 0.5em 2em;
|
116
|
+
}
|
117
|
+
|
118
|
+
|
119
|
+
/* === Classes =================================== */
|
120
|
+
|
121
|
+
table.header-table {
|
122
|
+
color: white;
|
123
|
+
font-size: small;
|
124
|
+
}
|
125
|
+
|
126
|
+
.type-note {
|
127
|
+
font-size: small;
|
128
|
+
color: #DEDEDE;
|
129
|
+
}
|
130
|
+
|
131
|
+
.xxsection-bar {
|
132
|
+
background: #eee;
|
133
|
+
color: #333;
|
134
|
+
padding: 3px;
|
135
|
+
}
|
136
|
+
|
137
|
+
.section-bar {
|
138
|
+
color: #333;
|
139
|
+
border-bottom: 1px solid #999;
|
140
|
+
margin-left: -20px;
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
.section-title {
|
145
|
+
background: #79a;
|
146
|
+
color: #eee;
|
147
|
+
padding: 3px;
|
148
|
+
margin-top: 2em;
|
149
|
+
margin-left: -30px;
|
150
|
+
border: 1px solid #999;
|
151
|
+
}
|
152
|
+
|
153
|
+
.top-aligned-row { vertical-align: top }
|
154
|
+
.bottom-aligned-row { vertical-align: bottom }
|
155
|
+
|
156
|
+
/* --- Context section classes ----------------------- */
|
157
|
+
|
158
|
+
.context-row { }
|
159
|
+
.context-item-name { font-family: monospace; font-weight: bold; color: black; }
|
160
|
+
.context-item-value { font-size: small; color: #448; }
|
161
|
+
.context-item-desc { color: #333; padding-left: 2em; }
|
162
|
+
|
163
|
+
/* --- Method classes -------------------------- */
|
164
|
+
.method-detail {
|
165
|
+
background: #efefef;
|
166
|
+
padding: 0;
|
167
|
+
margin-top: 0.5em;
|
168
|
+
margin-bottom: 1em;
|
169
|
+
border: 1px dotted #ccc;
|
170
|
+
}
|
171
|
+
.method-heading {
|
172
|
+
color: black;
|
173
|
+
background: #ccc;
|
174
|
+
border-bottom: 1px solid #666;
|
175
|
+
padding: 0.2em 0.5em 0 0.5em;
|
176
|
+
}
|
177
|
+
.method-signature { color: black; background: inherit; }
|
178
|
+
.method-name { font-weight: bold; }
|
179
|
+
.method-args { font-style: italic; }
|
180
|
+
.method-description { padding: 0 0.5em 0 0.5em; }
|
181
|
+
|
182
|
+
/* --- Source code sections -------------------- */
|
183
|
+
|
184
|
+
a.source-toggle { font-size: 90%; }
|
185
|
+
div.method-source-code {
|
186
|
+
background: #262626;
|
187
|
+
color: #ffdead;
|
188
|
+
margin: 1em;
|
189
|
+
padding: 0.5em;
|
190
|
+
border: 1px dashed #999;
|
191
|
+
overflow: hidden;
|
192
|
+
}
|
193
|
+
|
194
|
+
div.method-source-code pre { color: #ffdead; overflow: hidden; }
|
195
|
+
|
196
|
+
/* --- Ruby keyword styles --------------------- */
|
197
|
+
|
198
|
+
.standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
|
199
|
+
|
200
|
+
.ruby-constant { color: #7fffd4; background: transparent; }
|
201
|
+
.ruby-keyword { color: #00ffff; background: transparent; }
|
202
|
+
.ruby-ivar { color: #eedd82; background: transparent; }
|
203
|
+
.ruby-operator { color: #00ffee; background: transparent; }
|
204
|
+
.ruby-identifier { color: #ffdead; background: transparent; }
|
205
|
+
.ruby-node { color: #ffa07a; background: transparent; }
|
206
|
+
.ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
|
207
|
+
.ruby-regexp { color: #ffa07a; background: transparent; }
|
208
|
+
.ruby-value { color: #7fffd4; background: transparent; }
|
data/lib/agent.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Siffer
|
2
|
+
|
3
|
+
class Agent
|
4
|
+
|
5
|
+
include Siffer::Protocol
|
6
|
+
|
7
|
+
attr_reader :name, :host, :port, :admin, :server
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
raise "Server URL(s) required" unless options.include? "servers"
|
11
|
+
@server = options["servers"]
|
12
|
+
raise "Administration URL required" unless options.include? "admin"
|
13
|
+
@admin = options["admin"]
|
14
|
+
@name = options["name"] || "Default Agent"
|
15
|
+
@host = options["host"] || "localhost"
|
16
|
+
@port = options["port"] || 8300
|
17
|
+
@registered = false
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(env)
|
21
|
+
with_each_request(env) do
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def wake_up
|
27
|
+
self_register unless registered?
|
28
|
+
end
|
29
|
+
|
30
|
+
def self_register
|
31
|
+
registration = Siffer::Messages::Register.new(name, name)
|
32
|
+
response = Response.from(server,registration)
|
33
|
+
# OOOOH BAAAAD ====> Check the ACL please ! Make a parser !
|
34
|
+
@registered = response.ok?
|
35
|
+
end
|
36
|
+
|
37
|
+
def registered?
|
38
|
+
@registered
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/lib/container.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
module Siffer
|
2
|
+
|
3
|
+
class Container
|
4
|
+
|
5
|
+
attr_reader :environment, :component, :name, :host, :port, :log, :pid
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
raise "Component Configuration missing" if options[:config].nil?
|
9
|
+
raise "Environment missing" if options[:environment].nil?
|
10
|
+
@environment = options[:environment]
|
11
|
+
config = options[:config]
|
12
|
+
type = config.include?("agent") ? "agent" : "server"
|
13
|
+
@component = (type == "agent") ?
|
14
|
+
Siffer::Agent.new(config["agent"]) :
|
15
|
+
Siffer::Server.new(config["server"])
|
16
|
+
@name = config[type]["name"]
|
17
|
+
@host = config[type]["host"]
|
18
|
+
@port = config[type]["port"]
|
19
|
+
@daemonize = options[:daemonize]
|
20
|
+
@pid = options[:pid]
|
21
|
+
@log = options[:log]
|
22
|
+
end
|
23
|
+
|
24
|
+
def daemonized?
|
25
|
+
@daemonize
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
daemonize
|
30
|
+
server = best_available_server
|
31
|
+
options = {
|
32
|
+
:Host => host,
|
33
|
+
:Port => port
|
34
|
+
}
|
35
|
+
component.wake_up if component.respond_to?("wake_up")
|
36
|
+
app = component_wrapped_in_environment
|
37
|
+
server.run app, options
|
38
|
+
end
|
39
|
+
|
40
|
+
def stop
|
41
|
+
pid_id = open("#{@pid}").read.to_i
|
42
|
+
Process.kill(15,pid_id)
|
43
|
+
File.delete(@pid) if File.exist?(@pid)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def best_available_server
|
48
|
+
begin
|
49
|
+
server = Rack::Handler::Mongrel
|
50
|
+
rescue
|
51
|
+
server = Rack::Handler::WEBrick
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def component_wrapped_in_environment
|
56
|
+
case environment
|
57
|
+
when "development"
|
58
|
+
builder = Rack::Builder.new
|
59
|
+
builder.use(Siffer::RequestLogger)
|
60
|
+
builder.use(Rack::CommonLogger)
|
61
|
+
builder.run(@component)
|
62
|
+
builder
|
63
|
+
when "deployment"
|
64
|
+
builder = Rack::Builder.new
|
65
|
+
builder.use(Rack::CommonLogger)
|
66
|
+
builder.run(@component)
|
67
|
+
builder
|
68
|
+
when "test": component
|
69
|
+
when "none": component
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def daemonize
|
74
|
+
if daemonized?
|
75
|
+
if RUBY_PLATFORM !~ /mswin/
|
76
|
+
require 'daemons/daemonize'
|
77
|
+
Daemonize.daemonize(@log)
|
78
|
+
else
|
79
|
+
# How to tell about the problem of no Daemon on WINDOWS
|
80
|
+
end
|
81
|
+
write_pid_file
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def write_pid_file
|
86
|
+
if RUBY_PLATFORM !~ /mswin/
|
87
|
+
open(@pid,"w") do |f|
|
88
|
+
f.write(Process.pid)
|
89
|
+
File.chmod(0644, @pid)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
data/lib/messages.rb
ADDED
data/lib/messages/ack.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Siffer
|
2
|
+
module Messages
|
3
|
+
|
4
|
+
# Acknowledge Message
|
5
|
+
# Used by Server and Agent to "acknowledge" receipt of a message. Allows
|
6
|
+
# Erorr and Status messages to be injected into the body.
|
7
|
+
class Ack < Message
|
8
|
+
|
9
|
+
attr_reader :original_msg
|
10
|
+
|
11
|
+
#
|
12
|
+
def initialize(source, original, options = {})
|
13
|
+
raise ArgumentError, "Original message is required" unless original
|
14
|
+
super(source, options)
|
15
|
+
@original_msg = original
|
16
|
+
@error = options[:error] || nil
|
17
|
+
@status = options[:status] || nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def content
|
21
|
+
body do |ack|
|
22
|
+
ack.SIF_Ack() { |xml|
|
23
|
+
put_header_into xml
|
24
|
+
if @original_msg.source_id.nil? or @original_msg.source_id == ""
|
25
|
+
xml.SIF_OriginalSourceId
|
26
|
+
else
|
27
|
+
xml.SIF_OriginalSourceId(@original_msg.source_id)
|
28
|
+
end
|
29
|
+
if @original_msg.msg_id.nil? or @original_msg.msg_id == ""
|
30
|
+
xml.SIF_OriginalMsgId
|
31
|
+
else
|
32
|
+
xml.SIF_OriginalMsgId(@original_msg.msg_id)
|
33
|
+
end
|
34
|
+
xml << @error.read unless @error.nil?
|
35
|
+
xml << @status.read unless @status.nil?
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/messages/acl.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Siffer
|
2
|
+
module Messages
|
3
|
+
class Acl
|
4
|
+
|
5
|
+
# This class roles through all the objects in all the contexts in
|
6
|
+
# the zone to provide a list of allowed actions on each object per
|
7
|
+
# registered agent
|
8
|
+
|
9
|
+
def read
|
10
|
+
xml = Builder::XmlMarkup.new
|
11
|
+
xml.SIF_AgentAcl { |xml|
|
12
|
+
# each one of these would collect all objects for each context
|
13
|
+
xml.SIF_ProvideAccess
|
14
|
+
xml.SIF_SubscribeAccess
|
15
|
+
xml.SIF_PublishAddAccess
|
16
|
+
xml.SIF_PublishChangeAccess
|
17
|
+
xml.SIF_PublishDeleteAccess
|
18
|
+
xml.SIF_RequestAccess
|
19
|
+
xml.SIF_RespondAccess
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|