yong-stropheruby 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.autotest ADDED
@@ -0,0 +1,9 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ at.add_mapping(/ext\/.*\/(.*)\.[ch]/) do |_, m|
3
+ ["test/test_#{m[1]}_extn.rb"]
4
+ end
5
+ end
6
+
7
+ Autotest.add_hook :run_command do |at|
8
+ system "rake compile"
9
+ end
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-12-05
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,39 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.rdoc
6
+ Rakefile
7
+ ext/md5.c
8
+ ext/parser.c
9
+ ext/util.c
10
+ ext/strophe_ruby.c
11
+ ext/conn.c
12
+ ext/ctx.c
13
+ ext/jid.c
14
+ ext/handler.c
15
+ ext/hash.c
16
+ ext/sasl.c
17
+ ext/event.c
18
+ ext/auth.c
19
+ ext/thread.c
20
+ ext/stanza.c
21
+ ext/tls_dummy.c
22
+ ext/sha1.c
23
+ ext/snprintf.c
24
+ ext/sock.c
25
+ ext/tls.h
26
+ ext/sasl.h
27
+ ext/thread.h
28
+ ext/util.h
29
+ ext/common.h
30
+ ext/md5.h
31
+ ext/hash.h
32
+ ext/sha1.h
33
+ ext/sock.h
34
+ ext/strophe.h
35
+ ext/ostypes.h
36
+ lib/strophe_ruby.rb
37
+ test/test_helper.rb
38
+ test/test_strophe_ruby.rb
39
+ test/test_strophe_ruby_extn.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,4 @@
1
+ For more information on strophe_ruby, see http://strophe_ruby.rubyforge.org
2
+
3
+ NOTE: Change this information in PostInstall.txt
4
+ You can also delete it if you don't want it.
data/README.rdoc ADDED
@@ -0,0 +1,143 @@
1
+ = strophe_ruby
2
+
3
+ http://stropheruby.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ Ruby bindings for Strophe 'http://code.stanziq.com/strophe/', a C library for
8
+ writing XMPP clients. If all you need is a simple XMPP bot that
9
+ react to message and presence notifications, you might be better off
10
+ with XMPPBot, which is an implementation I wrote on top of StropheRuby.
11
+
12
+ IMPORTANT : This gem is quite experimental currently... it is not ready
13
+ for production!
14
+
15
+ Strophe 'http://code.stanziq.com/strophe/' is a robust and well written
16
+ C library that allows the developer to implement XMPP clients.
17
+
18
+ I wanted to be able to use the power of this library with the ruby
19
+ syntax. I didn't use SWIG to generate the bindings for 2 reasons :
20
+
21
+ 1. I wanted to learn how to write a C extension for ruby
22
+ 2. I didn't like how SWIG generate gazilions of lines of code
23
+
24
+ My other project, XMPPBot, is an implementation of Strophe Ruby that
25
+ allows the ruby developer to write a XMPP bot in a few lines of code.
26
+
27
+ == CURRENT PROBLEMS:
28
+
29
+ - Currently no Support for TLS encryption (Coming soon as it's rather important)
30
+ - Cannot terminate the loop with CTRL-C
31
+ - Socket disconnects after being inactive for too long
32
+ - Cannot output log data in a file
33
+
34
+
35
+ == EXAMPLE OF USE
36
+
37
+ require 'strophe_ruby'
38
+
39
+ def announce_presence
40
+ stanza = StropheRuby::Stanza.new
41
+ stanza.name = "presence"
42
+ @conn.send(stanza)
43
+ end
44
+
45
+ def register_callbacks
46
+ #Accept all subscriptions
47
+ @conn.add_handler("presence") do |pres|
48
+ if pres.type == "subscribe"
49
+ #we accept
50
+ p = StropheRuby::Stanza.new
51
+ p.name = "presence"
52
+ p.type = "subscribed"
53
+ p.set_attribute("to",pres.attribute("from"))
54
+ @conn.send(p)
55
+
56
+ #then it's our turn to send our subscription request
57
+ p = StropheRuby::Stanza.new
58
+ p.name = "presence"
59
+ p.type = "subscribe"
60
+ p.set_attribute("to",pres.attribute("from"))
61
+ @conn.send(p)
62
+ end
63
+ end
64
+
65
+ #simple echo for messages
66
+ @conn.add_handler("message") do |msg|
67
+
68
+ if msg.child_by_name("body")
69
+ top_stanza = StropheRuby::Stanza.new
70
+ top_stanza.name="message"
71
+ top_stanza.type="chat"
72
+ top_stanza.set_attribute("to", msg.attribute("from"))
73
+
74
+ body_stanza = StropheRuby::Stanza.new
75
+ body_stanza.name="body"
76
+
77
+ text_stanza = StropheRuby::Stanza.new
78
+ text_stanza.text = msg.child_by_name("body").text
79
+
80
+ body_stanza.add_child(text_stanza)
81
+ top_stanza.add_child(body_stanza)
82
+ @conn.send(top_stanza)
83
+ end
84
+ end
85
+ end
86
+
87
+
88
+ #Prepare the strophe library
89
+ StropheRuby::EventLoop.prepare
90
+
91
+ #create the runtime context and specify the logging level (WARN,INFO,ERROR or DEBUG)
92
+ @ctx=StropheRuby::Context.new(StropheRuby::Logging::DEBUG)
93
+
94
+ #create the connection passing it the context
95
+ @conn=StropheRuby::Connection.new(@ctx)
96
+
97
+ #set the jid and password
98
+ @conn.jid = 'bot@example.com'
99
+ @conn.password = 'secret'
100
+
101
+ #Try to connect
102
+ @conn.connect do |status|
103
+ if status == StropheRuby::ConnectionEvents::CONNECT
104
+ #We are connected.
105
+ announce_presence
106
+ register_callbacks
107
+ else
108
+ @conn.disconnect
109
+ end
110
+ end
111
+
112
+
113
+ #Start the event loop
114
+ StropheRuby::EventLoop.run(@ctx)
115
+
116
+ puts 'Disconnected'
117
+
118
+ == INSTALL:
119
+
120
+ gem install strophe_ruby
121
+
122
+ == LICENSE:
123
+
124
+ Copyright (c) 2008 François Lamontagne
125
+
126
+ Permission is hereby granted, free of charge, to any person obtaining
127
+ a copy of this software and associated documentation files (the
128
+ 'Software'), to deal in the Software without restriction, including
129
+ without limitation the rights to use, copy, modify, merge, publish,
130
+ distribute, sublicense, and/or sell copies of the Software, and to
131
+ permit persons to whom the Software is furnished to do so, subject to
132
+ the following conditions:
133
+
134
+ The above copyright notice and this permission notice shall be
135
+ included in all copies or substantial portions of the Software.
136
+
137
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
138
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
139
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
140
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
141
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
142
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
143
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+
4
+ EXT = "ext/strophe_ruby.#{Hoe::DLEXT}"
5
+
6
+ Hoe.new('stropheruby', '0.0.5') do |p|
7
+ p.developer('François Lamontagne', 'flamontagne@gmail.com')
8
+ p.summary = 'strophe_ruby'
9
+
10
+ p.spec_extras[:extensions] = "ext/extconf.rb"
11
+ p.clean_globs << EXT << "ext/*.o" << "ext/Makefile"
12
+ end
13
+
14
+ task :test => EXT
15
+
16
+ file EXT => ["ext/extconf.rb", "ext/strophe_ruby.c"] do
17
+ Dir.chdir "ext" do
18
+ ruby "extconf.rb"
19
+ sh "make"
20
+ end
21
+ end