rsence 2.0.0.10.pre → 2.0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +10 -0
- data/INSTALL.rdoc +52 -86
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.rdoc +52 -49
- data/VERSION +1 -1
- data/bin/rsence +4 -6
- data/conf/default_conf.yaml +314 -305
- data/conf/default_strings.yaml +70 -71
- data/docs/ExampleGuiPlugin.rdoc +193 -0
- data/{js/comm/comm/autosync/js.inc → docs/JavascriptBundles.rdoc} +0 -0
- data/docs/PluginBundleInfo.rdoc +173 -0
- data/docs/PluginBundles.rdoc +96 -0
- data/docs/Values.rdoc +163 -0
- data/js/comm/{comm/autosync → autosync}/autosync.js +1 -2
- data/js/comm/{comm → autosync}/js.inc +0 -0
- data/js/comm/{comm/comm.js → comm.js} +1 -0
- data/js/comm/{comm/queue/js.inc → js.inc} +0 -0
- data/js/comm/jsloader/jsloader.js +2 -4
- data/js/comm/{comm/session → queue}/js.inc +0 -0
- data/js/comm/{comm/queue → queue}/queue.js +1 -0
- data/js/comm/{comm/sessionwatcher → session}/js.inc +0 -0
- data/js/comm/{comm/session → session}/session.js +4 -3
- data/js/comm/{comm/transporter → sessionwatcher}/js.inc +0 -0
- data/js/comm/{comm/sessionwatcher → sessionwatcher}/sessionwatcher.js +1 -0
- data/js/comm/{comm/urlresponder → transporter}/js.inc +0 -0
- data/js/comm/{comm/transporter → transporter}/transporter.js +1 -0
- data/js/comm/{comm/values → urlresponder}/js.inc +0 -0
- data/js/comm/{comm/urlresponder → urlresponder}/urlresponder.js +1 -0
- data/js/comm/{reloadapp → values}/js.inc +0 -0
- data/js/comm/{comm/values → values}/values.js +1 -0
- data/js/controls/button/button.js +10 -1
- data/js/controls/checkbox/checkbox.js +2 -0
- data/js/controls/dialogs/alert_sheet/alert_sheet.js +1 -0
- data/js/controls/dialogs/confirm_sheet/confirm_sheet.js +1 -0
- data/js/controls/dialogs/sheet/sheet.js +1 -0
- data/js/controls/imageview/imageview.js +1 -0
- data/js/controls/passwordcontrol/passwordcontrol.js +1 -0
- data/js/controls/progress/progressbar/progressbar.js +1 -0
- data/js/controls/progress/progressindicator/progressindicator.js +1 -0
- data/js/controls/radiobutton/radiobutton.js +3 -1
- data/js/controls/sliders/slider/slider.js +1 -0
- data/js/controls/sliders/vslider/vslider.js +1 -0
- data/js/controls/stepper/stepper.js +1 -0
- data/js/controls/stringview/stringview.js +2 -2
- data/js/controls/tab/tab.js +7 -5
- data/js/controls/textarea/textarea.js +1 -0
- data/js/controls/textcontrol/textcontrol.js +3 -1
- data/js/controls/uploader/uploader.js +1 -0
- data/js/controls/validatorview/validatorview.js +62 -59
- data/js/controls/window/window.js +1 -0
- data/js/core/class/class.js +2 -1
- data/js/core/elem/elem.js +27 -27
- data/js/core/event/event.js +3 -874
- data/js/{comm/sha → core/rsence_ns}/js.inc +0 -0
- data/js/core/rsence_ns/rsence_ns.js +15 -0
- data/js/{controls/datetime → datetime}/calendar/calendar.js +1 -0
- data/js/{comm/values/value → datetime/calendar}/js.inc +0 -0
- data/js/{controls/datetime → datetime}/calendar/themes/default/calendar.css +0 -0
- data/js/{controls/datetime → datetime}/calendar/themes/default/calendar.html +0 -0
- data/js/{controls/datetime → datetime}/calendar/themes/default/calendar_arrows-ie6.gif +0 -0
- data/js/{controls/datetime → datetime}/calendar/themes/default/calendar_arrows.png +0 -0
- data/js/{controls/datetime → datetime}/datetimevalue/datetimevalue.js +1 -0
- data/js/{comm/values/valuematrix → datetime/datetimevalue}/js.inc +0 -0
- data/js/{controls/datetime/calendar → datetime/timesheet}/js.inc +0 -0
- data/js/{controls/datetime → datetime}/timesheet/themes/default/timesheet.css +0 -0
- data/js/{controls/datetime → datetime}/timesheet/themes/default/timesheet.html +0 -0
- data/js/{controls/datetime → datetime}/timesheet/timesheet.js +1 -0
- data/js/{controls/datetime/datetimevalue → datetime/timesheet_item}/js.inc +0 -0
- data/js/{controls/datetime → datetime}/timesheet_item/themes/default/timesheet_item.css +0 -0
- data/js/{controls/datetime → datetime}/timesheet_item/themes/default/timesheet_item.html +0 -0
- data/js/{controls/datetime → datetime}/timesheet_item/timesheet_item.js +1 -0
- data/js/{controls/datetime/timesheet → datetime/timesheet_item_edit}/js.inc +0 -0
- data/js/{controls/datetime → datetime}/timesheet_item_edit/timesheet_item_edit.js +1 -1
- data/js/foundation/application/application.js +1 -2
- data/js/foundation/control/control.js +1 -4
- data/js/foundation/control/controldefaults/controldefaults.js +1 -4
- data/js/foundation/control/dummyvalue/dummyvalue.js +1 -0
- data/js/foundation/control/dyncontrol/dyncontrol.js +1 -2
- data/js/foundation/control/eventresponder/eventresponder.js +11 -3
- data/js/{controls/datetime/timesheet_item → foundation/control/valuematrix}/js.inc +0 -0
- data/js/{comm/values → foundation/control}/valuematrix/valuematrix.js +2 -5
- data/js/foundation/control/valueresponder/valueresponder.js +3 -1
- data/js/foundation/eventmanager/eventmanager.js +884 -0
- data/js/{controls/datetime/timesheet_item_edit → foundation/eventmanager}/js.inc +0 -0
- data/js/foundation/geom/point/point.js +2 -2
- data/js/foundation/geom/rect/rect.js +1 -0
- data/js/foundation/json_renderer/json_renderer.js +2 -0
- data/js/foundation/system/system.js +2 -1
- data/js/foundation/thememanager/thememanager.js +29 -23
- data/js/{controls/lists/checkboxlist → foundation/value}/js.inc +0 -0
- data/js/{comm/values → foundation}/value/value.js +1 -0
- data/js/foundation/view/markupview/markupview.js +2 -1
- data/js/foundation/view/morphanimation/morphanimation.js +1 -0
- data/js/foundation/view/view.js +6 -12
- data/js/foundation/view/viewdefaults/viewdefaults.js +1 -0
- data/js/{controls/lists → lists}/checkboxlist/checkboxlist.js +1 -0
- data/js/{controls/lists/listitems → lists/checkboxlist}/js.inc +0 -0
- data/js/{controls/lists/radiobuttonlist → lists/listitems}/js.inc +0 -0
- data/js/{controls/lists → lists}/listitems/listitems.js +22 -3
- data/js/lists/radiobuttonlist/js.inc +0 -0
- data/js/{controls/lists → lists}/radiobuttonlist/radiobuttonlist.js +2 -12
- data/js/util/reloadapp/js.inc +0 -0
- data/js/{comm → util}/reloadapp/reloadapp.js +10 -8
- data/js/{comm → util}/reloadapp/themes/default/reloadapp_warning-ie6.gif +0 -0
- data/js/{comm → util}/reloadapp/themes/default/reloadapp_warning.png +0 -0
- data/js/util/sha/js.inc +0 -0
- data/js/{comm → util}/sha/sha.js +27 -33
- data/js/views/centerview/centerview.js +33 -3
- data/js/views/inlineview/inlineview.js +1 -0
- data/js/views/scrollview/scrollview.js +1 -0
- data/lib/conf/argv.rb +34 -22
- data/lib/conf/default.rb +165 -173
- data/lib/daemon/daemon.rb +9 -9
- data/lib/daemon/sigcomm.rb +4 -4
- data/lib/http/broker.rb +30 -27
- data/lib/http/rackup.rb +2 -3
- data/lib/http/request.rb +1 -2
- data/lib/http/response.rb +10 -10
- data/lib/plugins/dependencies.rb +2 -1
- data/lib/plugins/gui_plugin.rb +77 -50
- data/lib/plugins/guiparser.rb +26 -22
- data/lib/plugins/plugin.rb +207 -427
- data/lib/plugins/plugin_base.rb +162 -0
- data/lib/plugins/plugin_plugins.rb +21 -15
- data/lib/plugins/plugin_sqlite_db.rb +45 -20
- data/lib/plugins/pluginmanager.rb +10 -5
- data/lib/plugins/plugins.rb +65 -31
- data/lib/plugins/servlet.rb +74 -26
- data/lib/rsence.rb +32 -0
- data/lib/session/msg.rb +131 -96
- data/lib/session/sessionmanager.rb +5 -4
- data/lib/session/sessionstorage.rb +4 -3
- data/lib/transporter/transporter.rb +30 -21
- data/lib/util/gzstring.rb +4 -2
- data/lib/util/ruby19_fixes.rb +18 -0
- data/lib/values/hvalue.rb +139 -88
- data/lib/values/valuemanager.rb +60 -46
- data/plugins/client_pkg/client_pkg.rb +6 -5
- data/plugins/client_pkg/lib/client_pkg_build.rb +5 -5
- data/plugins/client_pkg/lib/client_pkg_serve.rb +8 -0
- data/plugins/index_html/index_html.rb +3 -1
- data/plugins/index_html/tmpl/index.html +2 -3
- data/plugins/main/js/main.js +84 -0
- data/plugins/main/main.rb +54 -27
- data/plugins/ticket/lib/common.rb +4 -2
- data/plugins/ticket/lib/favicon.rb +3 -2
- data/plugins/ticket/lib/file.rb +2 -2
- data/plugins/ticket/lib/img.rb +2 -2
- data/plugins/ticket/lib/objblob.rb +2 -2
- data/plugins/ticket/lib/rsrc.rb +2 -2
- data/plugins/ticket/lib/upload.rb +9 -8
- data/plugins/ticket/ticket.rb +141 -8
- data/setup/welcome/welcome.rb +1 -0
- metadata +76 -72
- data/lib/plugins/plugin_util.rb +0 -107
- data/plugins/index_html/tmpl/startup_index.html +0 -29
- data/plugins/main/js/riassence_ns.js +0 -87
- data/setup/legacy/info.yaml +0 -18
- data/setup/legacy/legacy.rb +0 -17
- data/setup/welcome/gui/welcome.yaml +0 -68
- data/setup/welcome/text/welcome.html +0 -8
data/lib/plugins/servlet.rb
CHANGED
@@ -6,16 +6,41 @@
|
|
6
6
|
# with this software package. If not, contact licensing@riassence.com
|
7
7
|
##
|
8
8
|
|
9
|
-
|
9
|
+
|
10
|
+
module RSence
|
10
11
|
module Plugins
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
# Use the Servlet class to create responders for GET / POST urls.
|
14
|
+
#
|
15
|
+
# A Servlet's public API is accessible like the other plugins directly.
|
16
|
+
#
|
17
|
+
# == Responding to a URL consists of four phases:
|
18
|
+
# 1. PluginManager calls every {Servlet__#match #match} method
|
19
|
+
# 2. The plugins that return true to the {Servlet__#match #match} method are queried by their score -method
|
20
|
+
# 3. The matched plugins are sorted by score, lowest score wins. If it's a draw between equal scores, the choice is randomized.
|
21
|
+
# 4. The {Servlet__#post #post} or {Servlet__#get #get} method is called, depending on the type of HTTP request.
|
22
|
+
#
|
23
|
+
# = Extension hooks for server events
|
24
|
+
# These methods are provided as the basic server event hooks:
|
25
|
+
# * {#init +#init+} -- Use instead of +initialize+
|
26
|
+
# * {#open +#open+} -- Extend to open objects
|
27
|
+
# * {#flush +#flush+} -- Extend to write the state and to flush buffers
|
28
|
+
# * {#close +#close+} -- Extend to close objects
|
29
|
+
#
|
30
|
+
# = Extension hooks for REST events
|
31
|
+
# * {#match +#match+} -- Extend to return true for certain url and request_type conditions.
|
32
|
+
# * {#score +#score+} -- Extend to return a numeric score. Lower scores are "better" than higher ones.
|
33
|
+
# * {#get +#get+} -- Extend to handle a HTTP GET request and response.
|
34
|
+
# * {#post +#post+} -- Extend to handle a HTTP POST request and response.
|
35
|
+
class Servlet__
|
14
36
|
|
15
|
-
include
|
37
|
+
include PluginBase
|
16
38
|
|
39
|
+
# @private Class type identifier for the PluginManager.
|
40
|
+
# @return [:Servlet]
|
17
41
|
def self.bundle_type; :Servlet; end
|
18
42
|
|
43
|
+
# @private The constructor should not be accessed from anywhere else than the PluginManager, which does it automatically.
|
19
44
|
def initialize( bundle_name, bundle_info, bundle_path, plugin_manager )
|
20
45
|
@info = bundle_info
|
21
46
|
@name = bundle_name
|
@@ -25,36 +50,59 @@ module ::RSence
|
|
25
50
|
@inited = false
|
26
51
|
end
|
27
52
|
|
28
|
-
|
53
|
+
# @return [Symbol] The name of the plugin bundle
|
54
|
+
attr_reader :name
|
55
|
+
|
56
|
+
# @return [String] The absolute path of the plugin bundle.
|
57
|
+
attr_reader :path
|
58
|
+
|
59
|
+
# @return [Hash] The {file:PluginBundleInfo meta-information} of the plugin bundle.
|
60
|
+
attr_reader :info
|
61
|
+
|
62
|
+
# @private State of the plugin.
|
63
|
+
attr_reader :inited
|
64
|
+
|
29
65
|
|
30
|
-
|
66
|
+
# @private Used by PluginManager to register the plugin
|
67
|
+
def register
|
31
68
|
@plugins.register_bundle( self, @name )
|
32
69
|
@inited = true
|
33
70
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
#
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
#
|
44
|
-
#
|
45
|
-
|
46
|
-
|
47
|
-
end
|
71
|
+
|
72
|
+
# Extend to return true for the certain uri and request_type conditions your servlet code handles.
|
73
|
+
#
|
74
|
+
# @example Handles :get requests that begin with /foo
|
75
|
+
# def match( uri, request_type )
|
76
|
+
# request_type == :get and uri.start_with?( '/foo' )
|
77
|
+
# end
|
78
|
+
#
|
79
|
+
# @param [String] uri The request uri (full "path" of the request url).
|
80
|
+
# @param [:get, :post] request_type The type of request. Only :get and :post are handled yet.
|
81
|
+
#
|
82
|
+
# @return [true] to match
|
83
|
+
# @return [false] to not match. Returns false to everything, if not extended.
|
84
|
+
def match( uri, request_type=:get ); false; end
|
85
|
+
alias match? match
|
86
|
+
|
87
|
+
# If matched, returns score where lower is better. Score is needed for priority sorting, when several Servlet's {#match} are returning true for the same request.
|
88
|
+
#
|
89
|
+
# @return [Number]
|
90
|
+
def score; 100; end
|
48
91
|
|
49
92
|
# Extend to do any GET request processing. Not doing anything by default.
|
50
|
-
|
51
|
-
|
52
|
-
|
93
|
+
#
|
94
|
+
# @param [Request] req The HTTP Request object.
|
95
|
+
# @param [Response] res The HTTP Response object.
|
96
|
+
# @param [Hash] ses The session object, not implemented yet.
|
97
|
+
def get( req, res, ses ); end
|
53
98
|
|
54
99
|
# Extend to do any POST request processing. Not doing anything by default.
|
55
|
-
|
56
|
-
|
57
|
-
|
100
|
+
#
|
101
|
+
# @param [Request] req The HTTP Request object.
|
102
|
+
# @param [Response] res The HTTP Response object.
|
103
|
+
# @param [Hash] ses The session object, not implemented yet.
|
104
|
+
def post( req, res, ses ); end
|
105
|
+
|
58
106
|
end
|
59
107
|
end
|
60
108
|
end
|
data/lib/rsence.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
## RSence
|
2
|
+
# Copyright 2010 Riassence Inc.
|
3
|
+
# http://riassence.com/
|
4
|
+
#
|
5
|
+
# You should have received a copy of the GNU General Public License along
|
6
|
+
# with this software package. If not, contact licensing@riassence.com
|
7
|
+
##
|
8
|
+
|
9
|
+
# The RSence module contains the server interfaces of RSence.
|
10
|
+
# == The classes that matter from a Plugin developer's point of view are:
|
11
|
+
# - {RSence::Plugins::GUIPlugin__ GUIPlugin}
|
12
|
+
# - Use for user interface plugins. Supports {RSence::Plugins::GUIParser GUITree} handling; the user interface starts automatically.
|
13
|
+
# - No server programming except defining GUITree YAML structures is required to define a user interface when using this class.
|
14
|
+
# - {RSence::Plugins::Plugin__ Plugin}
|
15
|
+
# - Use for supporting plugins and advanced client-server development.
|
16
|
+
# - Great for providing backend functionality and miscellaneous API's for other Plugins.
|
17
|
+
# - {RSence::Plugins::Servlet__ Servlet}
|
18
|
+
# - Use for raw POST / GET handlers to provide external API's, search engine indexes, plain html fallback etc.
|
19
|
+
# - {RSence::HValue HValue}
|
20
|
+
# - Use for syncing data objects between client and server automatically.
|
21
|
+
# - Bind any plugin methods as responders / validators; they will be called whenever a client-server change triggers an data change event.
|
22
|
+
# - {RSence::Message Message (msg)}
|
23
|
+
# - Used extensively to pass around session, data and request/response bindings.
|
24
|
+
# - The standard convention is usage as the first parameter, named +msg+, of any method that includes handling session-related data.
|
25
|
+
#
|
26
|
+
# Most other classes are inner workings of RSence itself and are subject to change without further notice.
|
27
|
+
module RSence
|
28
|
+
end
|
29
|
+
|
30
|
+
# Requires the ARGVParser that functions as the command-line user interface.
|
31
|
+
require 'conf/argv'
|
32
|
+
|
data/lib/session/msg.rb
CHANGED
@@ -6,96 +6,101 @@
|
|
6
6
|
# with this software package. If not, contact licensing@riassence.com
|
7
7
|
##
|
8
8
|
|
9
|
+
|
10
|
+
require 'util/gzstring'
|
11
|
+
|
12
|
+
|
9
13
|
module RSence
|
10
|
-
require 'util/gzstring'
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
##
|
15
|
+
# A Message instance is used as a `messenger class` while processing client-server requests. It's initialized by the system and the convention guideline for its instance is +msg+, pass it on wherever msg might be needed.
|
16
|
+
# In most cases, the use of +msg+ is to just pass the same +msg+ onward from a method to another.
|
17
|
+
#
|
18
|
+
# @example Logs a message in the client javascript console.
|
19
|
+
# msg.console "#{Time.new.to_s} -- Testing.."
|
20
|
+
#
|
21
|
+
# @example Executes a custom Javascript command in the client.
|
22
|
+
# msg.reply "alert('Hello!');"
|
23
|
+
#
|
24
|
+
# @example Invalidates the session.
|
25
|
+
# msg.expire_session
|
26
|
+
#
|
27
|
+
# @example Creating a new {HValue}. Usage like this in any extended {Plugins::Plugin__ Plugin} or {Plugins::GUIPlugin__ GUIPlugin} class. It's recommended to use the +values.yaml+ file to create any initial values.
|
28
|
+
# def create_example_value( msg )
|
29
|
+
# ses = get_ses(msg)
|
30
|
+
# default_data = "Some text"
|
31
|
+
# if ses.has_key?( :example_value )
|
32
|
+
# # Resets the default data, causes it to update in the client too on the next sync.
|
33
|
+
# ses[:example_value].set( msg, default_data )
|
34
|
+
# else
|
35
|
+
# # Creates a new value with default data
|
36
|
+
# ses[:example_value] = HValue.new( msg, default_data )
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
#
|
38
40
|
class Message
|
39
41
|
|
40
|
-
# Session data placeholder, assigned by SessionManager.
|
42
|
+
# @private Session data placeholder, assigned by SessionManager.
|
41
43
|
attr_accessor :session
|
42
44
|
|
43
|
-
#
|
44
|
-
# what to do, when a new session is encountered.
|
45
|
-
# In
|
46
|
-
#
|
47
|
-
# user_id mapping needs to be done.
|
45
|
+
# Flag for a new session's first request.
|
46
|
+
# Check it in your code to decide what to do, when a new session is encountered.
|
47
|
+
# In systems that require authentication, this may be used as a trigger to display a login/register dialog.
|
48
|
+
# @return [Boolean] This flag is true on the first request of a newly created session.
|
48
49
|
attr_accessor :new_session
|
49
50
|
|
50
|
-
#
|
51
|
-
# to decide what to do, when a restored session is
|
52
|
-
#
|
53
|
-
# so you should at least not re-create or re-bind them.
|
51
|
+
# Flag for a restored session's first request.
|
52
|
+
# Check it in your code to decide what to do, when a restored session is encountered.
|
53
|
+
# @return [Boolean] This flag is true on the first request of a newly restored session.
|
54
54
|
attr_accessor :restored_session
|
55
55
|
|
56
|
-
# Contains the source ses on the first request after
|
57
|
-
#
|
56
|
+
# Contains the source ses on the first request after the active session was cloned from another session.
|
57
|
+
# @return [false, Hash]
|
58
58
|
attr_accessor :cloned_source
|
59
59
|
|
60
|
-
# Contains the target sessions packed in an
|
61
|
-
#
|
62
|
-
# from this session.
|
60
|
+
# Contains the target sessions packed in an Array on the first request after another session was cloned from the active session.
|
61
|
+
# @return [false, Array<Hash>]
|
63
62
|
attr_accessor :cloned_targets
|
64
63
|
|
65
|
-
# The session is not valid by default, it's set
|
66
|
-
# by SessionManager, if everything seems ok.
|
64
|
+
# @private The session is not valid by default, it's set by SessionManager, if everything seems ok.
|
67
65
|
attr_accessor :ses_valid
|
68
66
|
|
69
|
-
# The
|
67
|
+
# The HTTP Request object of the active request.
|
68
|
+
# @return [Request]
|
70
69
|
attr_accessor :request
|
71
70
|
|
72
|
-
# The
|
71
|
+
# The HTTP Response object of the active request.
|
72
|
+
# @return [Response]
|
73
73
|
attr_accessor :response
|
74
74
|
|
75
|
-
# Response output
|
75
|
+
# @private Response output buffer, Array of Strings; sent to client using to_json
|
76
76
|
attr_accessor :buffer
|
77
77
|
|
78
|
+
# @private Value response output buffer, Array value setters; sent to client using to_json before {:buffer} is sent
|
78
79
|
attr_accessor :value_buffer
|
79
80
|
|
80
|
-
# The request success flag.
|
81
|
+
# @private The request success flag; Boolean.
|
81
82
|
attr_accessor :response_success
|
82
83
|
|
83
|
-
# Reference to Transporter
|
84
|
+
# Reference to {Transporter}
|
85
|
+
# @return [Transporter]
|
84
86
|
attr_accessor :transporter
|
85
87
|
|
86
|
-
# Reference to ValueManager
|
88
|
+
# Reference to {ValueManager}
|
89
|
+
# @return [ValueManager]
|
87
90
|
attr_accessor :valuemanager
|
88
91
|
|
89
|
-
# Reference to SessionManager
|
92
|
+
# Reference to {SessionManager}
|
93
|
+
# @return [SessionManager]
|
90
94
|
attr_accessor :sessions
|
91
95
|
|
92
|
-
# Reference to PluginManager
|
96
|
+
# Reference to the main {PluginManager}
|
97
|
+
# @return [PluginManager]
|
93
98
|
attr_accessor :plugins
|
94
99
|
|
95
|
-
# Message is initialized with a valid
|
100
|
+
# @private Message is initialized with a valid {Transporter}, {Request} and {Response} objects along with options.
|
96
101
|
def initialize( transporter, request, response, options )
|
97
102
|
|
98
|
-
@config =
|
103
|
+
@config = RSence.config
|
99
104
|
|
100
105
|
@request = request
|
101
106
|
@response_success = false
|
@@ -127,11 +132,11 @@ module RSence
|
|
127
132
|
@do_gzip = false
|
128
133
|
else
|
129
134
|
@response.content_type = 'text/javascript; charset=utf-8'
|
130
|
-
@response['
|
135
|
+
@response['Cache-Control'] = 'no-cache'
|
131
136
|
|
132
137
|
# gnu-zipped responses:
|
133
138
|
if @request.header['accept-encoding'] and @request.header['accept-encoding'].include?('gzip') and not @config[:no_gzip]
|
134
|
-
@response['
|
139
|
+
@response['Content-Encoding'] = 'gzip'
|
135
140
|
@do_gzip = true
|
136
141
|
else
|
137
142
|
@do_gzip = false
|
@@ -141,58 +146,69 @@ module RSence
|
|
141
146
|
@response_sent = false
|
142
147
|
end
|
143
148
|
|
144
|
-
# Returns true for Internet Explorer 6.0
|
149
|
+
# @private Returns true for Internet Explorer 6.0
|
150
|
+
# @return [Boolean]
|
145
151
|
def ie6;
|
146
152
|
(request.header.has_key?('user-agent') and request.header['user-agent'].include?('MSIE 6.0'))
|
147
153
|
end
|
148
154
|
|
149
|
-
#
|
155
|
+
# Invalidates the active session.
|
156
|
+
# @return [nil]
|
150
157
|
def expire_session
|
151
158
|
@sessions.expire_session( @ses_id )
|
152
159
|
end
|
153
160
|
|
154
|
-
# Define the session key.
|
161
|
+
# @private Define the session key.
|
155
162
|
def ses_key=(ses_key)
|
156
163
|
@ses_key = ses_key
|
157
164
|
end
|
158
|
-
|
159
|
-
# Getter for session key.
|
165
|
+
|
166
|
+
# @private Getter for session key.
|
167
|
+
# @return [String] The active session key.
|
160
168
|
def ses_key
|
161
169
|
@ses_key
|
162
170
|
end
|
163
171
|
|
164
|
-
#
|
172
|
+
# Getter for the user id
|
173
|
+
# @return [Number, String] The current user id. Returns 0 by default.
|
165
174
|
def user_id
|
166
175
|
@session[:user_id]
|
167
176
|
end
|
168
177
|
|
169
178
|
# Setter for the user id
|
179
|
+
# @param [Number, String] user_id The user id to set. Use in login situations to store the user id.
|
180
|
+
# @return [nil]
|
170
181
|
def user_id=(user_id)
|
171
182
|
@session[:user_id] = user_id
|
172
183
|
end
|
173
184
|
|
174
185
|
# Returns the session id
|
186
|
+
# @return [Number]
|
175
187
|
def ses_id
|
176
188
|
@session[:ses_id]
|
177
189
|
end
|
190
|
+
alias session_id ses_id
|
178
191
|
|
179
|
-
# Sets the session id
|
192
|
+
# @private Sets the session id
|
193
|
+
# @param [Number] ses_id The session id to set.
|
194
|
+
# @return [nil]
|
180
195
|
def ses_id=(ses_id)
|
181
196
|
@session[:ses_id] = ses_id
|
182
197
|
end
|
183
198
|
|
184
|
-
# Sets the error message
|
199
|
+
# @private Sets the error message
|
200
|
+
# @param [String] error_js The error script to send instead of the regular buffers.
|
185
201
|
def error_msg( error_js )
|
186
202
|
@error_js = error_js
|
187
203
|
# response_done
|
188
204
|
end
|
189
205
|
|
190
|
-
# Converts the buffer to JSON
|
206
|
+
# @private Converts the buffer to JSON
|
191
207
|
def buf_json(buffer)
|
192
208
|
buffer.to_json
|
193
209
|
end
|
194
210
|
|
195
|
-
# Called to flush buffer.
|
211
|
+
# @private Called to flush buffer.
|
196
212
|
def response_done
|
197
213
|
return if @response_sent
|
198
214
|
if not @response_success
|
@@ -229,8 +245,9 @@ module RSence
|
|
229
245
|
@response_sent = true
|
230
246
|
end
|
231
247
|
|
232
|
-
# Sends data to the client, usually
|
233
|
-
#
|
248
|
+
# Sends data to the client, usually javascript, but is valid for any data that responds to #to_json
|
249
|
+
# @param [String<js>, #to_json] data Javascript source or object that responds to #to_json
|
250
|
+
# @param [Boolean] dont_squeeze When true, doesn't `squeeze` the contents (jsmin + jscompress)
|
234
251
|
def reply(data,dont_squeeze=false)
|
235
252
|
data.strip!
|
236
253
|
data = @plugins[:client_pkg].squeeze( data ) unless dont_squeeze
|
@@ -238,54 +255,72 @@ module RSence
|
|
238
255
|
@buffer.push( data )
|
239
256
|
end
|
240
257
|
|
241
|
-
# For value manager; insert changed values BEFORE other js.
|
258
|
+
# @private For value manager; insert changed values BEFORE other js.
|
242
259
|
def reply_value(data)
|
243
260
|
puts data if @config[:trace]
|
244
261
|
@value_buffer.push( data )
|
245
262
|
end
|
246
263
|
|
247
|
-
# Sends data to the client's console.
|
264
|
+
# Sends data to the client's javascript console.
|
265
|
+
# @param [#to_json] data Any data that can be presented in the Javascript console.
|
248
266
|
def console(data)
|
249
267
|
reply( "console.log(#{data.to_json});" )
|
250
268
|
end
|
251
|
-
|
252
|
-
# Serves an image object
|
253
|
-
#
|
254
|
-
#
|
269
|
+
|
270
|
+
# Serves an image object and returns its disposable URL.
|
271
|
+
# Calls the default `ticket` plugin.
|
272
|
+
# @param [#to_blob] img_obj RMagick image object.
|
273
|
+
# @param [String] img_format The format img_obj#to_blob is encoded as.
|
274
|
+
# @return [String] The URL where the image can be accessed from using a GET request.
|
275
|
+
# @deprecated
|
276
|
+
# Use {TicketPlugin#serve_img ticket.serve_img} directly instead.
|
255
277
|
def serve_img( img_obj, img_format='PNG' )
|
256
|
-
call(:ticket
|
278
|
+
call( :ticket, :serve_img, self, img_obj, img_format )
|
257
279
|
end
|
258
|
-
|
259
|
-
#
|
260
|
-
#
|
261
|
-
#
|
262
|
-
#
|
280
|
+
|
281
|
+
# Binary data to be served once as a downloadable file attachment, returns a disposable URL.
|
282
|
+
# Calls the default `ticket` plugin.
|
283
|
+
# @param [String] file_data The binary data to serve
|
284
|
+
# @param [String] content_type The MIME type to serve the data as
|
285
|
+
# @param [String] filename The name of the downloadable file.
|
286
|
+
# @return [String] The URL where the downloadable file can be accessed from using a GET request.
|
287
|
+
# @deprecated
|
288
|
+
# Use {TicketPlugin#serve_file ticket.serve_file} directly instead.
|
263
289
|
def serve_file( file_data, content_type='text/plain', filename='untitled.txt' )
|
264
|
-
call(:ticket
|
290
|
+
call( :ticket, :serve_file, self, file_data, content_type, filename )
|
265
291
|
end
|
266
|
-
|
267
|
-
# Sends any binary to be served, returns a static
|
268
|
-
#
|
269
|
-
# IMPORTANT: PLEASE call
|
270
|
-
#
|
271
|
-
#
|
272
|
-
#
|
273
|
-
#
|
274
|
-
#
|
292
|
+
|
293
|
+
# Sends any binary to be served indefinitely, returns a unique, random, static URL.
|
294
|
+
# Calls the default `ticket` plugin.
|
295
|
+
# IMPORTANT: PLEASE call {#release_rsrc} manually, when the resource is no longer needed to free the memory occupied!
|
296
|
+
# HINT: In most cases, it's a better idea to use serve_img or serve_file to expire the resource automatically.
|
297
|
+
# @see {#release_rsrc}
|
298
|
+
# @param [String] rsrc_data The binary data of the resource to serve.
|
299
|
+
# @param [String] content_type The MIME type to serve the data as
|
300
|
+
# @return [String] The URL where the resource can be accessed from using a GET request.
|
301
|
+
# @deprecated
|
302
|
+
# Use {TicketPlugin#serve_rsrc ticket.serve_rsrc} directly instead.
|
275
303
|
def serve_rsrc( rsrc_data, content_type='text/plain' )
|
276
304
|
call(:ticket,:serve_rsrc,self, rsrc_data, content_type )
|
277
305
|
end
|
278
306
|
|
279
|
-
# Removes the
|
280
|
-
#
|
307
|
+
# Removes the URL served, you *must* call this manually when after a served resource is no longer needed!
|
308
|
+
# Calls the default `ticket` plugin.
|
309
|
+
# @see {#serve_rsrc}
|
310
|
+
# @param [String] uri The URL to delete; the return value of {#serve_rsrc}
|
311
|
+
# @deprecated
|
312
|
+
# Use {TicketPlugin#serve_rsrc ticket.serve_rsrc} directly instead.
|
281
313
|
def release_rsrc( uri )
|
282
|
-
|
314
|
+
call(:ticket,:del_rsrc, uri[3..-1] )
|
283
315
|
end
|
284
316
|
alias unserve_rsrc release_rsrc
|
285
317
|
|
286
|
-
# Calls
|
287
|
-
|
288
|
-
|
318
|
+
# Calls a method of a registered plugin with optional arguments.
|
319
|
+
# @param [Symbol] plugin_name The plugin to call
|
320
|
+
# @param [Symbol] plugin_method The method of the plugin to call
|
321
|
+
# @param *args Any arguments to pass to the `plugin_method`
|
322
|
+
def call( plugin_name, plugin_method, *args )
|
323
|
+
@plugins.call( plugin_name, plugin_method, *args)
|
289
324
|
end
|
290
325
|
alias run call
|
291
326
|
end
|