c3s 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +1 -2
- data/Rakefile +1 -1
- data/c3s.gemspec +4 -4
- data/lib/component.rb +19 -9
- data/lib/component_connection.rb +3 -3
- metadata +5 -6
- data/c3s +0 -59
data/Manifest
CHANGED
data/Rakefile
CHANGED
data/c3s.gemspec
CHANGED
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{c3s}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ricardo Otero"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-04-08}
|
10
10
|
s.description = %q{C3s library gem.}
|
11
11
|
s.email = %q{oterosantos@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["README.rdoc", "lib/c3s.rb", "lib/c3s_logger.rb", "lib/component.rb", "lib/component_connection.rb", "lib/configreader.rb", "lib/databaseadapter.rb", "lib/model.rb", "lib/pubsub/node.rb", "lib/pubsub/nodetracker.rb", "lib/pubsub/publisher.rb", "lib/pubsub/subscriber.rb", "lib/republisher.rb"]
|
13
|
-
s.files = ["
|
13
|
+
s.files = ["README.rdoc", "Rakefile", "c3s.gemspec", "lib/c3s.rb", "lib/c3s_logger.rb", "lib/component.rb", "lib/component_connection.rb", "lib/configreader.rb", "lib/databaseadapter.rb", "lib/model.rb", "lib/pubsub/node.rb", "lib/pubsub/nodetracker.rb", "lib/pubsub/publisher.rb", "lib/pubsub/subscriber.rb", "lib/republisher.rb", "Manifest"]
|
14
14
|
s.homepage = %q{http://github.com/rikas/c3s}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "C3s", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{c3s}
|
18
|
-
s.rubygems_version = %q{1.3.
|
18
|
+
s.rubygems_version = %q{1.3.4}
|
19
19
|
s.summary = %q{C3s library gem.}
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
data/lib/component.rb
CHANGED
@@ -33,7 +33,7 @@ module C3s
|
|
33
33
|
# Throws ClientAuthenticationFailure
|
34
34
|
def connect
|
35
35
|
super(config['url'], config['port'])
|
36
|
-
|
36
|
+
|
37
37
|
if is_connected?
|
38
38
|
auth(config['password'])
|
39
39
|
else
|
@@ -51,17 +51,17 @@ module C3s
|
|
51
51
|
Thread.abort_on_exception = true
|
52
52
|
|
53
53
|
add_iq_callback do |iq|
|
54
|
-
|
54
|
+
t1 = Thread.new do
|
55
55
|
handle_iq(iq)
|
56
56
|
end
|
57
|
-
|
57
|
+
t1.join
|
58
58
|
end
|
59
59
|
|
60
60
|
add_message_callback do |msg|
|
61
|
-
|
61
|
+
t2 = Thread.new do
|
62
62
|
handle_msg(msg)
|
63
63
|
end
|
64
|
-
|
64
|
+
t2.join
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -113,10 +113,19 @@ module C3s
|
|
113
113
|
# iq:: [Jabber::IQ] the received IQ packet
|
114
114
|
def handle_set(iq)
|
115
115
|
stanza = iq.query.first_element(config['name']) # TODO assuming that pubsubnode = xml root
|
116
|
-
|
116
|
+
data = {}
|
117
|
+
|
118
|
+
# It's admin setting the information for someone
|
119
|
+
adminJID = "admin@#{config['url']}"
|
120
|
+
if iq.from.bare.to_s.eql?(adminJID)
|
121
|
+
if stanza.attributes['jid']
|
122
|
+
data = {:jid => stanza.attributes['jid']}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
117
126
|
# Build data for activerecord object. The jid is taken from
|
118
127
|
# the 'jid' attribute on the main tag under the <query>
|
119
|
-
data = {:jid => iq.from.to_s}
|
128
|
+
data = {:jid => iq.from.to_s} if data.empty?
|
120
129
|
self.model.new.nodes.each do |node|
|
121
130
|
data.merge!(node => stanza.first_element_text(node))
|
122
131
|
end
|
@@ -130,8 +139,8 @@ module C3s
|
|
130
139
|
object.save!
|
131
140
|
|
132
141
|
if object.errors.count == 0
|
133
|
-
$LOG.info "Publishing data to node #{config['name']}:#{
|
134
|
-
c3snode = C3s::Node.new("#{config['name']}:#{
|
142
|
+
$LOG.info "Publishing data to node #{config['name']}:#{data[:jid]} (data changed: #{changed})"
|
143
|
+
c3snode = C3s::Node.new("#{config['name']}:#{data[:jid]}")
|
135
144
|
publish(c3snode, stanza, changed)
|
136
145
|
send_ok(iq)
|
137
146
|
end
|
@@ -183,6 +192,7 @@ module C3s
|
|
183
192
|
# changed:: [Boolean] the data is different from last set operation?
|
184
193
|
def publish(c3snode, data, changed)
|
185
194
|
if changed
|
195
|
+
$LOG.info "Information for node '#{c3snode.to_s}' changed. Publishing data..."
|
186
196
|
pub = Publisher.new(self, config['pubsub'])
|
187
197
|
pub.create_tree(c3snode)
|
188
198
|
pub.publish(c3snode, data)
|
data/lib/component_connection.rb
CHANGED
@@ -57,9 +57,9 @@ module C3s
|
|
57
57
|
|
58
58
|
# TODO - use this to do something useful?
|
59
59
|
@component.on_exception do |e, component, where|
|
60
|
-
|
61
|
-
$LOG.error e.backtrace.join("\n")
|
62
|
-
|
60
|
+
component.disconnect
|
61
|
+
$LOG.error e.backtrace.join("\n") if e
|
62
|
+
exit 1
|
63
63
|
end
|
64
64
|
|
65
65
|
puts "Starting messaging loop..."
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 4
|
9
|
+
version: 0.3.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ricardo Otero
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-04-08 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -39,10 +39,9 @@ extra_rdoc_files:
|
|
39
39
|
- lib/pubsub/subscriber.rb
|
40
40
|
- lib/republisher.rb
|
41
41
|
files:
|
42
|
-
- Manifest
|
43
42
|
- README.rdoc
|
44
43
|
- Rakefile
|
45
|
-
- c3s
|
44
|
+
- c3s.gemspec
|
46
45
|
- lib/c3s.rb
|
47
46
|
- lib/c3s_logger.rb
|
48
47
|
- lib/component.rb
|
@@ -55,7 +54,7 @@ files:
|
|
55
54
|
- lib/pubsub/publisher.rb
|
56
55
|
- lib/pubsub/subscriber.rb
|
57
56
|
- lib/republisher.rb
|
58
|
-
-
|
57
|
+
- Manifest
|
59
58
|
has_rdoc: true
|
60
59
|
homepage: http://github.com/rikas/c3s
|
61
60
|
licenses: []
|
data/c3s
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# This is the command used to run the component
|
4
|
-
|
5
|
-
require 'rubygems'
|
6
|
-
|
7
|
-
# Check for gem versions
|
8
|
-
gem 'c3s', '>=0.3.2'
|
9
|
-
gem 'xmpp4r', '>=0.5'
|
10
|
-
|
11
|
-
require 'c3s'
|
12
|
-
require 'pathname'
|
13
|
-
|
14
|
-
PROVIDERS_DIR = File.join(ENV['HOME'], "ptcb", "code", "providers")
|
15
|
-
|
16
|
-
def usage
|
17
|
-
puts "Usage: provider [provider_dir]"
|
18
|
-
puts ""
|
19
|
-
puts "Available providers: #{available_providers}"
|
20
|
-
puts ""
|
21
|
-
exit
|
22
|
-
end
|
23
|
-
|
24
|
-
def available_providers
|
25
|
-
available_providers = []
|
26
|
-
Dir.glob(File.join(PROVIDERS_DIR, "*")) do |dir|
|
27
|
-
next unless File.directory?(dir)
|
28
|
-
conf = File.join(dir, "component.yml")
|
29
|
-
path = Pathname.new(dir)
|
30
|
-
available_providers << path.basename if File.exist?(conf)
|
31
|
-
end
|
32
|
-
available_providers.join(", ")
|
33
|
-
end
|
34
|
-
|
35
|
-
args = ARGV
|
36
|
-
if (args.size!=1)
|
37
|
-
usage
|
38
|
-
else
|
39
|
-
provider = File.join(PROVIDERS_DIR, args.last)
|
40
|
-
if (!File.directory?(provider))
|
41
|
-
puts "Couldn't find '#{args.last}' provider"
|
42
|
-
exit
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Set process name to provider
|
47
|
-
$0 = args.last
|
48
|
-
|
49
|
-
# Set the dir variables
|
50
|
-
C3S_COMPONENT_DIR = File.join(PROVIDERS_DIR, args.last)
|
51
|
-
C3S_LIB_DIR = File.join(C3S_COMPONENT_DIR, 'lib')
|
52
|
-
C3S_LOG_DIR = File.join(C3S_COMPONENT_DIR, 'logs')
|
53
|
-
|
54
|
-
# Power to the requires
|
55
|
-
$:.unshift C3S_COMPONENT_DIR
|
56
|
-
$:.unshift C3S_LIB_DIR
|
57
|
-
$:.unshift File.join(C3S_LIB_DIR, args.last)
|
58
|
-
|
59
|
-
require 'lib/runner'
|