rsence 2.0.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (311) hide show
  1. data/INSTALL.rdoc +295 -0
  2. data/LICENSE +622 -0
  3. data/README.rdoc +24 -0
  4. data/VERSION +1 -0
  5. data/bin/build_client.rb +254 -0
  6. data/bin/help +6 -0
  7. data/bin/launch.rb +120 -0
  8. data/bin/rdoc.sh +2 -0
  9. data/bin/restart +6 -0
  10. data/bin/rsence +120 -0
  11. data/bin/run +6 -0
  12. data/bin/run.rb +6 -0
  13. data/bin/save +6 -0
  14. data/bin/start +6 -0
  15. data/bin/status +6 -0
  16. data/bin/stop +6 -0
  17. data/conf/config.ru +5 -0
  18. data/conf/default_conf.yaml +337 -0
  19. data/conf/default_strings.yaml +77 -0
  20. data/conf/local_conf.yaml +14 -0
  21. data/conf/unicorn.conf +78 -0
  22. data/js/comm/comm/autosync/autosync.js +18 -0
  23. data/js/comm/comm/autosync/js.inc +0 -0
  24. data/js/comm/comm/comm.js +195 -0
  25. data/js/comm/comm/js.inc +0 -0
  26. data/js/comm/comm/queue/js.inc +0 -0
  27. data/js/comm/comm/queue/queue.js +183 -0
  28. data/js/comm/comm/session/js.inc +0 -0
  29. data/js/comm/comm/session/session.js +51 -0
  30. data/js/comm/comm/sessionwatcher/js.inc +0 -0
  31. data/js/comm/comm/sessionwatcher/sessionwatcher.js +43 -0
  32. data/js/comm/comm/transporter/js.inc +0 -0
  33. data/js/comm/comm/transporter/transporter.js +257 -0
  34. data/js/comm/comm/urlresponder/js.inc +0 -0
  35. data/js/comm/comm/urlresponder/urlresponder.js +148 -0
  36. data/js/comm/comm/values/js.inc +0 -0
  37. data/js/comm/comm/values/values.js +432 -0
  38. data/js/comm/jsloader/js.inc +0 -0
  39. data/js/comm/jsloader/jsloader.js +114 -0
  40. data/js/comm/reloadapp/js.inc +0 -0
  41. data/js/comm/reloadapp/reloadapp.js +150 -0
  42. data/js/comm/reloadapp/themes/default/reloadapp_warning-ie6.gif +0 -0
  43. data/js/comm/reloadapp/themes/default/reloadapp_warning.png +0 -0
  44. data/js/comm/sha/js.inc +0 -0
  45. data/js/comm/sha/sha.js +432 -0
  46. data/js/comm/values/value/js.inc +0 -0
  47. data/js/comm/values/value/value.js +182 -0
  48. data/js/comm/values/valuematrix/js.inc +0 -0
  49. data/js/comm/values/valuematrix/valuematrix.js +138 -0
  50. data/js/controls/button/button.js +57 -0
  51. data/js/controls/button/js.inc +0 -0
  52. data/js/controls/button/themes/bright/button.css +89 -0
  53. data/js/controls/button/themes/bright/button.html +7 -0
  54. data/js/controls/button/themes/bright/button_parts1-ie6.gif +0 -0
  55. data/js/controls/button/themes/bright/button_parts1.png +0 -0
  56. data/js/controls/button/themes/default/button.css +89 -0
  57. data/js/controls/button/themes/default/button.html +7 -0
  58. data/js/controls/button/themes/default/button_parts1-ie6.gif +0 -0
  59. data/js/controls/button/themes/default/button_parts1.png +0 -0
  60. data/js/controls/checkbox/checkbox.js +47 -0
  61. data/js/controls/checkbox/js.inc +0 -0
  62. data/js/controls/checkbox/themes/default/checkbox.css +69 -0
  63. data/js/controls/checkbox/themes/default/checkbox.html +5 -0
  64. data/js/controls/checkbox/themes/default/checkbox_parts1-ie6.gif +0 -0
  65. data/js/controls/checkbox/themes/default/checkbox_parts1.png +0 -0
  66. data/js/controls/datetime/calendar/calendar.js +197 -0
  67. data/js/controls/datetime/calendar/js.inc +0 -0
  68. data/js/controls/datetime/calendar/themes/default/calendar.css +108 -0
  69. data/js/controls/datetime/calendar/themes/default/calendar.html +9 -0
  70. data/js/controls/datetime/calendar/themes/default/calendar_arrows-ie6.gif +0 -0
  71. data/js/controls/datetime/calendar/themes/default/calendar_arrows.png +0 -0
  72. data/js/controls/datetime/datetimevalue/datetimevalue.js +246 -0
  73. data/js/controls/datetime/datetimevalue/js.inc +0 -0
  74. data/js/controls/datetime/timesheet/js.inc +0 -0
  75. data/js/controls/datetime/timesheet/themes/default/timesheet.css +30 -0
  76. data/js/controls/datetime/timesheet/themes/default/timesheet.html +2 -0
  77. data/js/controls/datetime/timesheet/timesheet.js +182 -0
  78. data/js/controls/datetime/timesheet_item/js.inc +0 -0
  79. data/js/controls/datetime/timesheet_item/themes/default/timesheet_item.css +42 -0
  80. data/js/controls/datetime/timesheet_item/themes/default/timesheet_item.html +8 -0
  81. data/js/controls/datetime/timesheet_item/timesheet_item.js +247 -0
  82. data/js/controls/datetime/timesheet_item_edit/js.inc +0 -0
  83. data/js/controls/datetime/timesheet_item_edit/timesheet_item_edit.js +274 -0
  84. data/js/controls/dialogs/alert_sheet/alert_sheet.js +62 -0
  85. data/js/controls/dialogs/alert_sheet/js.inc +0 -0
  86. data/js/controls/dialogs/confirm_sheet/confirm_sheet.js +36 -0
  87. data/js/controls/dialogs/confirm_sheet/js.inc +0 -0
  88. data/js/controls/dialogs/sheet/js.inc +0 -0
  89. data/js/controls/dialogs/sheet/sheet.js +83 -0
  90. data/js/controls/dialogs/sheet/themes/default/sheet.css +64 -0
  91. data/js/controls/dialogs/sheet/themes/default/sheet.html +14 -0
  92. data/js/controls/dialogs/sheet/themes/default/sheet_bg-ie6.gif +0 -0
  93. data/js/controls/dialogs/sheet/themes/default/sheet_bg.png +0 -0
  94. data/js/controls/dialogs/sheet/themes/default/sheet_dim-ie6.gif +0 -0
  95. data/js/controls/dialogs/sheet/themes/default/sheet_dim.png +0 -0
  96. data/js/controls/dialogs/sheet/themes/default/sheet_parts1-ie6.gif +0 -0
  97. data/js/controls/dialogs/sheet/themes/default/sheet_parts1.png +0 -0
  98. data/js/controls/dialogs/sheet/themes/default/sheet_parts2-ie6.gif +0 -0
  99. data/js/controls/dialogs/sheet/themes/default/sheet_parts2.png +0 -0
  100. data/js/controls/dialogs/sheet/themes/default/sheet_warning-ie6.gif +0 -0
  101. data/js/controls/dialogs/sheet/themes/default/sheet_warning.png +0 -0
  102. data/js/controls/imageview/imageview.js +108 -0
  103. data/js/controls/imageview/js.inc +0 -0
  104. data/js/controls/imageview/themes/default/blank.gif +0 -0
  105. data/js/controls/lists/checkboxlist/checkboxlist.js +170 -0
  106. data/js/controls/lists/checkboxlist/js.inc +0 -0
  107. data/js/controls/lists/listitems/js.inc +0 -0
  108. data/js/controls/lists/listitems/listitems.js +65 -0
  109. data/js/controls/lists/radiobuttonlist/js.inc +0 -0
  110. data/js/controls/lists/radiobuttonlist/radiobuttonlist.js +126 -0
  111. data/js/controls/passwordcontrol/js.inc +0 -0
  112. data/js/controls/passwordcontrol/passwordcontrol.js +22 -0
  113. data/js/controls/passwordcontrol/themes/default/passwordcontrol.css +0 -0
  114. data/js/controls/passwordcontrol/themes/default/passwordcontrol.html +18 -0
  115. data/js/controls/progress/progressbar/js.inc +0 -0
  116. data/js/controls/progress/progressbar/progressbar.js +36 -0
  117. data/js/controls/progress/progressbar/themes/default/progressbar.css +16 -0
  118. data/js/controls/progress/progressbar/themes/default/progressbar.html +2 -0
  119. data/js/controls/progress/progressindicator/js.inc +0 -0
  120. data/js/controls/progress/progressindicator/progressindicator.js +43 -0
  121. data/js/controls/radiobutton/js.inc +0 -0
  122. data/js/controls/radiobutton/radiobutton.js +41 -0
  123. data/js/controls/radiobutton/themes/default/radiobutton.css +69 -0
  124. data/js/controls/radiobutton/themes/default/radiobutton.html +5 -0
  125. data/js/controls/radiobutton/themes/default/radiobutton_parts1-ie6.gif +0 -0
  126. data/js/controls/radiobutton/themes/default/radiobutton_parts1.png +0 -0
  127. data/js/controls/sliders/slider/js.inc +0 -0
  128. data/js/controls/sliders/slider/slider.js +356 -0
  129. data/js/controls/sliders/slider/themes/default/hslider_tracks-ie6.gif +0 -0
  130. data/js/controls/sliders/slider/themes/default/hslider_tracks.png +0 -0
  131. data/js/controls/sliders/slider/themes/default/slider.css +108 -0
  132. data/js/controls/sliders/slider/themes/default/slider.html +5 -0
  133. data/js/controls/sliders/slider/themes/default/slider_thumbs-ie6.gif +0 -0
  134. data/js/controls/sliders/slider/themes/default/slider_thumbs.png +0 -0
  135. data/js/controls/sliders/vslider/js.inc +0 -0
  136. data/js/controls/sliders/vslider/themes/default/vslider.css +52 -0
  137. data/js/controls/sliders/vslider/themes/default/vslider.html +5 -0
  138. data/js/controls/sliders/vslider/themes/default/vslider_tracks-ie6.gif +0 -0
  139. data/js/controls/sliders/vslider/themes/default/vslider_tracks.png +0 -0
  140. data/js/controls/sliders/vslider/vslider.js +40 -0
  141. data/js/controls/stepper/js.inc +0 -0
  142. data/js/controls/stepper/stepper.js +212 -0
  143. data/js/controls/stepper/themes/default/stepper-ie6.gif +0 -0
  144. data/js/controls/stepper/themes/default/stepper.css +14 -0
  145. data/js/controls/stepper/themes/default/stepper.html +2 -0
  146. data/js/controls/stepper/themes/default/stepper.png +0 -0
  147. data/js/controls/stringview/js.inc +0 -0
  148. data/js/controls/stringview/stringview.js +49 -0
  149. data/js/controls/stringview/themes/default/stringview.css +8 -0
  150. data/js/controls/stringview/themes/default/stringview.html +1 -0
  151. data/js/controls/tab/js.inc +0 -0
  152. data/js/controls/tab/tab.js +276 -0
  153. data/js/controls/tab/themes/bright/tab.css +76 -0
  154. data/js/controls/tab/themes/bright/tab.html +6 -0
  155. data/js/controls/tab/themes/bright/tab_bg_color-ie6.gif +0 -0
  156. data/js/controls/tab/themes/bright/tab_bg_color.png +0 -0
  157. data/js/controls/tab/themes/bright/tab_border_pattern-ie6.gif +0 -0
  158. data/js/controls/tab/themes/bright/tab_border_pattern.png +0 -0
  159. data/js/controls/tab/themes/bright/tab_parts1-ie6.gif +0 -0
  160. data/js/controls/tab/themes/bright/tab_parts1.png +0 -0
  161. data/js/controls/tab/themes/default/tab.css +77 -0
  162. data/js/controls/tab/themes/default/tab.html +6 -0
  163. data/js/controls/tab/themes/default/tab_bg_color-ie6.gif +0 -0
  164. data/js/controls/tab/themes/default/tab_bg_color.png +0 -0
  165. data/js/controls/tab/themes/default/tab_border_pattern-ie6.gif +0 -0
  166. data/js/controls/tab/themes/default/tab_border_pattern.png +0 -0
  167. data/js/controls/tab/themes/default/tab_parts1-ie6.gif +0 -0
  168. data/js/controls/tab/themes/default/tab_parts1.png +0 -0
  169. data/js/controls/textarea/js.inc +0 -0
  170. data/js/controls/textarea/textarea.js +23 -0
  171. data/js/controls/textarea/themes/default/textarea.css +21 -0
  172. data/js/controls/textarea/themes/default/textarea.html +18 -0
  173. data/js/controls/textcontrol/js.inc +0 -0
  174. data/js/controls/textcontrol/textcontrol.js +372 -0
  175. data/js/controls/textcontrol/themes/default/textcontrol.css +107 -0
  176. data/js/controls/textcontrol/themes/default/textcontrol.html +18 -0
  177. data/js/controls/textcontrol/themes/default/textcontrol_parts1-ie6.gif +0 -0
  178. data/js/controls/textcontrol/themes/default/textcontrol_parts1.png +0 -0
  179. data/js/controls/textcontrol/themes/default/textcontrol_parts2-ie6.gif +0 -0
  180. data/js/controls/textcontrol/themes/default/textcontrol_parts2.png +0 -0
  181. data/js/controls/textcontrol/themes/default/textcontrol_parts3-ie6.gif +0 -0
  182. data/js/controls/textcontrol/themes/default/textcontrol_parts3.png +0 -0
  183. data/js/controls/uploader/js.inc +0 -0
  184. data/js/controls/uploader/themes/default/upload_progress.gif +0 -0
  185. data/js/controls/uploader/themes/default/uploader.css +108 -0
  186. data/js/controls/uploader/themes/default/uploader.html +27 -0
  187. data/js/controls/uploader/uploader.js +153 -0
  188. data/js/controls/validatorview/js.inc +0 -0
  189. data/js/controls/validatorview/themes/default/validator-ie6.gif +0 -0
  190. data/js/controls/validatorview/themes/default/validator.png +0 -0
  191. data/js/controls/validatorview/themes/default/validatorview.css +0 -0
  192. data/js/controls/validatorview/themes/default/validatorview.html +0 -0
  193. data/js/controls/validatorview/validatorview.js +55 -0
  194. data/js/controls/window/js.inc +0 -0
  195. data/js/controls/window/themes/default/window.css +219 -0
  196. data/js/controls/window/themes/default/window.html +17 -0
  197. data/js/controls/window/themes/default/window_bg_active-ie6.gif +0 -0
  198. data/js/controls/window/themes/default/window_bg_active.png +0 -0
  199. data/js/controls/window/themes/default/window_bg_inactive-ie6.gif +0 -0
  200. data/js/controls/window/themes/default/window_bg_inactive.png +0 -0
  201. data/js/controls/window/themes/default/window_buttons-ie6.gif +0 -0
  202. data/js/controls/window/themes/default/window_buttons.png +0 -0
  203. data/js/controls/window/themes/default/window_parts1-ie6.gif +0 -0
  204. data/js/controls/window/themes/default/window_parts1.png +0 -0
  205. data/js/controls/window/themes/default/window_parts2-ie6.gif +0 -0
  206. data/js/controls/window/themes/default/window_parts2.png +0 -0
  207. data/js/controls/window/window.js +284 -0
  208. data/js/core/class/class.js +317 -0
  209. data/js/core/class/js.inc +0 -0
  210. data/js/core/elem/elem.js +1376 -0
  211. data/js/core/elem/js.inc +0 -0
  212. data/js/core/event/event.js +1021 -0
  213. data/js/core/event/js.inc +0 -0
  214. data/js/core/iefix/ie_css_element.htc +5 -0
  215. data/js/core/iefix/ie_css_style.htc +5 -0
  216. data/js/core/iefix/iefix.js +359 -0
  217. data/js/core/iefix/js.inc +0 -0
  218. data/js/debugg/debugg.js +43 -0
  219. data/js/debugg/js.inc +0 -0
  220. data/js/foundation/application/application.js +209 -0
  221. data/js/foundation/application/js.inc +0 -0
  222. data/js/foundation/control/control.js +342 -0
  223. data/js/foundation/control/controldefaults/controldefaults.js +59 -0
  224. data/js/foundation/control/controldefaults/js.inc +0 -0
  225. data/js/foundation/control/dummyvalue/dummyvalue.js +50 -0
  226. data/js/foundation/control/dummyvalue/js.inc +0 -0
  227. data/js/foundation/control/dyncontrol/dyncontrol.js +494 -0
  228. data/js/foundation/control/dyncontrol/js.inc +0 -0
  229. data/js/foundation/control/dyncontrol/themes/default/dyncontrol.css +0 -0
  230. data/js/foundation/control/dyncontrol/themes/default/dyncontrol.html +0 -0
  231. data/js/foundation/control/eventresponder/eventresponder.js +713 -0
  232. data/js/foundation/control/eventresponder/js.inc +0 -0
  233. data/js/foundation/control/js.inc +0 -0
  234. data/js/foundation/control/valueresponder/js.inc +0 -0
  235. data/js/foundation/control/valueresponder/valueresponder.js +77 -0
  236. data/js/foundation/geom/point/js.inc +0 -0
  237. data/js/foundation/geom/point/point.js +202 -0
  238. data/js/foundation/geom/rect/js.inc +0 -0
  239. data/js/foundation/geom/rect/rect.js +610 -0
  240. data/js/foundation/json_renderer/js.inc +0 -0
  241. data/js/foundation/json_renderer/json_renderer.js +231 -0
  242. data/js/foundation/system/js.inc +0 -0
  243. data/js/foundation/system/system.js +369 -0
  244. data/js/foundation/thememanager/js.inc +0 -0
  245. data/js/foundation/thememanager/thememanager.js +387 -0
  246. data/js/foundation/view/js.inc +0 -0
  247. data/js/foundation/view/markupview/js.inc +0 -0
  248. data/js/foundation/view/markupview/markupview.js +113 -0
  249. data/js/foundation/view/morphanimation/js.inc +0 -0
  250. data/js/foundation/view/morphanimation/morphanimation.js +236 -0
  251. data/js/foundation/view/view.js +1804 -0
  252. data/js/foundation/view/viewdefaults/js.inc +0 -0
  253. data/js/foundation/view/viewdefaults/viewdefaults.js +25 -0
  254. data/js/views/centerview/centerview.js +45 -0
  255. data/js/views/centerview/js.inc +0 -0
  256. data/js/views/inlineview/inlineview.js +14 -0
  257. data/js/views/inlineview/js.inc +0 -0
  258. data/js/views/scrollview/js.inc +0 -0
  259. data/js/views/scrollview/scrollview.js +39 -0
  260. data/lib/conf/default.rb +220 -0
  261. data/lib/conf/wizard.rb +303 -0
  262. data/lib/daemon/daemon.rb +293 -0
  263. data/lib/http/broker.rb +102 -0
  264. data/lib/http/rackup.rb +88 -0
  265. data/lib/http/request.rb +69 -0
  266. data/lib/http/response.rb +63 -0
  267. data/lib/plugins/gui_plugin.rb +129 -0
  268. data/lib/plugins/guiparser.rb +114 -0
  269. data/lib/plugins/plugin.rb +652 -0
  270. data/lib/plugins/plugin_plugins.rb +47 -0
  271. data/lib/plugins/plugin_sqlite_db.rb +72 -0
  272. data/lib/plugins/plugin_util.rb +96 -0
  273. data/lib/plugins/pluginmanager.rb +517 -0
  274. data/lib/plugins/servlet.rb +69 -0
  275. data/lib/session/msg.rb +291 -0
  276. data/lib/session/sessionmanager.rb +491 -0
  277. data/lib/session/sessionstorage.rb +314 -0
  278. data/lib/transporter/transporter.rb +254 -0
  279. data/lib/util/gzstring.rb +5 -0
  280. data/lib/values/hvalue.rb +323 -0
  281. data/lib/values/valuemanager.rb +152 -0
  282. data/plugins/client_pkg/client_pkg.rb +186 -0
  283. data/plugins/client_pkg/info.yaml +25 -0
  284. data/plugins/client_pkg/lib/client_pkg_build.rb +569 -0
  285. data/plugins/client_pkg/lib/client_pkg_cache.rb +50 -0
  286. data/plugins/client_pkg/lib/client_pkg_serve.rb +210 -0
  287. data/plugins/client_pkg/log/build_log +0 -0
  288. data/plugins/index_html/img/loading.gif +0 -0
  289. data/plugins/index_html/img/riassence.gif +0 -0
  290. data/plugins/index_html/index_html.rb +150 -0
  291. data/plugins/index_html/tmpl/index.html +22 -0
  292. data/plugins/index_html/tmpl/startup_index.html +29 -0
  293. data/plugins/legacy/disabled +0 -0
  294. data/plugins/legacy/disabled- +0 -0
  295. data/plugins/legacy/info.yaml +22 -0
  296. data/plugins/legacy/legacy.rb +15 -0
  297. data/plugins/main/js/riassence_ns.js +87 -0
  298. data/plugins/main/main.rb +234 -0
  299. data/plugins/main/values.yaml +8 -0
  300. data/plugins/ticketservices/lib/common.rb +300 -0
  301. data/plugins/ticketservices/lib/favicon.rb +38 -0
  302. data/plugins/ticketservices/lib/file.rb +58 -0
  303. data/plugins/ticketservices/lib/img.rb +50 -0
  304. data/plugins/ticketservices/lib/objblob.rb +66 -0
  305. data/plugins/ticketservices/lib/rsrc.rb +34 -0
  306. data/plugins/ticketservices/lib/upload.rb +206 -0
  307. data/plugins/ticketservices/ticketservices.rb +268 -0
  308. data/var/db/.git_include +0 -0
  309. data/var/log/.git_include +0 -0
  310. data/var/run/.git_include +0 -0
  311. metadata +390 -0
@@ -0,0 +1,47 @@
1
+ ## Riassence Framework
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
+ ## Interface to enable plugins in a plugin. Just include this in your subclass of Plugin.
10
+ module PluginPlugins
11
+ def init
12
+ super
13
+ @plugin_plugins = RSence::PluginManager.new( [ bundle_path('plugins') ] )
14
+ end
15
+ def open
16
+ super
17
+ @plugin_plugins.delegate(:open)
18
+ end
19
+ def close
20
+ super
21
+ @plugin_plugins.delegate(:close)
22
+ end
23
+ def flush
24
+ super
25
+ @plugin_plugins.delegate(:flush)
26
+ end
27
+ def idle( msg )
28
+ super
29
+ @plugin_plugins.delegate(:idle,msg)
30
+ end
31
+ def init_ses( msg )
32
+ super
33
+ @plugin_plugins.delegate(:init_ses,msg)
34
+ end
35
+ def restore_ses( msg )
36
+ super
37
+ @plugin_plugins.delegate(:restore_ses,msg)
38
+ end
39
+ def cloned_target( msg, source_session )
40
+ super
41
+ @plugin_plugins.delegate(:cloned_target,msg,source_session)
42
+ end
43
+ def cloned_source( msg, target_session )
44
+ super
45
+ @plugin_plugins.delegate(:cloned_source,msg,target_session)
46
+ end
47
+ end
@@ -0,0 +1,72 @@
1
+ ## Riassence Framework
2
+ # Copyright 2009 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
+ # Include this module in your plugin class to automatically
10
+ # create and connect/disconnect an sqllite database.
11
+ # The plugin instance will have a @db Sequel object refering
12
+ # to the sqlite database automatically created
13
+ module PluginSqliteDB
14
+
15
+ # First calls superclass, then creates database directory and database.
16
+ # Then calls init_db_tables.
17
+ def init
18
+ super
19
+ db_dir = File.join( @path, 'db' )
20
+ unless File.directory?( db_dir )
21
+ Dir.mkdir( db_dir )
22
+ end
23
+ @db_path = File.join( db_dir, "#{@name}.db" )
24
+ unless File.exist?( @db_path )
25
+ @db = Sequel.sqlite( @db_path )
26
+ create_db_tables
27
+ @db.disconnect
28
+ end
29
+
30
+ end
31
+
32
+ # Automatically opens the database connection, then calls update_db.
33
+ def open
34
+ @db = Sequel.sqlite( @db_path )
35
+ update_db
36
+ super
37
+ end
38
+
39
+ # Automatically closes (disconnects) the database. Calls flush_db before closing.
40
+ def close
41
+ flush_db
42
+ @db.disconnect
43
+ super
44
+ end
45
+
46
+ # Extend this method to do something immediately after the @db object is assigned.
47
+ # An usage scenario would be updating some tables or deleting some junk rows.
48
+ def update_db
49
+ end
50
+
51
+ # Extend this method to do something immediately before the @db object is disconnected.
52
+ # An usage scenario would be deleting some junk rows or writing some pending data in memory into the database.
53
+ def flush_db
54
+ end
55
+
56
+ # Extend this method to define tables or initial data for the tables.
57
+ # It's called once, when the database is created.
58
+ #
59
+ # NOTE: In a future reversion, tables might be defined from a configuration file.
60
+ #
61
+ # = Usage:
62
+ # @db.create_table :my_table do
63
+ # primary_key :id
64
+ # String :my_text_column
65
+ # end
66
+ # my_table = @db[:my_table]
67
+ # my_table.insert(:my_text_column => 'Some text')
68
+ #
69
+ def create_db_tables
70
+ end
71
+ end
72
+
@@ -0,0 +1,96 @@
1
+
2
+ module PluginUtil
3
+
4
+ include RSence
5
+
6
+ # Extend to do any initial configuration. Not doing anything by default.
7
+ def init
8
+ end
9
+
10
+ # Extend this method to open objects like streams and database connections.
11
+ # It is called when everything is constructed after all plugins are loaded.
12
+ def open
13
+ end
14
+
15
+ # Extend to save your plugin state or store any data that needs to be
16
+ # persistent. It's always called before close, but doesn't necessarily mean
17
+ # a close call is imminent.
18
+ def flush
19
+ end
20
+
21
+ # Extend this method to close objects like streams and database connections.
22
+ # It's called when plugins are about to be destructed, so don't expect any
23
+ # calls after it has been called. When this method is called, it's the last
24
+ # chance to save persistent data before being destructed, so implement
25
+ # the +#flush+ method for primarily storing data.
26
+ def close
27
+ end
28
+
29
+ # Returns the contents of the file given as +path+.
30
+ #
31
+ # The plugin bundle's path is used as the prefix, unless +path+ starts with '/' or '..'
32
+ #
33
+ # If the file doesn't exist, it returns +false+.
34
+ def file_read( path )
35
+ path = bundle_path( path )
36
+ return false unless File.exist?( path )
37
+ return File.read( path )
38
+ end
39
+
40
+ def yaml_read( path )
41
+ file_data = file_read( path )
42
+ if not file_data
43
+ return false
44
+ else
45
+ return YAML.load( file_data )
46
+ end
47
+ end
48
+
49
+ def method_undefined?( *args )
50
+ puts "Method undefined: #{args.inspect}"
51
+ end
52
+
53
+ # Writes the +data+ into the file +path+.
54
+ #
55
+ # The plugin bundle's path is used as the prefix, unless +path+ starts with '/' or '..'
56
+ #
57
+ # It returns a success code (+false+ for failure and +true+ for success).
58
+ def file_write( path, data )
59
+ path = bundle_path( path )
60
+ begin
61
+ datafile = File.open( path, 'wb' )
62
+ datafile.write( data )
63
+ datafile.close
64
+ return true
65
+ rescue => e
66
+ warn "file_write error for path #{path} #{e}"
67
+ return false
68
+ end
69
+ end
70
+ alias file_save file_write
71
+
72
+ # Makes a full path using the plugin bundle as the 'local path'.
73
+ # The (optional) +prefix+ is a subdirectory in the bundle,
74
+ # the +suffix+ is the file extension.
75
+ def bundle_path( path, prefix=false, suffix=false )
76
+ if suffix
77
+ path = "#{path}#{suffix}" unless path.end_with?(suffix)
78
+ end
79
+ if prefix
80
+ path = File.join( prefix, path )
81
+ end
82
+ if path[0].chr != '/' and path[0..1] != '..'
83
+ path = File.join( @path, path )
84
+ end
85
+ return path
86
+ end
87
+
88
+ alias compose_plugin_path bundle_path
89
+
90
+ # Helper method to return the time formatted according to the HTTP RFC
91
+ def httime(time=false)
92
+ time = Time.new unless time
93
+ return time.gmtime.strftime('%a, %d %b %Y %H:%M:%S %Z')
94
+ end
95
+
96
+ end
@@ -0,0 +1,517 @@
1
+ ## Riassence Framework
2
+ # Copyright 2006 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
+
10
+ def bundle_loader( params )
11
+ src_path = params[:src_path]
12
+ mod = Module.new do |m|
13
+ @@bundle_path = params[:bundle_path ]
14
+ @@bundle_name = params[:bundle_name ]
15
+ @@bundle_info = params[:bundle_info ]
16
+ @@plugin_manager = params[:plugin_manager]
17
+ begin
18
+ if params[:bundle_info][:inits_self] == false
19
+ m::module_eval( File.read(src_path) )
20
+ elsif params[:bundle_info][:reloadable] == false
21
+ require src_path[0..-4]
22
+ else
23
+ load src_path
24
+ end
25
+ rescue => e
26
+ @@plugin_manager.plugin_error(
27
+ e,
28
+ 'BundleLoaderError',
29
+ "An error occurred while loading the plugin bundle #{@@bundle_name}.",
30
+ @@bundle_path
31
+ )
32
+ end
33
+ end
34
+ return mod
35
+ end
36
+
37
+
38
+ module RSence
39
+
40
+ # Contains the PluginUtil module which has common methods for the bundle classes
41
+ require 'plugins/plugin_util'
42
+
43
+ # plugin.rb contains the Plugin skeleton class
44
+ require 'plugins/plugin'
45
+
46
+ # guiparser.rb contains the Yaml serializer for gui trees.
47
+ # It uses JSONRenderer on the client to build user interfaces.
48
+ require 'plugins/guiparser'
49
+
50
+ # gui_plugin.rb is an extension of Plugin that uses
51
+ # GUIParser to init the gui automatically.
52
+ require 'plugins/gui_plugin'
53
+
54
+ # plugin_sqlite_db.rb contains automatic local sqlite database
55
+ # creation for a plugin that includes it.
56
+ require 'plugins/plugin_sqlite_db'
57
+
58
+ # servlet includes the Servlet class, for handling any requests / responses
59
+ require 'plugins/servlet'
60
+
61
+ # Interface for plugins in a plugin bundle
62
+ require 'plugins/plugin_plugins'
63
+
64
+ ## = Abstract
65
+ ## PluginManager is the service that loads and provides method delegation
66
+ ## amongst all installed plugins.
67
+ ##
68
+ ## = Usage
69
+ ## plugin_paths = [ 'plugins', '/home/me/rsence/plugins' ]
70
+ ## myPluginManager = RSence::PluginManager.new( plugin_paths )
71
+ ##
72
+ class PluginManager
73
+
74
+ attr_reader :transporter, :sessions
75
+
76
+ # Initialize with a list of directories as plugin_paths.
77
+ # It's an array containing all plugin directories to scan.
78
+ def initialize( plugin_paths, transporter=nil, autoreload=false )
79
+ if transporter
80
+ @transporter = transporter
81
+ @sessions = transporter.sessions
82
+ end
83
+ @plugin_paths = plugin_paths
84
+ puts "Loading plugins..."
85
+ scan_plugins
86
+ puts "Plugins loaded."
87
+ puts "Riassence Framework is online."
88
+ if autoreload
89
+ @thr = Thread.new do
90
+ Thread.pass
91
+ while true
92
+ begin
93
+ changed_plugins!
94
+ rescue => e
95
+ warn e.inspect
96
+ end
97
+ sleep 3
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ def method_missing( sym, *args, &block )
104
+ if @registry.has_key?(sym)
105
+ if args == [] and block == nil
106
+ return @registry[sym]
107
+ elsif block == nil
108
+ call( sym, *args )
109
+ end
110
+ end
111
+ end
112
+
113
+ def changed_plugins!
114
+ @plugin_paths.each do |path|
115
+ next unless File.directory? path
116
+ Dir.entries(path).each do |bundle_name|
117
+ next if bundle_name =~ /&\./
118
+ bundle_path = File.expand_path( File.join( path, bundle_name ) )
119
+ next unless File.directory?( bundle_path )
120
+ bundle_file = bundle_name+'.rb'
121
+ next unless File.exists?( File.join( bundle_path, bundle_file ) )
122
+ if File.exists?( File.join( bundle_path, 'disabled' ) )
123
+ if @registry.has_key?( bundle_name.to_sym )
124
+ puts "Disabling bundle #{bundle_name}..."
125
+ unload_bundle( bundle_name.to_sym )
126
+ if ARGV.include?('-say')
127
+ Thread.new do
128
+ Thread.pass
129
+ system(%{say "Unloaded #{bundle_name.to_s}."})
130
+ end
131
+ end
132
+ end
133
+ else
134
+ if not @registry.has_key?( bundle_name.to_sym )
135
+ puts "Loading bundle #{bundle_name}..."
136
+ load_bundle( bundle_path, bundle_name.to_sym, bundle_name+'.rb' )
137
+ call( bundle_name.to_sym, :open )
138
+ if ARGV.include?('-say')
139
+ Thread.new do
140
+ Thread.pass
141
+ system(%{say "Loaded #{bundle_name.to_s}."})
142
+ end
143
+ end
144
+ else
145
+ # puts "Checking if bundle #{bundle_name} is changed..."
146
+ info = @info[bundle_name.to_sym]
147
+ if info[:reloadable] and plugin_changed?( bundle_name.to_sym )
148
+ puts "Bundle #{bundle_name} has changed, reloading..."
149
+ unload_bundle( bundle_name.to_sym )
150
+ load_bundle( bundle_path, bundle_name.to_sym, bundle_name+'.rb' )
151
+ call( bundle_name.to_sym, :open )
152
+ if ARGV.include?('-say')
153
+ Thread.new do
154
+ Thread.pass
155
+ system(%{say "Reloaded #{bundle_name.to_s}."})
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
164
+
165
+ def unload_bundle( bundle_name )
166
+ if @registry.has_key?( bundle_name )
167
+ call( bundle_name, :flush )
168
+ call( bundle_name, :close )
169
+ @registry.delete( bundle_name )
170
+ @aliases.each do |a_name,b_name|
171
+ if b_name == bundle_name
172
+ @aliases.delete( a_name )
173
+ end
174
+ end
175
+ if @servlets.include?( bundle_name )
176
+ @servlets.delete( bundle_name )
177
+ end
178
+ if @info.include?( bundle_name )
179
+ @info.delete( bundle_name )
180
+ end
181
+ end
182
+ end
183
+
184
+ def plugin_changed?( plugin_name )
185
+ info = @info[plugin_name]
186
+ last_changed = info[:last_changed]
187
+ newest_change = most_recent( info[:path], last_changed )
188
+ return last_changed < newest_change
189
+ end
190
+
191
+ # Top-level method for scanning all plugin directories.
192
+ # Clears previously loaded plugins.
193
+ def scan_plugins
194
+ @registry = {}
195
+ @info = {}
196
+ @aliases = {}
197
+ @servlets = []
198
+ # @types = {
199
+ # :gui => [],
200
+ # :plugin => [],
201
+ # :servlet => []
202
+ # }
203
+ @plugin_paths.each do |path|
204
+ next unless File.directory? path
205
+ scan_plugindir( path )
206
+ end
207
+ delegate( :open )
208
+ end
209
+
210
+ def registry( plugin_name )
211
+ return @registry[ plugin_name ]
212
+ end
213
+ alias [] registry
214
+
215
+ # Scans a directory of plugins, calls +load_plugin+ for bundles that match
216
+ # the definition of a plugin bundle.
217
+ # - Skips bundles starting with a dot
218
+ # - Skips bundles without a ruby source file with the same
219
+ # name as the directory (plus '.rb').
220
+ # - Skips bundles containing a file or directory named 'disabled'
221
+ def scan_plugindir( path )
222
+ Dir.entries(path).each do |bundle_name|
223
+ # puts "bundle_name: #{bundle_name}"
224
+ next if bundle_name[0].chr == '.'
225
+ bundle_path = File.expand_path( File.join( path, bundle_name ) )
226
+ # puts "#{File.stat(bundle_path).inspect}"
227
+ next unless File.directory?( bundle_path )
228
+ bundle_file = bundle_name+'.rb'
229
+ if not File.exists?( File.join( bundle_path, bundle_file ) )
230
+ bundle_file = 'main.rb'
231
+ next unless File.exists?( File.join( bundle_path, bundle_file ) )
232
+ end
233
+ next if File.exists?( File.join( bundle_path, 'disabled' ) )
234
+
235
+ load_bundle( bundle_path, bundle_name.to_sym, bundle_file )
236
+ end
237
+ end
238
+
239
+ # Finds the most recent file in the path
240
+ def most_recent( bundle_path, newest_date=0 )
241
+ path_date = File.stat( bundle_path ).mtime.to_i
242
+ is_dir = File.directory?( bundle_path )
243
+ if path_date > newest_date and not is_dir
244
+ # puts "File is newer: #{bundle_path}"
245
+ newest_date = path_date
246
+ end
247
+ if is_dir
248
+ Dir.entries( bundle_path ).each do |entry_name|
249
+ next if entry_name[0].chr == '.'
250
+ full_path = File.join( bundle_path, entry_name )
251
+ unless File.directory?( full_path )
252
+ next unless entry_name.include?('.') and ['yaml','rb'].include?( entry_name.split('.')[-1] )
253
+ end
254
+ newest_date = most_recent( full_path, newest_date )
255
+ end
256
+ end
257
+ return newest_date
258
+ end
259
+
260
+ # Gets plugin information
261
+ def bundle_info( bundle_path )
262
+
263
+ bundle_name = File.split( bundle_path )[1]
264
+
265
+ # Default bundle information
266
+ info = {
267
+ # The human-readable product name of the package
268
+ :title => bundle_name.capitalize,
269
+
270
+ # The human-readable version of the package
271
+ :version => '0.0.0',
272
+
273
+ # A brief description of the package (rdoc formatting supported)
274
+ :description => 'No Description given',
275
+
276
+ # A flag (when false) prevents the plugin from automatically reload when changed.
277
+ :reloadable => true,
278
+
279
+ # A flag (when false) enables automatic construction
280
+ # of the Plugin and Servlet classes contained.
281
+ :inits_self => true,
282
+
283
+ # System version requirement.
284
+ :sys_version => '>= 1.0.0',
285
+
286
+ # Path to bundle
287
+ :path => bundle_path,
288
+
289
+ # Name of bundle
290
+ :name => bundle_name.to_sym,
291
+
292
+ # Last change
293
+ :last_changed => most_recent( bundle_path )
294
+
295
+ }
296
+
297
+ info_path = File.join( bundle_path, 'info.yaml' )
298
+ if File.exists?( info_path )
299
+ info_yaml = YAML.load( File.read( info_path ) )
300
+ info_yaml.each do |info_key,info_value|
301
+ info[ info_key.to_sym ] = info_value
302
+ end
303
+ end
304
+ return info
305
+
306
+ end
307
+
308
+ # Loads a plugin bundle.
309
+ def load_bundle( bundle_path, bundle_name, bundle_file )
310
+
311
+ if @registry.has_key?( bundle_name.to_sym )
312
+ warn "Warning: Bundle #{bundle_name} already loaded."
313
+ return
314
+ end
315
+
316
+ bundle_file_path = File.join( bundle_path, bundle_file )
317
+
318
+ bundle_info = bundle_info( bundle_path )
319
+
320
+ @info[bundle_name.to_sym] = bundle_info
321
+
322
+ bundle_src = File.read( bundle_file_path )
323
+
324
+ if RUBY_VERSION.to_f >= 1.9
325
+ puts "ruby 1.9.x"
326
+ puts "ruby version: #{RUBY_VERSION.inspect}"
327
+ src_path = bundle_file_path
328
+ plugin_manager = self
329
+ module_ns = Module.new do |m|
330
+ @@bundle_path = bundle_path
331
+ @@bundle_name = bundle_name
332
+ @@bundle_info = bundle_info
333
+ @@plugin_manager = plugin_manager
334
+ def m.bundle_path; @@bundle_path; end
335
+ # puts "using eval"
336
+ # m::module_eval( File.read(src_path) )
337
+ # puts "using require"
338
+ # require src_path[0..-4]
339
+ puts "using load"
340
+ load src_path
341
+ end
342
+ else
343
+ module_ns = bundle_loader( {
344
+ :bundle_path => bundle_path,
345
+ :bundle_name => bundle_name,
346
+ :bundle_info => bundle_info,
347
+ :plugin_manager => self,
348
+ :src_path => bundle_file_path,
349
+ :src => bundle_src
350
+ } )
351
+ end
352
+
353
+ unless bundle_info[:inits_self]
354
+ # puts "#{bundle_name}: #{module_ns.constants.inspect}"
355
+ module_ns.constants.each do |module_const_name|
356
+ module_const = module_ns.const_get( module_const_name )
357
+ if module_const.class == Class
358
+ # puts "is class"
359
+ module_const.ancestors.each do |ancestor|
360
+ # puts "ancestor: #{ancestor.to_s.inspect}"
361
+ if ancestor.to_s == "Servlet"
362
+ module_const.new
363
+ break
364
+ elsif ancestor.to_s == "Plugin"
365
+ puts "bundle_name: #{bundle_name}"
366
+ module_const.new.register( bundle_name )
367
+ break
368
+ elsif ancestor.to_s == "Object"
369
+ puts "Can't init class: #{module_const.to_s}"
370
+ break
371
+ end
372
+ end
373
+ end
374
+ end
375
+ end
376
+ end
377
+
378
+ def register_bundle( inst, bundle_name )
379
+ bundle_name = bundle_name.to_sym
380
+ if @registry.has_key?( bundle_name )
381
+ if registry[ bundle_name ] != inst
382
+ warn "Tried to register a conflicting bundle name: #{bundle_name.inspect}; ignoring"
383
+ else
384
+ warn "Use @plugins.register_alias to register more than one name per plugin."
385
+ register_alias( inst.name.to_sym, bundle_name )
386
+ end
387
+ else
388
+ inst.init if inst.respond_to? :init and not inst.inited
389
+ @registry[ bundle_name ] = inst
390
+ if inst.respond_to?( :match )
391
+ @servlets.push( bundle_name )
392
+ end
393
+ end
394
+ end
395
+
396
+ def register_alias( bundle_name, alias_name )
397
+ if @aliases.has_key?( alias_name.to_sym )
398
+ warn "Alias already taken: #{alias_name.inspect}"
399
+ else
400
+ @aliases[ alias_name ] = bundle_name.to_sym
401
+ end
402
+ end
403
+
404
+ def plugin_error( e, err_location, err_location_descr, eval_repl=false )
405
+ err_msg = [
406
+ "*"*40,
407
+ err_location,
408
+ err_location_descr,
409
+ "#{e.class.to_s}, #{e.message}",
410
+ "Backtrace:",
411
+ "\t"+e.backtrace.join("\n\t"),
412
+ "*"*40
413
+ ].join("\n")+"\n"
414
+ puts
415
+ puts "eval repl: #{eval_repl}"
416
+ puts
417
+ if eval_repl
418
+ err_msg = err_msg.gsub('from (eval):',"from #{eval_repl}:")
419
+ end
420
+ $stderr.write( err_msg )
421
+ end
422
+
423
+ def match_servlet_uri( uri, req_type=:get )
424
+ match_score = {}
425
+ @servlets.each do | servlet_name |
426
+ servlet = @registry[ servlet_name ]
427
+ next unless servlet.respond_to?( req_type )
428
+ begin
429
+ if servlet.match( uri, req_type )
430
+ score = servlet.score
431
+ match_score[ score ] = [] unless match_score.has_key? score
432
+ match_score[ score ].push( servlet_name )
433
+ end
434
+ rescue => e
435
+ plugin_error(
436
+ e,
437
+ "RSence::PluginManager.match_servlet_uri",
438
+ "servlet: #{servlet_name.inspect}, req_type: #{req_type.inspect}, uri: #{uri.inspect}",
439
+ servlet_name
440
+ )
441
+ end
442
+ end
443
+ match_scores = match_score.keys.sort
444
+ if match_scores.empty?
445
+ return false
446
+ else
447
+ matches_order = []
448
+ matches_best = match_score[ match_scores[0] ]
449
+ if matches_best.size > 1
450
+ matches_best = matches_best[ rand( matches_best.size ) ]
451
+ else
452
+ matches_best = matches_best.first
453
+ end
454
+ matches_order.push( matches_best )
455
+ match_score.keys.sort.each do |match_n|
456
+ match_score[ match_n ].each do | match_name |
457
+ matches_order.push( match_name ) unless matches_order.include? match_name
458
+ end
459
+ end
460
+ return matches_order
461
+ end
462
+ end
463
+
464
+ def delegate( method_name, *args )
465
+ @registry.each do | plugin_name, plugin |
466
+ if plugin.respond_to?( method_name )
467
+ plugin.send( method_name, *args )
468
+ end
469
+ end
470
+ end
471
+
472
+ def shutdown
473
+ delegate( :flush )
474
+ delegate( :close )
475
+ end
476
+
477
+ def call( plugin_name, method_name, *args )
478
+ plugin_name = plugin_name.to_sym
479
+ if @registry.has_key?( plugin_name )
480
+ if @registry[ plugin_name ].respond_to?( method_name )
481
+ return @registry[ plugin_name ].send( method_name, *args )
482
+ else
483
+ puts "No method #{method_name.inspect} for plugin #{plugin_name.inspect}"
484
+ return false
485
+ end
486
+ else
487
+ puts "No such plugin: #{plugin_name.inspect}"
488
+ return false
489
+ end
490
+ end
491
+
492
+ alias run_plugin call
493
+
494
+ def match_servlet( req_type, req, resp, session )
495
+ req_uri = req.fullpath
496
+ matches_order = match_servlet_uri( req_uri, req_type )
497
+ return false unless matches_order
498
+ matches_order.each do |servlet_name|
499
+ begin
500
+ @registry[servlet_name].send( req_type, req, resp, session )
501
+ return true
502
+ rescue => e
503
+ plugin_error(
504
+ e,
505
+ "RSence::PluginManager.match_servlet",
506
+ "servlet_name: #{servlet_name.inspect}, req_type: #{req_type.inspect}",
507
+ servlet_name
508
+ )
509
+ next
510
+ end
511
+ end
512
+ return false
513
+ end
514
+
515
+ end
516
+
517
+ end