Module: AgentXmpp

Defined in:
lib/agent_xmpp/xmpp/iq.rb,
lib/agent_xmpp/main.rb,
lib/agent_xmpp/config.rb,
lib/agent_xmpp/xmpp/jid.rb,
lib/agent_xmpp/xmpp/sasl.rb,
lib/agent_xmpp/xmpp/entry.rb,
lib/agent_xmpp/client/boot.rb,
lib/agent_xmpp/xmpp/stanza.rb,
lib/agent_xmpp/xmpp/x_data.rb,
lib/agent_xmpp/xmpp/element.rb,
lib/agent_xmpp/xmpp/message.rb,
lib/agent_xmpp/client/client.rb,
lib/agent_xmpp/models/roster.rb,
lib/agent_xmpp/xmpp/iq_disco.rb,
lib/agent_xmpp/xmpp/presence.rb,
lib/agent_xmpp/models/contact.rb,
lib/agent_xmpp/models/message.rb,
lib/agent_xmpp/models/service.rb,
lib/agent_xmpp/xmpp/iq_pubsub.rb,
lib/agent_xmpp/xmpp/iq_roster.rb,
lib/agent_xmpp/client/response.rb,
lib/agent_xmpp/xmpp/iq_command.rb,
lib/agent_xmpp/xmpp/iq_version.rb,
lib/agent_xmpp/client/connection.rb,
lib/agent_xmpp/client/controller.rb,
lib/agent_xmpp/models/publication.rb,
lib/agent_xmpp/client/message_pipe.rb,
lib/agent_xmpp/models/subscription.rb,
lib/agent_xmpp/xmpp/error_response.rb,
lib/agent_xmpp/client/message_delegate.rb,
lib/agent_xmpp/models/table_definitions.rb

Overview

Original from XMPP4R - XMPP Library for Ruby Website::home.gna.org/xmpp4r/

Defined Under Namespace

Modules: Delegator, Xmpp Classes: AgentXmppError, BaseController, Boot, Client, Connection, Contact, Controller, Delegate, Error, Message, MessageDelegate, MessagePipe, Publication, Response, Roster, Service, Subscription

Constant Summary collapse

VERSION =

.….….….….….….….….….….….….….….….….….….….….….….….….….….

"0.1.1"
AGENT_XMPP_NAME =
'AgentXMPP'
OS_VERSION =
IO.popen('uname -sr').readlines.first.to_s.strip
SUBSCRIBE_RETRY_PERIOD =
60
IDENTITY =
{:category => 'client', :name => AGENT_XMPP_NAME, :type => 'bot'}
FEATURES =
['http://jabber.org/protocol/disco#info', 
'http://jabber.org/protocol/disco#items',
'jabber:iq:version',
'jabber:x:data',
'http://jabber.org/protocol/commands',
'http://jabber.org/protocol/pubsub',
'http://jabber.org/protocol/pubsub#publish',
'http://jabber.org/protocol/pubsub#subscribe',
'http://jabber.org/protocol/pubsub#create-nodes',
'http://jabber.org/protocol/pubsub#delete-nodes']
GARBAGE_COLLECTION_INTERVAL =
86400
DEFAULT_PUBSUB_CONFIG =
{
  :title                    => 'event',
  :access_model             => 'presence',
  :max_items                => 20,
  :deliver_notifications    => 1,
  :deliver_payloads         => 1,
  :persist_items            => 1,
  :subscribe                => 1,
  :notify_config            => 0,
  :notify_delete            => 0,
  :notify_retract           => 0,
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.app_pathObject

Returns the value of attribute app_path.



39
40
41
# File 'lib/agent_xmpp/config.rb', line 39

def app_path
  @app_path
end

.configObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



25
26
27
# File 'lib/agent_xmpp/main.rb', line 25

def config
  @config
end

.config_fileObject

Returns the value of attribute config_file.



39
40
41
# File 'lib/agent_xmpp/config.rb', line 39

def config_file
  @config_file
end

.log_fileObject

Returns the value of attribute log_file.



39
40
41
# File 'lib/agent_xmpp/config.rb', line 39

def log_file
  @log_file
end

.settingsObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



25
26
27
# File 'lib/agent_xmpp/main.rb', line 25

def settings
  @settings
end

Class Method Details

.agent_xmpp_dbObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



42
43
44
45
46
47
48
# File 'lib/agent_xmpp/main.rb', line 42

def agent_xmpp_db
  @agent_xmpp_db ||= if settings[:agent_xmpp_db_adapter] 
                       settings[:agent_xmpp_db_adapter].call
                     else 
                       Sequel.sqlite("#{AgentXmpp.app_path}/agent_xmpp.db") 
                     end
end

.bare_jid_to_s(jid) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



118
119
120
121
122
123
124
# File 'lib/agent_xmpp/main.rb', line 118

def bare_jid_to_s(jid)
  case jid
    when String then Xmpp::Jid.new(jid).bare.to_s
    when Xmpp::Jid then jid.bare.to_s
  else jid
  end 
end

.create_agent_xmpp_dbObject




67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/agent_xmpp/models/table_definitions.rb', line 67

def create_agent_xmpp_db
  unless agent_xmpp_db.table_exists? :version
    agent_xmpp_db.create_table :version do
    	primary_key :id
      integer :number
    end
  end
  version << {:number=>1} if version.count.eql?(0)
  unless agent_xmpp_db.table_exists? :contacts
    agent_xmpp_db.create_table :contacts do
    	primary_key :id
    	column :jid, :text, :unique=>true
      column :ask, :text
      column :subscription, :text
    	column :groups, :text
    end
  end
  unless agent_xmpp_db.table_exists? :messages
    agent_xmpp_db.create_table :messages do
    	primary_key :id
    	column :message_text, :text
    	column :content_type, :text
    	column :message_type, :text
    	column :to_jid, :text
    	column :from_jid, :text
    	column :node, :text
    	column :item_id, :text
      Time :created_at
    end
  end
end

.create_in_memory_dbObject




8
9
10
11
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/agent_xmpp/models/table_definitions.rb', line 8

def create_in_memory_db
  in_memory_db.create_table :roster do
  	primary_key :id
  	column :contact_id, :integer
    column :jid, :text, :unique=>true
  	column :status, :text
    column :client_name, :text
    column :client_version, :text
    column :client_os, :text
  end
  in_memory_db.create_table :services do
  	primary_key :id
    column :jid, :text
    column :name, :text
    column :category, :text
    column :type, :text
    column :node, :text
    unique [:node, :jid]
  end
  in_memory_db.create_table :service_items do
  	primary_key :id
    column :parent_node, :text
    column :service, :text
    column :node, :text
    column :jid, :text
    column :name, :text
    unique [:node, :service]
  end
  in_memory_db.create_table :service_features do
  	primary_key :id
    column :node, :text
    column :service, :text
    column :var, :text
    unique [:node, :service, :var]
  end
  in_memory_db.create_table :publications do
  	primary_key :id
    column :node, :text, :unique=>true
    column :status, :text
    column :title, :text
    column :access_model, :text
    column :max_items, :integer
    column :deliver_notifications, :integer
    column :deliver_payloads, :integer
    column :persist_items, :integer
    column :subscribe, :integer
    column :notify_config, :integer
    column :notify_delete, :integer
    column :notify_retract, :integer
  end
  in_memory_db.create_table :subscriptions do
  	primary_key :id
    column :node, :text, :unique=>true
    column :service, :text
    column :subscription, :text
  end
end

.full_jid_to_s(jid) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



127
128
129
130
131
132
133
# File 'lib/agent_xmpp/main.rb', line 127

def full_jid_to_s(jid)
  case jid
    when String then jid
    when Xmpp::Jid then jid.to_s
  else jid
  end 
end

.in_memory_dbObject

.….….….….….….….….….….….….….….….….….….….….….….….….…. database .….….….….….….….….….….….….….….….….….….….….….….….….….….



37
38
39
# File 'lib/agent_xmpp/main.rb', line 37

def in_memory_db
  @in_memory_db ||= Sequel.sqlite
end

.is_account_jid?(jid) ⇒ Boolean

.….….….….….….….….….….….….….….….….….….….….….….….….…. client account configuration .….….….….….….….….….….….….….….….….….….….….….….….….….….

Returns:

  • (Boolean)


75
76
77
# File 'lib/agent_xmpp/main.rb', line 75

def (jid)
  @jid.bare.to_s.eql?(bare_jid_to_s(jid))
end

.jidObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



80
81
82
# File 'lib/agent_xmpp/main.rb', line 80

def jid
  @jid ||= Xmpp::Jid.new("#{config['jid']}/#{resource}")
end

.jid=(jid) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



85
86
87
# File 'lib/agent_xmpp/main.rb', line 85

def jid=(jid)
  @jid = jid
end

.loggerObject



40
# File 'lib/agent_xmpp/config.rb', line 40

def logger; @logger ||= Logger.new(STDOUT); end

.logger=(logger) ⇒ Object



41
# File 'lib/agent_xmpp/config.rb', line 41

def logger=(logger); @logger = logger; end

.passwordObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



100
101
102
# File 'lib/agent_xmpp/main.rb', line 100

def password
  config['password']
end

.portObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



95
96
97
# File 'lib/agent_xmpp/main.rb', line 95

def port
  config['port'] || 5222
end

.priorityObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/agent_xmpp/main.rb', line 105

def priority
  @priority ||= if config['priority']
                  if config['priority'] < -127
                    -127
                  elsif config['priority'] > 128
                    128
                  else
                    config['priority']
                  end
                else; 1; end
end

.publicationObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



56
57
58
# File 'lib/agent_xmpp/main.rb', line 56

def publication
  @publication ||= PublishModel.new(config['publish'])
end

.pubsub_rootObject

.….….….….….….….….….….….….….….….….….….….….….….….….…. pubsub nodes .….….….….….….….….….….….….….….….….….….….….….….….….….….



63
64
65
# File 'lib/agent_xmpp/main.rb', line 63

def pubsub_root
  @pubsub_root ||= "/home/#{AgentXmpp.jid.domain}"  
end

.resourceObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



90
91
92
# File 'lib/agent_xmpp/main.rb', line 90

def resource
  config['resource'] || Socket.gethostname
end

.set(key, value) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….…. settings .….….….….….….….….….….….….….….….….….….….….….….….….….….



30
31
32
# File 'lib/agent_xmpp/main.rb', line 30

def set(key, value)
  @settings[key] = value
end

.start_garbage_collection(pipe) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….….….



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/agent_xmpp/main.rb', line 136

def start_garbage_collection(pipe)
  EventMachine::PeriodicTimer.new(AgentXmpp::GARBAGE_COLLECTION_INTERVAL) do
    AgentXmpp.logger.info "GARBAGE COLLECTION IN PROGRESS ON INTERVAL: #{AgentXmpp::GARBAGE_COLLECTION_INTERVAL}"
    AgentXmpp::BaseController.commands_list.each do |(session, command_info)|
      AgentXmpp::BaseController.remove_command_from_list(session) if Time.now - command_info[:created_at] > AgentXmpp::GARBAGE_COLLECTION_INTERVAL
    end
    pipe.responder_list.each do |(stanza_id, command_info)|
      pipe.remove_from_responder_list(stanza_id) if Time.now - command_info[:created_at] > AgentXmpp::GARBAGE_COLLECTION_INTERVAL
    end
  end  
end

.upgrade_agent_xmpp_dbObject




100
101
# File 'lib/agent_xmpp/models/table_definitions.rb', line 100

def upgrade_agent_xmpp_db
end

.user_pubsub_rootObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



68
69
70
# File 'lib/agent_xmpp/main.rb', line 68

def user_pubsub_root
  @user_pubsub_root ||= "#{@pubsub_root}/#{AgentXmpp.jid.node}" 
end

.versionObject

.….….….….….….….….….….….….….….….….….….….….….….….….….….



51
52
53
# File 'lib/agent_xmpp/main.rb', line 51

def version
  @version ||= agent_xmpp_db[:version]
end