agent_xmpp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +11 -0
- data/LICENSE +20 -0
- data/README.rdoc +417 -0
- data/Rakefile +75 -0
- data/VERSION +1 -0
- data/agent_xmpp.gemspec +144 -0
- data/lib/agent_xmpp.rb +22 -0
- data/lib/agent_xmpp/admin.rb +113 -0
- data/lib/agent_xmpp/client.rb +7 -0
- data/lib/agent_xmpp/client/boot.rb +83 -0
- data/lib/agent_xmpp/client/client.rb +64 -0
- data/lib/agent_xmpp/client/connection.rb +108 -0
- data/lib/agent_xmpp/client/controller.rb +394 -0
- data/lib/agent_xmpp/client/message_delegate.rb +720 -0
- data/lib/agent_xmpp/client/message_pipe.rb +193 -0
- data/lib/agent_xmpp/client/response.rb +102 -0
- data/lib/agent_xmpp/config.rb +48 -0
- data/lib/agent_xmpp/main.rb +175 -0
- data/lib/agent_xmpp/models.rb +7 -0
- data/lib/agent_xmpp/models/contact.rb +85 -0
- data/lib/agent_xmpp/models/message.rb +152 -0
- data/lib/agent_xmpp/models/publication.rb +53 -0
- data/lib/agent_xmpp/models/roster.rb +107 -0
- data/lib/agent_xmpp/models/service.rb +91 -0
- data/lib/agent_xmpp/models/subscription.rb +61 -0
- data/lib/agent_xmpp/models/table_definitions.rb +107 -0
- data/lib/agent_xmpp/patches.rb +7 -0
- data/lib/agent_xmpp/patches/array.rb +32 -0
- data/lib/agent_xmpp/patches/float.rb +10 -0
- data/lib/agent_xmpp/patches/hash.rb +13 -0
- data/lib/agent_xmpp/patches/object.rb +15 -0
- data/lib/agent_xmpp/patches/rexml.rb +69 -0
- data/lib/agent_xmpp/patches/string.rb +15 -0
- data/lib/agent_xmpp/xmpp.rb +18 -0
- data/lib/agent_xmpp/xmpp/element.rb +158 -0
- data/lib/agent_xmpp/xmpp/entry.rb +36 -0
- data/lib/agent_xmpp/xmpp/error_response.rb +189 -0
- data/lib/agent_xmpp/xmpp/iq.rb +90 -0
- data/lib/agent_xmpp/xmpp/iq_command.rb +54 -0
- data/lib/agent_xmpp/xmpp/iq_disco.rb +206 -0
- data/lib/agent_xmpp/xmpp/iq_pubsub.rb +270 -0
- data/lib/agent_xmpp/xmpp/iq_roster.rb +183 -0
- data/lib/agent_xmpp/xmpp/iq_version.rb +89 -0
- data/lib/agent_xmpp/xmpp/jid.rb +150 -0
- data/lib/agent_xmpp/xmpp/message.rb +82 -0
- data/lib/agent_xmpp/xmpp/presence.rb +127 -0
- data/lib/agent_xmpp/xmpp/sasl.rb +241 -0
- data/lib/agent_xmpp/xmpp/stanza.rb +107 -0
- data/lib/agent_xmpp/xmpp/x_data.rb +357 -0
- data/test/app/app.rb +339 -0
- data/test/cases/test_application_message_processing.rb +65 -0
- data/test/cases/test_errors.rb +24 -0
- data/test/cases/test_presence_management.rb +139 -0
- data/test/cases/test_roster_management.rb +214 -0
- data/test/cases/test_service_discovery.rb +168 -0
- data/test/cases/test_session_management.rb +120 -0
- data/test/cases/test_version_discovery.rb +67 -0
- data/test/helpers/matchers.rb +23 -0
- data/test/helpers/mocks.rb +82 -0
- data/test/helpers/test_case_extensions.rb +45 -0
- data/test/helpers/test_client.rb +44 -0
- data/test/helpers/test_delegate.rb +60 -0
- data/test/helpers/test_helper.rb +91 -0
- data/test/messages/application_messages.rb +206 -0
- data/test/messages/error_messages.rb +35 -0
- data/test/messages/presence_messages.rb +66 -0
- data/test/messages/roster_messages.rb +126 -0
- data/test/messages/service_discovery_messages.rb +201 -0
- data/test/messages/session_messages.rb +158 -0
- data/test/messages/version_discovery_messages.rb +69 -0
- data/test/peer/peer.rb +21 -0
- metadata +187 -0
data/Rakefile
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
############################################################################################################
|
2
|
+
$:.unshift('lib')
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'agent_xmpp/config'
|
6
|
+
|
7
|
+
#####-------------------------------------------------------------------------------------------------------
|
8
|
+
task :default => :test
|
9
|
+
|
10
|
+
#####-------------------------------------------------------------------------------------------------------
|
11
|
+
begin
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
gem.name = "agent_xmpp"
|
15
|
+
gem.summary = %Q{Agent XMPP is a ruby XMPP bot framework inspired by MVC web frameworks.}
|
16
|
+
gem.email = "troy.stribling@gmail.com"
|
17
|
+
gem.homepage = "http://github.com/troystribling/agent_xmpp"
|
18
|
+
gem.authors = ["Troy Stribling"]
|
19
|
+
gem.files.include %w(lib/jeweler/templates/.gitignore VERSION)
|
20
|
+
gem.add_dependency('rake', '>= 0.8.3')
|
21
|
+
gem.add_dependency('eventmachine', '>= 0.12.6')
|
22
|
+
gem.add_dependency('sequel', '>= 3.9.0')
|
23
|
+
gem.add_dependency('evma_xmlpushparser', '>= 0.0.1')
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
abort "jeweler is not available. In order to run test, you must: sudo gem install technicalpickles-jeweler --source=http://gems.github.com"
|
27
|
+
end
|
28
|
+
|
29
|
+
#####-------------------------------------------------------------------------------------------------------
|
30
|
+
task :uninstall do
|
31
|
+
%x[gem uninstall agent_xmpp]
|
32
|
+
end
|
33
|
+
|
34
|
+
#####-------------------------------------------------------------------------------------------------------
|
35
|
+
task :default => [:test]
|
36
|
+
|
37
|
+
#####-------------------------------------------------------------------------------------------------------
|
38
|
+
require 'rake/testtask'
|
39
|
+
Rake::TestTask.new(:test) do |test|
|
40
|
+
test.libs << ['test/cases', 'test/helpers', 'test/messages']
|
41
|
+
test.pattern = 'test/cases/**/test_*.rb'
|
42
|
+
test.verbose = true
|
43
|
+
end
|
44
|
+
|
45
|
+
#####-------------------------------------------------------------------------------------------------------
|
46
|
+
Rake::TestTask.new(:test_case) do |test|
|
47
|
+
file = ENV["FILE"] || ''
|
48
|
+
test.libs << ['test/cases', 'test/helpers', 'test/messages']
|
49
|
+
test.test_files = ["test/cases/#{file}"]
|
50
|
+
test.verbose = true
|
51
|
+
end
|
52
|
+
|
53
|
+
#####-------------------------------------------------------------------------------------------------------
|
54
|
+
begin
|
55
|
+
require 'rcov/rcovtask'
|
56
|
+
Rcov::RcovTask.new do |test|
|
57
|
+
test.libs << 'test'
|
58
|
+
test.pattern = 'test/**/test_*.rb'
|
59
|
+
test.verbose = true
|
60
|
+
end
|
61
|
+
rescue LoadError
|
62
|
+
task :rcov do
|
63
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov --source=http://gems.github.com"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
#####-------------------------------------------------------------------------------------------------------
|
68
|
+
require 'rake/rdoctask'
|
69
|
+
Rake::RDocTask.new do |rdoc|
|
70
|
+
rdoc.rdoc_dir = 'rdoc'
|
71
|
+
rdoc.title = "agent_xmpp #{AgentXmpp::VERSION}"
|
72
|
+
rdoc.rdoc_files.include('README*')
|
73
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
74
|
+
end
|
75
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/agent_xmpp.gemspec
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{agent_xmpp}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Troy Stribling"]
|
12
|
+
s.date = %q{2010-08-21}
|
13
|
+
s.email = %q{troy.stribling@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"agent_xmpp.gemspec",
|
26
|
+
"lib/agent_xmpp.rb",
|
27
|
+
"lib/agent_xmpp/admin.rb",
|
28
|
+
"lib/agent_xmpp/client.rb",
|
29
|
+
"lib/agent_xmpp/client/boot.rb",
|
30
|
+
"lib/agent_xmpp/client/client.rb",
|
31
|
+
"lib/agent_xmpp/client/connection.rb",
|
32
|
+
"lib/agent_xmpp/client/controller.rb",
|
33
|
+
"lib/agent_xmpp/client/message_delegate.rb",
|
34
|
+
"lib/agent_xmpp/client/message_pipe.rb",
|
35
|
+
"lib/agent_xmpp/client/response.rb",
|
36
|
+
"lib/agent_xmpp/config.rb",
|
37
|
+
"lib/agent_xmpp/main.rb",
|
38
|
+
"lib/agent_xmpp/models.rb",
|
39
|
+
"lib/agent_xmpp/models/contact.rb",
|
40
|
+
"lib/agent_xmpp/models/message.rb",
|
41
|
+
"lib/agent_xmpp/models/publication.rb",
|
42
|
+
"lib/agent_xmpp/models/roster.rb",
|
43
|
+
"lib/agent_xmpp/models/service.rb",
|
44
|
+
"lib/agent_xmpp/models/subscription.rb",
|
45
|
+
"lib/agent_xmpp/models/table_definitions.rb",
|
46
|
+
"lib/agent_xmpp/patches.rb",
|
47
|
+
"lib/agent_xmpp/patches/array.rb",
|
48
|
+
"lib/agent_xmpp/patches/float.rb",
|
49
|
+
"lib/agent_xmpp/patches/hash.rb",
|
50
|
+
"lib/agent_xmpp/patches/object.rb",
|
51
|
+
"lib/agent_xmpp/patches/rexml.rb",
|
52
|
+
"lib/agent_xmpp/patches/string.rb",
|
53
|
+
"lib/agent_xmpp/xmpp.rb",
|
54
|
+
"lib/agent_xmpp/xmpp/element.rb",
|
55
|
+
"lib/agent_xmpp/xmpp/entry.rb",
|
56
|
+
"lib/agent_xmpp/xmpp/error_response.rb",
|
57
|
+
"lib/agent_xmpp/xmpp/iq.rb",
|
58
|
+
"lib/agent_xmpp/xmpp/iq_command.rb",
|
59
|
+
"lib/agent_xmpp/xmpp/iq_disco.rb",
|
60
|
+
"lib/agent_xmpp/xmpp/iq_pubsub.rb",
|
61
|
+
"lib/agent_xmpp/xmpp/iq_roster.rb",
|
62
|
+
"lib/agent_xmpp/xmpp/iq_version.rb",
|
63
|
+
"lib/agent_xmpp/xmpp/jid.rb",
|
64
|
+
"lib/agent_xmpp/xmpp/message.rb",
|
65
|
+
"lib/agent_xmpp/xmpp/presence.rb",
|
66
|
+
"lib/agent_xmpp/xmpp/sasl.rb",
|
67
|
+
"lib/agent_xmpp/xmpp/stanza.rb",
|
68
|
+
"lib/agent_xmpp/xmpp/x_data.rb",
|
69
|
+
"test/app/app.rb",
|
70
|
+
"test/cases/test_application_message_processing.rb",
|
71
|
+
"test/cases/test_errors.rb",
|
72
|
+
"test/cases/test_presence_management.rb",
|
73
|
+
"test/cases/test_roster_management.rb",
|
74
|
+
"test/cases/test_service_discovery.rb",
|
75
|
+
"test/cases/test_session_management.rb",
|
76
|
+
"test/cases/test_version_discovery.rb",
|
77
|
+
"test/helpers/matchers.rb",
|
78
|
+
"test/helpers/mocks.rb",
|
79
|
+
"test/helpers/test_case_extensions.rb",
|
80
|
+
"test/helpers/test_client.rb",
|
81
|
+
"test/helpers/test_delegate.rb",
|
82
|
+
"test/helpers/test_helper.rb",
|
83
|
+
"test/messages/application_messages.rb",
|
84
|
+
"test/messages/error_messages.rb",
|
85
|
+
"test/messages/presence_messages.rb",
|
86
|
+
"test/messages/roster_messages.rb",
|
87
|
+
"test/messages/service_discovery_messages.rb",
|
88
|
+
"test/messages/session_messages.rb",
|
89
|
+
"test/messages/version_discovery_messages.rb",
|
90
|
+
"test/peer/peer.rb"
|
91
|
+
]
|
92
|
+
s.homepage = %q{http://github.com/troystribling/agent_xmpp}
|
93
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
94
|
+
s.require_paths = ["lib"]
|
95
|
+
s.rubygems_version = %q{1.3.5}
|
96
|
+
s.summary = %q{Agent XMPP is a ruby XMPP bot framework inspired by MVC web frameworks.}
|
97
|
+
s.test_files = [
|
98
|
+
"test/app/app.rb",
|
99
|
+
"test/cases/test_application_message_processing.rb",
|
100
|
+
"test/cases/test_errors.rb",
|
101
|
+
"test/cases/test_presence_management.rb",
|
102
|
+
"test/cases/test_roster_management.rb",
|
103
|
+
"test/cases/test_service_discovery.rb",
|
104
|
+
"test/cases/test_session_management.rb",
|
105
|
+
"test/cases/test_version_discovery.rb",
|
106
|
+
"test/helpers/matchers.rb",
|
107
|
+
"test/helpers/mocks.rb",
|
108
|
+
"test/helpers/test_case_extensions.rb",
|
109
|
+
"test/helpers/test_client.rb",
|
110
|
+
"test/helpers/test_delegate.rb",
|
111
|
+
"test/helpers/test_helper.rb",
|
112
|
+
"test/messages/application_messages.rb",
|
113
|
+
"test/messages/error_messages.rb",
|
114
|
+
"test/messages/presence_messages.rb",
|
115
|
+
"test/messages/roster_messages.rb",
|
116
|
+
"test/messages/service_discovery_messages.rb",
|
117
|
+
"test/messages/session_messages.rb",
|
118
|
+
"test/messages/version_discovery_messages.rb",
|
119
|
+
"test/peer/peer.rb"
|
120
|
+
]
|
121
|
+
|
122
|
+
if s.respond_to? :specification_version then
|
123
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
124
|
+
s.specification_version = 3
|
125
|
+
|
126
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
127
|
+
s.add_runtime_dependency(%q<rake>, [">= 0.8.3"])
|
128
|
+
s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.6"])
|
129
|
+
s.add_runtime_dependency(%q<sequel>, [">= 3.9.0"])
|
130
|
+
s.add_runtime_dependency(%q<evma_xmlpushparser>, [">= 0.0.1"])
|
131
|
+
else
|
132
|
+
s.add_dependency(%q<rake>, [">= 0.8.3"])
|
133
|
+
s.add_dependency(%q<eventmachine>, [">= 0.12.6"])
|
134
|
+
s.add_dependency(%q<sequel>, [">= 3.9.0"])
|
135
|
+
s.add_dependency(%q<evma_xmlpushparser>, [">= 0.0.1"])
|
136
|
+
end
|
137
|
+
else
|
138
|
+
s.add_dependency(%q<rake>, [">= 0.8.3"])
|
139
|
+
s.add_dependency(%q<eventmachine>, [">= 0.12.6"])
|
140
|
+
s.add_dependency(%q<sequel>, [">= 3.9.0"])
|
141
|
+
s.add_dependency(%q<evma_xmlpushparser>, [">= 0.0.1"])
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
data/lib/agent_xmpp.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'find'
|
4
|
+
require 'singleton'
|
5
|
+
require 'logger'
|
6
|
+
require 'socket'
|
7
|
+
require 'optparse'
|
8
|
+
require 'rexml/document'
|
9
|
+
require 'base64'
|
10
|
+
|
11
|
+
require 'eventmachine'
|
12
|
+
require 'evma_xmlpushparser'
|
13
|
+
|
14
|
+
require 'sequel'
|
15
|
+
|
16
|
+
require 'agent_xmpp/patches'
|
17
|
+
require 'agent_xmpp/client'
|
18
|
+
require 'agent_xmpp/xmpp'
|
19
|
+
require 'agent_xmpp/config'
|
20
|
+
require 'agent_xmpp/models'
|
21
|
+
require 'agent_xmpp/main'
|
22
|
+
require 'agent_xmpp/admin'
|
@@ -0,0 +1,113 @@
|
|
1
|
+
#.........................................................................................................
|
2
|
+
# authorize command access
|
3
|
+
#.........................................................................................................
|
4
|
+
before :command => :all do
|
5
|
+
if access = route[:opts][:access]
|
6
|
+
jid = params[:from]
|
7
|
+
unless AgentXmpp.is_account_jid?(jid)
|
8
|
+
groups = AgentXmpp::Contact.find_by_jid(jid)[:groups]
|
9
|
+
[access].flatten.any?{|a| groups.include?(a)}
|
10
|
+
else; true; end
|
11
|
+
else; true; end
|
12
|
+
end
|
13
|
+
|
14
|
+
#.........................................................................................................
|
15
|
+
# admin commands
|
16
|
+
#.........................................................................................................
|
17
|
+
command 'admin/contacts', :access => 'admin' do
|
18
|
+
AgentXmpp.logger.info "ACTION: admin/contacts"
|
19
|
+
AgentXmpp::Contact.find_all.map{|c| {:jid => c[:jid], :sub => c[:subscription]}}
|
20
|
+
end
|
21
|
+
|
22
|
+
#.........................................................................................................
|
23
|
+
command 'admin/on_line_users', :access => 'admin' do
|
24
|
+
AgentXmpp.logger.info "ACTION: admin/on_line_users"
|
25
|
+
AgentXmpp::Roster.find_all_by_status(:available).map do |r|
|
26
|
+
jid = AgentXmpp::Xmpp::Jid.new(r[:jid])
|
27
|
+
{:jid => jid.bare, :resource => jid.resource}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#.........................................................................................................
|
32
|
+
command 'admin/add_contact', :access => 'admin' do
|
33
|
+
AgentXmpp.logger.info "ACTION: admin/add_contact"
|
34
|
+
on(:execute) do |form|
|
35
|
+
form.add_title('Add Contact')
|
36
|
+
form.add_jid_single('jid', 'contact JID')
|
37
|
+
form.add_text_single('groups', 'groups comma seperated')
|
38
|
+
end
|
39
|
+
on(:submit) do
|
40
|
+
contact = params[:data]
|
41
|
+
if contact["jid"]
|
42
|
+
AgentXmpp::Contact.update(contact)
|
43
|
+
xmpp_msg(AgentXmpp::Xmpp::IqRoster.update(pipe, contact["jid"], contact["groups"].split(/,/)))
|
44
|
+
xmpp_msg(AgentXmpp::Xmpp::Presence.subscribe(contact["jid"]))
|
45
|
+
delegate_to(
|
46
|
+
:on_update_roster_item_result => lambda do |pipe, item_jid|
|
47
|
+
command_completed if item_jid.eql?(contact["jid"])
|
48
|
+
end,
|
49
|
+
:on_update_roster_item_error => lambda do |pipe, item_jid|
|
50
|
+
error(:bad_request, params, 'roster updated failed') if item_jid.eql?(contact["jid"])
|
51
|
+
end
|
52
|
+
)
|
53
|
+
else
|
54
|
+
error(:bad_request, params, 'jid not specified')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
#.........................................................................................................
|
60
|
+
command 'admin/delete_contact', :access => 'admin' do
|
61
|
+
AgentXmpp.logger.info "ACTION: admin/delete_contact"
|
62
|
+
contacts = AgentXmpp::Contact.find_all.map{|c| c[:jid]}
|
63
|
+
on(:execute) do |form|
|
64
|
+
form.add_title('Delete Contact')
|
65
|
+
form.add_list_single('jid', contacts)
|
66
|
+
end
|
67
|
+
on(:submit) do
|
68
|
+
contact = params[:data]
|
69
|
+
if contact["jid"]
|
70
|
+
xmpp_msg(AgentXmpp::Xmpp::IqRoster.remove(pipe, contact["jid"]))
|
71
|
+
delegate_to(
|
72
|
+
:on_remove_roster_item_result => lambda do |pipe, item_jid|
|
73
|
+
command_completed if item_jid.eql?(contact["jid"])
|
74
|
+
end,
|
75
|
+
:on_remove_roster_item_error => lambda do |pipe, item_jid|
|
76
|
+
error(:bad_request, params, 'roster updated failed') if item_jid.eql?(contact["jid"])
|
77
|
+
end
|
78
|
+
)
|
79
|
+
else
|
80
|
+
error(:bad_request, params, 'jid not specified')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
#.........................................................................................................
|
86
|
+
command 'admin/subscriptions', :access => 'admin' do
|
87
|
+
AgentXmpp.logger.info "ACTION: admin/subscriptions"
|
88
|
+
AgentXmpp::Subscription.stats_by_node
|
89
|
+
end
|
90
|
+
|
91
|
+
#.........................................................................................................
|
92
|
+
command 'admin/publications', :access => 'admin' do
|
93
|
+
AgentXmpp.logger.info "ACTION: admin/publications"
|
94
|
+
AgentXmpp::Publication.stats_by_node
|
95
|
+
end
|
96
|
+
|
97
|
+
#.........................................................................................................
|
98
|
+
command 'admin/messages_by_type', :access => 'admin' do
|
99
|
+
AgentXmpp.logger.info "ACTION: admin/publications"
|
100
|
+
AgentXmpp::Message.stats_by_message_type
|
101
|
+
end
|
102
|
+
|
103
|
+
#.........................................................................................................
|
104
|
+
command 'admin/messages_by_contact', :access => 'admin' do
|
105
|
+
AgentXmpp.logger.info "ACTION: admin/publications"
|
106
|
+
AgentXmpp::Contact.message_stats
|
107
|
+
end
|
108
|
+
|
109
|
+
#.........................................................................................................
|
110
|
+
command 'admin/messages_by_command', :access => 'admin' do
|
111
|
+
AgentXmpp.logger.info "ACTION: admin/publications"
|
112
|
+
AgentXmpp::Message.stats_by_command_node
|
113
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'agent_xmpp/client/boot'
|
2
|
+
require 'agent_xmpp/client/controller'
|
3
|
+
require 'agent_xmpp/client/response'
|
4
|
+
require 'agent_xmpp/client/message_pipe'
|
5
|
+
require 'agent_xmpp/client/message_delegate'
|
6
|
+
require 'agent_xmpp/client/connection'
|
7
|
+
require 'agent_xmpp/client/client'
|
@@ -0,0 +1,83 @@
|
|
1
|
+
##############################################################################################################
|
2
|
+
module AgentXmpp
|
3
|
+
|
4
|
+
#####-------------------------------------------------------------------------------------------------------
|
5
|
+
class Boot
|
6
|
+
|
7
|
+
####......................................................................................................
|
8
|
+
class << self
|
9
|
+
|
10
|
+
####....................................................................................................
|
11
|
+
# start application
|
12
|
+
#.......................................................................................................
|
13
|
+
def boot
|
14
|
+
|
15
|
+
AgentXmpp.config_file = File.join(AgentXmpp.app_path, "agent_xmpp.yml")
|
16
|
+
|
17
|
+
AgentXmpp.log_file = add_path(AgentXmpp.log_file) if AgentXmpp.log_file.kind_of?(String)
|
18
|
+
AgentXmpp.logger = Logger.new(AgentXmpp.log_file, 10, 1024000)
|
19
|
+
AgentXmpp.logger.level = Logger::WARN
|
20
|
+
|
21
|
+
call_if_implemented(:call_before_start)
|
22
|
+
|
23
|
+
AgentXmpp.logger.info "STARTING AgentXmpp"
|
24
|
+
AgentXmpp.logger.info "APPLICATION PATH: #{AgentXmpp.app_path}"
|
25
|
+
AgentXmpp.logger.info "LOG FILE: #{AgentXmpp.log_file.kind_of?(String) ? AgentXmpp.log_file : "STDOUT"}"
|
26
|
+
AgentXmpp.logger.info "CONFIGURATION FILE: #{AgentXmpp.config_file}"
|
27
|
+
|
28
|
+
raise AgentXmppError, "Configuration file #{AgentXmpp.config_file} required." unless File.exist?(AgentXmpp.config_file)
|
29
|
+
|
30
|
+
AgentXmpp.config = File.open(AgentXmpp.config_file) {|yf| YAML::load(yf)}
|
31
|
+
|
32
|
+
AgentXmpp.create_agent_xmpp_db
|
33
|
+
AgentXmpp.create_in_memory_db
|
34
|
+
AgentXmpp.upgrade_agent_xmpp_db
|
35
|
+
Contact.load_config
|
36
|
+
Publication.load_config
|
37
|
+
|
38
|
+
AgentXmpp::Client.new().connect
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
####....................................................................................................
|
43
|
+
# application deligate methods
|
44
|
+
#.......................................................................................................
|
45
|
+
def call_if_implemented(method, *args)
|
46
|
+
send(method, *args) if respond_to?(method)
|
47
|
+
end
|
48
|
+
|
49
|
+
#.........................................................................................................
|
50
|
+
def callbacks(*args)
|
51
|
+
args.each do |meth|
|
52
|
+
instance_eval <<-do_eval
|
53
|
+
def call_#{meth}(*args)
|
54
|
+
@array_#{meth}.each{|m| m.call(*args)} unless @array_#{meth}.nil?
|
55
|
+
end
|
56
|
+
def #{meth}(&blk)
|
57
|
+
(@array_#{meth} ||= []) << blk
|
58
|
+
end
|
59
|
+
do_eval
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
####......................................................................................................
|
64
|
+
# private
|
65
|
+
#.......................................................................................................
|
66
|
+
def add_path(dir)
|
67
|
+
File.join(AgentXmpp.app_path, dir)
|
68
|
+
end
|
69
|
+
|
70
|
+
private :add_path
|
71
|
+
|
72
|
+
#### self
|
73
|
+
end
|
74
|
+
|
75
|
+
#.........................................................................................................
|
76
|
+
callbacks(:before_start, :after_connected, :discovered_all_publish_nodes, :discovered_command_nodes,
|
77
|
+
:discovered_pubsub_node, :received_presence, :restarting_client)
|
78
|
+
|
79
|
+
#### Boot
|
80
|
+
end
|
81
|
+
|
82
|
+
#### AgentXmpp
|
83
|
+
end
|