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.0"
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

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



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

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

Class Method Details

.agent_xmpp_dbObject

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



34
35
36
# File 'lib/agent_xmpp/main.rb', line 34

def agent_xmpp_db
  @agent_xmpp_db ||= Sequel.sqlite("#{AgentXmpp.app_path}/agent_xmpp.db")
end

.bare_jid_to_s(jid) ⇒ Object

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



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

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

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



115
116
117
118
119
120
121
# File 'lib/agent_xmpp/main.rb', line 115

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 .….….….….….….….….….….….….….….….….….….….….….….….….….….



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

def in_memory_db
  @in_memory_db ||= Sequel.sqlite
end

.is_account_jid?(jid) ⇒ Boolean

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

Returns:

  • (Boolean)


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

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

.jidObject

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



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

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

.jid=(jid) ⇒ Object

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



73
74
75
# File 'lib/agent_xmpp/main.rb', line 73

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

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



88
89
90
# File 'lib/agent_xmpp/main.rb', line 88

def password
  config['password']
end

.portObject

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



83
84
85
# File 'lib/agent_xmpp/main.rb', line 83

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

.priorityObject

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



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/agent_xmpp/main.rb', line 93

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

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



44
45
46
# File 'lib/agent_xmpp/main.rb', line 44

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

.pubsub_rootObject

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



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

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

.resourceObject

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



78
79
80
# File 'lib/agent_xmpp/main.rb', line 78

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

.start_garbage_collection(pipe) ⇒ Object

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



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

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

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



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

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

.versionObject

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



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

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