libisi 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +677 -0
- data/Manifest +89 -0
- data/Rakefile +34 -0
- data/lib/inifile.rb +119 -0
- data/lib/libisi.rb +948 -0
- data/lib/libisi/attribute.rb +32 -0
- data/lib/libisi/attribute/activerecord.rb +34 -0
- data/lib/libisi/attribute/base.rb +33 -0
- data/lib/libisi/base.rb +109 -0
- data/lib/libisi/bridge.rb +21 -0
- data/lib/libisi/bridge/base.rb +23 -0
- data/lib/libisi/bridge/java.rb +71 -0
- data/lib/libisi/bridge/python.rb +37 -0
- data/lib/libisi/cache.rb +21 -0
- data/lib/libisi/cache/base.rb +67 -0
- data/lib/libisi/cache/file_cache.rb +24 -0
- data/lib/libisi/chart.rb +21 -0
- data/lib/libisi/chart/base.rb +320 -0
- data/lib/libisi/chart/jfreechart.rb +682 -0
- data/lib/libisi/chart/jfreechart_generator.rb +206 -0
- data/lib/libisi/color.rb +21 -0
- data/lib/libisi/color/base.rb +66 -0
- data/lib/libisi/color/colortools.rb +92 -0
- data/lib/libisi/color/java.rb +44 -0
- data/lib/libisi/concept.rb +33 -0
- data/lib/libisi/concept/activerecord.rb +39 -0
- data/lib/libisi/concept/base.rb +58 -0
- data/lib/libisi/doc.rb +35 -0
- data/lib/libisi/doc/base.rb +414 -0
- data/lib/libisi/doc/html.rb +85 -0
- data/lib/libisi/doc/text.rb +98 -0
- data/lib/libisi/doc/wiki.rb +55 -0
- data/lib/libisi/environment.rb +21 -0
- data/lib/libisi/environment/base.rb +36 -0
- data/lib/libisi/environment/http.rb +105 -0
- data/lib/libisi/environment/rails.rb +27 -0
- data/lib/libisi/environment/root.rb +23 -0
- data/lib/libisi/fake_logger/logger.rb +61 -0
- data/lib/libisi/function/base.rb +30 -0
- data/lib/libisi/hal.rb +558 -0
- data/lib/libisi/instance.rb +27 -0
- data/lib/libisi/instance/activerecord.rb +21 -0
- data/lib/libisi/instance/base.rb +42 -0
- data/lib/libisi/log.rb +237 -0
- data/lib/libisi/mail/base.rb +32 -0
- data/lib/libisi/mail/tmail.rb +120 -0
- data/lib/libisi/parameter/base.rb +41 -0
- data/lib/libisi/property.rb +27 -0
- data/lib/libisi/property/base.rb +28 -0
- data/lib/libisi/reciever/base.rb +31 -0
- data/lib/libisi/reciever/socket.rb +31 -0
- data/lib/libisi/relation.rb +23 -0
- data/lib/libisi/request.rb +22 -0
- data/lib/libisi/request/base.rb +29 -0
- data/lib/libisi/request/http.rb +129 -0
- data/lib/libisi/response/base.rb +27 -0
- data/lib/libisi/task/base.rb +27 -0
- data/lib/libisi/task/http.rb +90 -0
- data/lib/libisi/tee.rb +296 -0
- data/lib/libisi/ui/base.rb +116 -0
- data/lib/libisi/ui/console.rb +238 -0
- data/lib/libisi/ui/kde.rb +94 -0
- data/lib/libisi/ui/nobody.rb +29 -0
- data/lib/libisi/ui/rails.rb +150 -0
- data/lib/libisi/ui/x11.rb +55 -0
- data/lib/libisi/uri.rb +42 -0
- data/lib/libisi/uri/activerecord.rb +152 -0
- data/lib/libisi/uri/base.rb +115 -0
- data/lib/libisi/uri/file.rb +43 -0
- data/lib/libisi/uri/ldap.rb +72 -0
- data/lib/libisi/uri/mysql.rb +98 -0
- data/lib/libisi/value.rb +31 -0
- data/lib/libisi/value/attribute_value.rb +19 -0
- data/lib/libisi/value/base.rb +55 -0
- data/lib/libisi/value/property_value.rb +19 -0
- data/lib/libisi/value/relation_value.rb +19 -0
- data/lib/ordered_hash.rb +228 -0
- data/libisi.gemspec +31 -0
- data/test/bridge_test.rb +77 -0
- data/test/cache_test.rb +65 -0
- data/test/chart_test.rb +179 -0
- data/test/color_test.rb +64 -0
- data/test/concept_test.rb +56 -0
- data/test/doc_test.rb +172 -0
- data/test/fixtures/test.db +0 -0
- data/test/ordered_hash_test.rb +39 -0
- data/test/profile_test.rb +36 -0
- data/test/request_test.rb +121 -0
- data/test/test +0 -0
- data/test/ui_test.rb +62 -0
- metadata +244 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
# object:
|
19
|
+
# Object to work on
|
20
|
+
# * a Class: For class methods
|
21
|
+
# * a Object: For instance methods
|
22
|
+
# * a Hash of Attributes: For pseudo instance functions
|
23
|
+
# * nil: For normal functions without context (default)
|
24
|
+
#
|
25
|
+
# arguments:
|
26
|
+
# Array of arguments (ARGV?)
|
27
|
+
# default: []
|
28
|
+
#
|
29
|
+
# parameters:
|
30
|
+
# Hash of options
|
31
|
+
# default: {}
|
32
|
+
class BaseParameter
|
33
|
+
|
34
|
+
attr_accessor :object, :arguments, :options
|
35
|
+
def initialize
|
36
|
+
@object = nil
|
37
|
+
@arguments = []
|
38
|
+
@options = {}
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "libisi/base.rb"
|
19
|
+
require "libisi/concept/base.rb"
|
20
|
+
require "libisi/property/base.rb"
|
21
|
+
class Property < Base
|
22
|
+
|
23
|
+
def self.create(concept, val, options = {})
|
24
|
+
BaseProperty.new(concept, val)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
class BaseProperty
|
19
|
+
|
20
|
+
attr_reader :base_class, :name
|
21
|
+
|
22
|
+
def initialize(base_class, name, options = {})
|
23
|
+
@base_class = base_class
|
24
|
+
@name = name
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
class BaseReciever
|
19
|
+
|
20
|
+
attr_accessor :create_block
|
21
|
+
|
22
|
+
def initialize(recieving_concept, options = {}, &block)
|
23
|
+
raise "No create block given" unless block
|
24
|
+
@create_block = block
|
25
|
+
end
|
26
|
+
|
27
|
+
def get
|
28
|
+
@create_block.call(self.get_io)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "libisi/reciever/base"
|
19
|
+
require "socket"
|
20
|
+
class SocketReciever < BaseReciever
|
21
|
+
|
22
|
+
def initialize(port, options = {}, &block)
|
23
|
+
super
|
24
|
+
@server = TCPServer.new(port)
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_io
|
28
|
+
@server.accept
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "libisi/base.rb"
|
19
|
+
require "libisi/concept/base.rb"
|
20
|
+
class Relation < Base
|
21
|
+
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "libisi/base.rb"
|
19
|
+
|
20
|
+
class Request < Base
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
class BaseRequest
|
19
|
+
|
20
|
+
attr_accessor :environment, :task
|
21
|
+
|
22
|
+
def initialize(env, task, options = {})
|
23
|
+
@environment = env
|
24
|
+
@task = task
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute; environment.execute(task); end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "libisi/request/base"
|
19
|
+
require "libisi/environment/http"
|
20
|
+
require "libisi/function/base"
|
21
|
+
require "libisi/task/base"
|
22
|
+
require "libisi/parameter/base"
|
23
|
+
require "uri"
|
24
|
+
require "cgi"
|
25
|
+
|
26
|
+
class HttpRequest < BaseRequest
|
27
|
+
|
28
|
+
|
29
|
+
# Splits a ordinary http url into
|
30
|
+
# * HttpEnvironment
|
31
|
+
# * Task(Function and Parameters)
|
32
|
+
def HttpRequest.from_uri(uri, options = {})
|
33
|
+
raise "Unexpected uri provided #{uri.parse}" unless uri.class == URI::HTTP
|
34
|
+
options = {
|
35
|
+
:root => URI::HTTP.build(:scheme => uri.scheme,
|
36
|
+
:userinfo => uri.userinfo,
|
37
|
+
:host => uri.host,
|
38
|
+
:port => uri.port,
|
39
|
+
:path => "/")
|
40
|
+
}.merge(options)
|
41
|
+
|
42
|
+
unless uri.to_s.starts_with?(options[:root].to_s)
|
43
|
+
raise "URI #{uri.to_s} does not start with root #{options[:root].to_s}"
|
44
|
+
end
|
45
|
+
|
46
|
+
# take the rest of the path as context, function name and arguments
|
47
|
+
path_rest = uri.path[options[:root].path.length..-1]
|
48
|
+
|
49
|
+
# environment
|
50
|
+
env = HttpEnvironment.new(options[:root])
|
51
|
+
|
52
|
+
# task
|
53
|
+
task = HttpTask.from_path_with_parameters(path_rest + "?" + uri.query)
|
54
|
+
|
55
|
+
HttpRequest.new(env, task)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
=begin
|
60
|
+
#!/usr/bin/ruby
|
61
|
+
|
62
|
+
# hello.pl -- my first perl script!
|
63
|
+
|
64
|
+
|
65
|
+
cgi = CGI.new('html4')
|
66
|
+
|
67
|
+
page = nil
|
68
|
+
page = $1 if cgi["old_link"] =~ /([^\/]+\.cgi)/
|
69
|
+
|
70
|
+
NEW_ROOT = "https://todo.kapozh.imsec.ch/kapozilla/"
|
71
|
+
unless page
|
72
|
+
uri = NEW_ROOT
|
73
|
+
else
|
74
|
+
uri = URI.parse("#{NEW_ROOT}#{page}")
|
75
|
+
|
76
|
+
ps = cgi.params.map {|name, vals|
|
77
|
+
next if name == "old_link"
|
78
|
+
vals.map {|val| "#{name}=#{CGI.escape(val)}"}
|
79
|
+
}.compact.flatten.join("&")
|
80
|
+
uri = uri.to_s + "?" + ps
|
81
|
+
end
|
82
|
+
|
83
|
+
uri = uri.to_s
|
84
|
+
|
85
|
+
# Ask the cgi object to send some text out to the browser.
|
86
|
+
cgi.out {
|
87
|
+
cgi.html {
|
88
|
+
cgi.body {
|
89
|
+
cgi.h1 { 'KapoZilla ist umgezogen' } +
|
90
|
+
cgi.p { 'Die von Ihnen gewählte URL ist nicht mehr gültig. Sie zeigt auf eine frühere Instanz von KapoZilla.'} +
|
91
|
+
cgi.p {
|
92
|
+
if page
|
93
|
+
'Der neue, richtige Link lautet: ' +
|
94
|
+
cgi.a(uri) { uri }
|
95
|
+
else
|
96
|
+
'Die neue Instanz befindet sich hier: ' + cgi.a(uri) {uri}
|
97
|
+
end +
|
98
|
+
'<br><br>Bitte passen Sie Ihre URL entsprechend an.'
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
exit 0
|
105
|
+
|
106
|
+
print "Content-type: text/html\n\n"
|
107
|
+
|
108
|
+
print <<EOF
|
109
|
+
<HTML>
|
110
|
+
<HEAD>
|
111
|
+
<TITLE>KapoZilla Moved</TITLE>
|
112
|
+
</HEAD>
|
113
|
+
|
114
|
+
<BODY>
|
115
|
+
<H1>KapoZilla ist umgezogen</H1>
|
116
|
+
|
117
|
+
<P>
|
118
|
+
Die von Ihnen gewählte URL ist nicht mehr gültig. Sie zeigt auf eine führere
|
119
|
+
Instaz von KapoZilla.
|
120
|
+
|
121
|
+
Der neue, richtige Link ist<br>
|
122
|
+
#{URI.parse(ARGV[0]).inspect}<br>
|
123
|
+
Bitte passen Sie Ihre URL entsprechend an.
|
124
|
+
</P>
|
125
|
+
|
126
|
+
</BODY>
|
127
|
+
</HTML>
|
128
|
+
EOF
|
129
|
+
=end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
class BaseResponse
|
19
|
+
|
20
|
+
attr_accessor :task, :request
|
21
|
+
|
22
|
+
def initialize(task, request, options = {})
|
23
|
+
@task = task
|
24
|
+
@request = request
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
class BaseTask
|
19
|
+
|
20
|
+
attr_accessor :function, :parameter
|
21
|
+
|
22
|
+
def initialize(function, parameter)
|
23
|
+
@function = function
|
24
|
+
@parameter = parameter
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Copyright (C) 2007-2010 Logintas AG Switzerland
|
2
|
+
#
|
3
|
+
# This file is part of Libisi.
|
4
|
+
#
|
5
|
+
# Libisi is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# Libisi is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with Libisi. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
18
|
+
require "libisi/task/base"
|
19
|
+
require "libisi/function/base"
|
20
|
+
require "libisi/parameter/base"
|
21
|
+
require "cgi"
|
22
|
+
class HttpTask < BaseTask
|
23
|
+
|
24
|
+
# Splits the rest of the uri path into context,
|
25
|
+
# function name and arguments.
|
26
|
+
#
|
27
|
+
# First regular expression match as context
|
28
|
+
# Second regular expression match as function name
|
29
|
+
# the rest of the matches as arguments
|
30
|
+
DEFAULT_CONTEXT_NAME_ARG_REGEXP =
|
31
|
+
/^\/?([^\/]+)\/([^\/]+)\/(.+)$/
|
32
|
+
|
33
|
+
def HttpTask.from_path(path, options = {})
|
34
|
+
unless path =~ DEFAULT_CONTEXT_NAME_ARG_REGEXP
|
35
|
+
raise "context name arg regular expression did not match #{path.inspect}"
|
36
|
+
end
|
37
|
+
context = $1
|
38
|
+
function_name = $2
|
39
|
+
arguments = $3.split("/")
|
40
|
+
|
41
|
+
# function
|
42
|
+
func = BaseFunction.new(context, function_name)
|
43
|
+
|
44
|
+
# parameter
|
45
|
+
params = BaseParameter.new
|
46
|
+
params.arguments = arguments
|
47
|
+
|
48
|
+
HttpTask.new(func, params)
|
49
|
+
end
|
50
|
+
|
51
|
+
def HttpTask.from_path_with_parameters(full_path, options = {})
|
52
|
+
path, query = full_path.split("?",2)
|
53
|
+
task = HttpTask.from_path(path, options)
|
54
|
+
if query
|
55
|
+
n_opts = {}
|
56
|
+
CGI::parse(query).each {|key,val|
|
57
|
+
n_opts[key.to_sym] = val
|
58
|
+
}
|
59
|
+
task.parameter.options = task.parameter.options.merge(n_opts)
|
60
|
+
end
|
61
|
+
|
62
|
+
task
|
63
|
+
end
|
64
|
+
|
65
|
+
def HttpTask.from_browser(io, options = {})
|
66
|
+
p "gets"
|
67
|
+
request_line = io.gets
|
68
|
+
p "request_line: #{request_line}"
|
69
|
+
# base from webrick/httprequest.rb read_request_line(socket)
|
70
|
+
if /^(\S+)\s+(\S+)(?:\s+HTTP\/(\d+\.\d+))?\r?\n/mo =~ request_line
|
71
|
+
request_method = $1
|
72
|
+
unparsed_uri = $2
|
73
|
+
http_version = ($3 ? $3 : "0.9")
|
74
|
+
|
75
|
+
request = HttpTask.from_path_with_parameters(unparsed_uri)
|
76
|
+
request.parameter.options[:http_version] = http_version
|
77
|
+
request.parameter.options[:request_method] = $1
|
78
|
+
request.parameter.options[:input_stream] = io
|
79
|
+
request.parameter.options[:output_stream] = io
|
80
|
+
request
|
81
|
+
|
82
|
+
# TODO: read parameters
|
83
|
+
else
|
84
|
+
rl = request_line.sub(/\x0d?\x0a\z/o, '')
|
85
|
+
raise "Bad request #{rl.inspect}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
end
|