rslp 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ef8e7db15adf1f9e15979f07caecad8051e01084a4aeb215351adfcc97eb7335
4
+ data.tar.gz: 208805a618c7b3b278513fd7bb8fa7945e3b3b61ef4f8696eeb565eb1008c04f
5
+ SHA512:
6
+ metadata.gz: dd5c483bb96f5866adcf971a86551f441a3ed2046fc1a7b245ccfbda979cbccd5bee7525deafdf98a5244c8c7f3c20012b0c1a99f1aa339ee756d1749f91675d
7
+ data.tar.gz: 1c4293e328733ecc6dbbfcf92574ac8c671fe7f31eb1458643c03b8975125ce57ef967543fcb53a92677e8c0001103644b47036e1fb47d98faef53d76eeb5897
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ��@�!�]�P��G��n�ыYE�D��g�T����5�ׯ(���߆P�(MN��8Ѩ:�S(��)1�!I?
2
+ HXs�����=?��c���h�+狓|���2Q�u7�c���:��f�M���k������Б�s4nh�r$C:��|�K� �����$��u
data/CHANGES.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.0.1 - 2-Jul-2021
2
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org' do
2
+ gemspec
3
+ end
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/MANIFEST.md ADDED
@@ -0,0 +1,14 @@
1
+ CHANGES.md
2
+ Gemfile
3
+ LICENSE
4
+ MANIFEST.md
5
+ README.md
6
+ rslp.gemspec
7
+ Rakefile
8
+ certs/djberg96_pub.pem
9
+ lib/rslp.rb
10
+ lib/slp/constants.rb
11
+ lib/slp/functions.rb
12
+ lib/slp/helper.rb
13
+ lib/slp/structs.rb
14
+ spec/rslp_spec.rb
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ ## Description
2
+ A Ruby wrapper for OpenSLP using FFI.
3
+
4
+ ## Installation
5
+ `gem install rslp`
6
+
7
+ ## Synopsis
8
+ ```ruby
9
+ require 'rslp'
10
+
11
+ OpenSLP::SLP.new do |slp|
12
+ # See docs for more methods
13
+ p slp.find_services
14
+ p slp.find_scopes
15
+ end
16
+ ```
17
+
18
+ ## Known Bugs
19
+ None that I'm aware of. Please report bugs on the project page at:
20
+
21
+ https://github.com/djberg96/rslp
22
+
23
+ ## Future Plans
24
+ None at this time.
25
+
26
+ ## Maintenance
27
+ Please contact me about taking over maintenance of this library if you are
28
+ interested. I'm not actually using it myself, and have no real plans to update
29
+ it.
30
+
31
+ Why then? I originally wrote most of this when I thought we might need it
32
+ for a project at work. That never materialized, but I hated to let it go to
33
+ waste, so I've published what I completed.
34
+
35
+ ## License
36
+ Apache-2.0
37
+
38
+ ## Copyright
39
+ (C) 2003-2021 Daniel J. Berger, All Rights Reserved
40
+
41
+ ## Warranty
42
+ This package is provided "as is" and without any express or
43
+ implied warranties, including, without limitation, the implied
44
+ warranties of merchantability and fitness for a particular purpose.
45
+
46
+ ## Author
47
+ Daniel J. Berger
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rake/clean'
4
+
5
+ CLEAN.include('**/*.gem', '**/*.rbc', '**/*.rbx', '**/*.lock')
6
+
7
+ namespace 'gem' do
8
+ desc "Create the sys-cpu gem"
9
+ task :create => [:clean] do
10
+ require 'rubygems/package'
11
+ spec = Gem::Specification.load('rslp.gemspec')
12
+ spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
13
+ Gem::Package.build(spec)
14
+ end
15
+
16
+ desc "Install the sys-cpu gem"
17
+ task :install => [:create] do
18
+ file = Dir["*.gem"].first
19
+ sh "gem install -l #{file}"
20
+ end
21
+ end
22
+
23
+ desc "Run the test suite"
24
+ RSpec::Core::RakeTask.new(:spec)
25
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
3
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
4
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
5
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
6
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
7
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
8
+ u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
9
+ 75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
10
+ 6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
11
+ iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
12
+ ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
13
+ 74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
14
+ 058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
15
+ HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
16
+ AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
17
+ YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
18
+ /3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
19
+ h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
20
+ 6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
21
+ ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
22
+ 1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
23
+ DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
24
+ ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
25
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
26
+ -----END CERTIFICATE-----
data/lib/rslp.rb ADDED
@@ -0,0 +1,346 @@
1
+ require_relative 'slp/functions'
2
+ require_relative 'slp/constants'
3
+ require_relative 'slp/structs'
4
+ require_relative 'slp/helper'
5
+
6
+ module OpenSLP
7
+ class SLP
8
+ include OpenSLP::Functions
9
+ include OpenSLP::Constants
10
+ include OpenSLP::Structs
11
+ extend OpenSLP::Functions
12
+
13
+ # The version of the rslp library.
14
+ VERSION = '0.0.1'.freeze
15
+
16
+ # The language tag for requests.
17
+ attr_reader :lang
18
+
19
+ # Returns whether or not the SLP instance is asynchronous.
20
+ attr_reader :async
21
+
22
+ # Creates and returns an OpenSLP::SLP object. This establishes a handle
23
+ # that is used for the life of the object.
24
+ #
25
+ # The +lang+ argument may be an RFC 1766 language tag, e.g. 'en-us', that
26
+ # sets the natural language local for requests. By default it uses your
27
+ # machine's locale.
28
+ #
29
+ # The +async+ argument may be set to true or false and establishes whether
30
+ # the underlying handle is set to handl asynchronous operations or not. By
31
+ # default this value is false.
32
+ #
33
+ # If a block is given, then the object itself is yielded to the block, and
34
+ # it is automatically closed at the end of the block.
35
+ #
36
+ # Examples:
37
+ #
38
+ # OpenSLP::SLP.new('en-us') do |slp|
39
+ # # ... do stuff
40
+ # end
41
+ #
42
+ # slp = OpenSLP::SLP.new('en-us')
43
+ # # Do stuff
44
+ # slp.close
45
+ #
46
+ def initialize(lang = '', async = false)
47
+ @lang = lang
48
+ @async = async
49
+
50
+ ptr = FFI::MemoryPointer.new(:ulong)
51
+
52
+ if SLPOpen(lang, async, ptr) != SLP_OK
53
+ raise SystemCallError.new('SLPOpen', FFI.errno)
54
+ end
55
+
56
+ @handle = ptr.read_ulong
57
+
58
+ if block_given?
59
+ begin
60
+ yield self
61
+ ensure
62
+ close
63
+ end
64
+ end
65
+ end
66
+
67
+ # Close the OpenSLP::SLP object. The block form of the constructor will
68
+ # automatically call this for you.
69
+ #
70
+ def close
71
+ SLPClose(@handle)
72
+ end
73
+
74
+ # Register a :url for the given :lifetime. You may also specify a hash
75
+ # of :attributes, specify whether or not this is a :fresh service.
76
+ #
77
+ # The lifetime defaults to SLP_LIFETIME_DEFAULT.
78
+ #
79
+ # The attributes defaults to an empty string. Note that the has you provide
80
+ # automatically converts the attributes into the appropriate format.
81
+ #
82
+ # By default it will be considered a fresh service.
83
+ #
84
+ # Returns the url if successful.
85
+ #
86
+ def register(options = {})
87
+ options[:lifetime] ||= SLP_LIFETIME_DEFAULT
88
+ options[:attributes] ||= ""
89
+ options[:fresh] ||= true
90
+
91
+ options[:callback] ||= Proc.new{ |hslp, err, cookie| }
92
+
93
+ if options[:attributes] && options[:attributes] != ""
94
+ attributes = options[:attributes].map{ |k,v| "(#{k}=#{v})" }.join(',')
95
+ else
96
+ attributes = ""
97
+ end
98
+
99
+ cookie = FFI::MemoryPointer.new(:void)
100
+
101
+ result = SLPReg(
102
+ @handle,
103
+ options[:url],
104
+ options[:lifetime],
105
+ nil,
106
+ attributes,
107
+ options[:fresh],
108
+ options[:callback],
109
+ cookie
110
+ )
111
+
112
+ raise SystemCallError.new('SLPReg', result) if result != SLP_OK
113
+
114
+ options[:url]
115
+ end
116
+
117
+ # Deregisters the advertisement for +url+ in all scopes where the service
118
+ # is registered and all language locales.
119
+ #
120
+ def deregister(url)
121
+ callback = Proc.new{ |hslp, err, cookie| }
122
+ cookie = FFI::MemoryPointer.new(:void)
123
+
124
+ result = SLPDereg(@handle, url, callback, cookie)
125
+ raise SystemCallError.new('SLPDereg', result) if result != SLP_OK
126
+
127
+ true
128
+ end
129
+
130
+ # Deletes specified attributes from a registered service. The attributes
131
+ # argument should be a comma separated list (in string form) of attribute
132
+ # ids.
133
+ #
134
+ # Returns the list of deleted attributes if successful.
135
+ #
136
+ def delete_service_attributes(url, attributes)
137
+ callback = Proc.new{ |hslp, err, cookie| }
138
+ cookie = FFI::MemoryPointer.new(:void)
139
+
140
+ result = SLPDelAttrs(@handle, url, attributes, callback, cookie)
141
+ raise SystemCallError.new('SLPDelAttrs', result) if result != SLP_OK
142
+
143
+ attributes
144
+ end
145
+
146
+ # Returns a list of scopes. The most desirable values are always first in
147
+ # the list. There is always at least one value ("DEFAULT") in the list.
148
+ #
149
+ def find_scopes
150
+ begin
151
+ pptr = FFI::MemoryPointer.new(:pointer, 128)
152
+
153
+ rv = SLPFindScopes(@handle, pptr)
154
+
155
+ if rv != SLP_OK
156
+ raise SystemCallError.new('SLPFindScopes', rv)
157
+ end
158
+
159
+ arr = pptr.read_array_of_string
160
+ ensure
161
+ SLPFree(pptr.read_pointer)
162
+ pptr.free
163
+ end
164
+
165
+ arr
166
+ end
167
+
168
+ # Issue a query for services.
169
+ #
170
+ # The +type+ argument is the service type string, including the authority
171
+ # string, for the request. It may not be nil or empty.
172
+ #
173
+ # The +scope+ argument is a comma separated list of scope names. May be an
174
+ # empty string if you wish to use scopes this machine is configured for.
175
+ #
176
+ # A query formulated of attribute pattern matching expressions in the
177
+ # form of an LDAP search filter. The default is an empty string, which
178
+ # will gather all services of the requested type.
179
+ #
180
+ def find_services(type, scope = '', filter = '')
181
+ arr = []
182
+
183
+ callback = Proc.new{ |hslp, url, life, err, cook|
184
+ if err == SLP_OK
185
+ arr << {url => life}
186
+ true
187
+ else
188
+ false
189
+ end
190
+ }
191
+
192
+ cookie = FFI::MemoryPointer.new(:void)
193
+
194
+ rv = SLPFindSrvs(@handle, type, scope, filter, callback, cookie)
195
+
196
+ if rv != SLP_OK
197
+ raise SystemCallError.new('SLPFindSrvs', rv)
198
+ end
199
+
200
+ arr
201
+ end
202
+
203
+ # The find_service_types method issues an SLP service type request for
204
+ # service types indicated by the scope parameter, limited by the naming
205
+ # authority +auth+.
206
+ #
207
+ # The default naming authority is '*', i.e. all naming authorities. A
208
+ # blank string will result in the default naming authority of IANA.
209
+ #
210
+ # A blank +scope+ parameter will use scopes this machine is configured for.
211
+ #
212
+ # Returns an array of service type names.
213
+ #
214
+ def find_service_types(auth = '*', scope = '')
215
+ arr = []
216
+
217
+ callback = Proc.new{ |hslp, types, err, cookie|
218
+ if err == SLP_OK
219
+ arr << types
220
+ true
221
+ else
222
+ false
223
+ end
224
+ }
225
+
226
+ cookie = FFI::MemoryPointer.new(:void)
227
+
228
+ rv = SLPFindSrvTypes(@handle, auth, scope, callback, cookie)
229
+
230
+ if rv != SLP_OK
231
+ raise SystemCallError.new('SLPFindSrvs', rv)
232
+ end
233
+
234
+ arr
235
+ end
236
+
237
+ # Return a list of service attributes matching the +attrs+ for the
238
+ # indicated service +url+ using the given +scope+.
239
+ #
240
+ # A blank +scope+ parameter will use scopes this machine is configured for.
241
+ #
242
+ def find_service_attributes(url, attrs = '', scope = '')
243
+ arr = []
244
+
245
+ callback = Proc.new{ |hslp, attrlist, err, cookie|
246
+ if err == SLP_OK
247
+ arr << attrlist
248
+ true
249
+ else
250
+ false
251
+ end
252
+ }
253
+
254
+ cookie = FFI::MemoryPointer.new(:void)
255
+
256
+ rv = SLPFindAttrs(@handle, url, scope, attrs, callback, cookie)
257
+
258
+ if rv != SLP_OK
259
+ raise SystemCallError.new('SLPFindSrvs', rv)
260
+ end
261
+
262
+ arr
263
+ end
264
+
265
+ # Singleton methods
266
+
267
+ # Returns the minimum refresh interval that will be accepted by all SLP
268
+ # agents on the network. If no agents advertise a minimum refresh interval
269
+ # then zero is returned, though that is not a valid lifetime parameter to
270
+ # other methods.
271
+ #
272
+ def self.refresh_interval
273
+ SLPGetRefreshInterval()
274
+ end
275
+
276
+ # Returns the value of the SLP property +name+.
277
+ #
278
+ def self.get_property(name)
279
+ SLPGetProperty(name)
280
+ end
281
+
282
+ # Sets the value of the SLP property +prop+ to +name+.
283
+ #
284
+ def self.set_property(prop, name)
285
+ SLPSetProperty(prop, name)
286
+ name
287
+ end
288
+
289
+ # Parses a Service URL string and returns SLPSrvURL struct.
290
+ #
291
+ def self.parse_service_url(url)
292
+ begin
293
+ pptr = FFI::MemoryPointer.new(SLPSrvURL)
294
+
295
+ if SLPParseSrvURL(url, pptr) != SLP_OK
296
+ raise SystemCallError.new('SLPParseSrvURL', FFI.errno)
297
+ end
298
+
299
+ ptr = pptr.read_pointer
300
+ struct = SLPSrvURL.new(ptr)
301
+ ensure
302
+ SLPFree(ptr)
303
+ end
304
+
305
+ struct
306
+ end
307
+
308
+ # Process the +string+ to escape any SLP reserved characters. If the
309
+ # +istag_ parameter is true then it will look for bad tag characters.
310
+ #
311
+ def self.escape_reserved(string, istag = true)
312
+ begin
313
+ pptr = FFI::MemoryPointer.new(:pointer)
314
+
315
+ if SLPEscape(string, pptr, istag) != SLP_OK
316
+ raise SystemCallError.new('SLPEscape', FFI.errno)
317
+ end
318
+
319
+ str = pptr.read_pointer.read_string
320
+ ensure
321
+ SLPFree(pptr.read_pointer)
322
+ end
323
+
324
+ str
325
+ end
326
+
327
+ # Process the +string+ to unescape any SLP reserved characters. If the
328
+ # +istag_ parameter is true then it will look for bad tag characters.
329
+ #
330
+ def self.unescape_reserved(string, istag = true)
331
+ begin
332
+ pptr = FFI::MemoryPointer.new(:pointer)
333
+
334
+ if SLPUnescape(string, pptr, istag) != SLP_OK
335
+ raise SystemCallError.new('SLPEscape', FFI.errno)
336
+ end
337
+
338
+ str = pptr.read_pointer.read_string
339
+ ensure
340
+ SLPFree(pptr.read_pointer)
341
+ end
342
+
343
+ str
344
+ end
345
+ end
346
+ end
@@ -0,0 +1,13 @@
1
+ module OpenSLP
2
+ module Constants
3
+ SLP_OK = 0
4
+
5
+ SLP_LIFETIME_DEFAULT = 10800
6
+ SLP_LIFETIME_MAXIMUM = 65535
7
+
8
+ SLP_FALSE = 0
9
+ SLP_TRUE = 1
10
+
11
+ SLP_LAST_CALL = 1
12
+ end
13
+ end
@@ -0,0 +1,54 @@
1
+ require 'ffi'
2
+
3
+ module OpenSLP
4
+ module Functions
5
+ extend FFI::Library
6
+
7
+ # Look for either slp or libslip
8
+ begin
9
+ ffi_lib :libslp
10
+ rescue LoadError
11
+ begin
12
+ ffi_lib :slp
13
+ rescue LoadError
14
+ if File::ALT_SEPARATOR
15
+ ffi_lib "C:/Program Files (x86)/OpenSLP/slp"
16
+ else
17
+ raise
18
+ end
19
+ end
20
+ end
21
+
22
+ typedef :ulong, :handle
23
+
24
+ callback :SLPSrvURLCallback, [:handle, :string, :ushort, :int, :pointer], :bool
25
+ callback :SLPSrvTypeCallback, [:handle, :string, :int, :pointer], :bool
26
+ callback :SLPAttrCallback, [:handle, :string, :int, :pointer], :bool
27
+ callback :SLPRegReportCallback, [:handle, :int, :pointer], :void
28
+
29
+ attach_function :SLPClose, [:handle], :void
30
+ attach_function :SLPEscape, [:string, :pointer, :bool], :int
31
+ attach_function :SLPDelAttrs, [:handle, :string, :string, :SLPRegReportCallback, :pointer], :int
32
+ attach_function :SLPDereg, [:handle, :string, :SLPRegReportCallback, :pointer], :int
33
+
34
+ attach_function :SLPFindAttrs,
35
+ [:handle, :string, :string, :string, :SLPAttrCallback, :pointer], :int
36
+
37
+ attach_function :SLPFindScopes, [:handle, :pointer], :int
38
+
39
+ attach_function :SLPFindSrvs,
40
+ [:handle, :string, :string, :string, :SLPSrvURLCallback, :pointer], :int
41
+
42
+ attach_function :SLPFindSrvTypes,
43
+ [:handle, :string, :string, :SLPSrvTypeCallback, :pointer], :int
44
+
45
+ attach_function :SLPFree, [:pointer], :void
46
+ attach_function :SLPGetProperty, [:string], :string
47
+ attach_function :SLPGetRefreshInterval, [], :uint
48
+ attach_function :SLPOpen, [:string, :bool, :pointer], :handle
49
+ attach_function :SLPParseSrvURL, [:string, :pointer], :int
50
+ attach_function :SLPReg, [:handle, :string, :ushort, :string, :string, :bool, :SLPRegReportCallback, :pointer], :int
51
+ attach_function :SLPSetProperty, [:string, :string], :void
52
+ attach_function :SLPUnescape, [:string, :pointer, :bool], :int
53
+ end
54
+ end
data/lib/slp/helper.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'ffi'
2
+
3
+ class FFI::Pointer
4
+ def read_array_of_string
5
+ elements = []
6
+
7
+ loc = self
8
+
9
+ until ((element = loc.read_pointer).null?)
10
+ elements << element.read_string
11
+ loc += FFI::Type::POINTER.size
12
+ end
13
+
14
+ elements
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require 'ffi'
2
+
3
+ module OpenSLP
4
+ module Structs
5
+ class SLPSrvURL < FFI::Struct
6
+ layout(
7
+ :s_pcSrvType, :string,
8
+ :s_pcHost, :string,
9
+ :s_iPort, :int,
10
+ :s_pcNetFamily, :string,
11
+ :s_pcSrvPart, :string
12
+ )
13
+ end
14
+ end
15
+ end
data/rslp.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'rbconfig'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'rslp'
6
+ spec.version = '0.0.1'
7
+ spec.license = 'Apache-2.0'
8
+ spec.author = 'Daniel J. Berger'
9
+ spec.email = 'djberg96@gmail.com'
10
+ spec.homepage = 'https://github.com/djberg96/rslp'
11
+ spec.summary = 'Interface for the OpenSLP library'
12
+ spec.test_files = Dir['spec/*.rb']
13
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
14
+ spec.cert_chain = ['certs/djberg96_pub.pem']
15
+
16
+ spec.extra_rdoc_files = ['README.md', 'CHANGES.md', 'MANIFEST.md', 'LICENSE']
17
+
18
+ spec.add_dependency('ffi', "~> 1.1")
19
+
20
+ spec.add_development_dependency('rake')
21
+ spec.add_development_dependency('rspec', "~> 3.9")
22
+
23
+ spec.metadata = {
24
+ 'homepage_uri' => 'https://github.com/djberg96/rslp',
25
+ 'bug_tracker_uri' => 'https://github.com/djberg96/rslp/issues',
26
+ 'changelog_uri' => 'https://github.com/djberg96/rslp/blob/main/CHANGES.md',
27
+ 'documentation_uri' => 'https://github.com/djberg96/rslp/wiki',
28
+ 'source_code_uri' => 'https://github.com/djberg96/rslp',
29
+ 'wiki_uri' => 'https://github.com/djberg96/rslp/wiki'
30
+ }
31
+
32
+ spec.description = <<-EOF
33
+ The rslp library is an FFI interface for the OpenSLP service
34
+ location protocol library.
35
+ EOF
36
+ end
data/spec/rslp_spec.rb ADDED
@@ -0,0 +1,76 @@
1
+ ########################################################################
2
+ # rslp_spec.rb
3
+ #
4
+ # Test suite for the rslp library.
5
+ ########################################################################
6
+ require 'rspec'
7
+ require 'rslp'
8
+
9
+ describe OpenSLP::SLP do
10
+ before do
11
+ @lang = 'en-us'
12
+ @slp = OpenSLP::SLP.new(@lang, false)
13
+ end
14
+
15
+ context "version" do
16
+ example "version is set to the expected value" do
17
+ expect(OpenSLP::SLP::VERSION).to eq('0.0.1')
18
+ end
19
+ end
20
+
21
+ context "constructor" do
22
+ example "defaults to an empty string if no lang is provided" do
23
+ expect(OpenSLP::SLP.new.lang).to eq('')
24
+ end
25
+
26
+ example "defaults to a false async value if no value is provided" do
27
+ expect(OpenSLP::SLP.new.async).to be false
28
+ end
29
+
30
+ example "sets attributes to expected values" do
31
+ expect(@slp.lang).to eq(@lang)
32
+ expect(@slp.async).to be false
33
+ end
34
+ end
35
+
36
+ context "singleton methods" do
37
+ example "defines a refresh_interval method" do
38
+ expect(OpenSLP::SLP).to respond_to(:refresh_interval)
39
+ end
40
+
41
+ example "returns the expected value for refresh_interval" do
42
+ expect(OpenSLP::SLP.refresh_interval).to eq(0)
43
+ end
44
+
45
+ example "defines a get_property method" do
46
+ expect(OpenSLP::SLP).to respond_to(:get_property)
47
+ end
48
+
49
+ example "defines a set_property method" do
50
+ expect(OpenSLP::SLP).to respond_to(:set_property)
51
+ end
52
+
53
+ example "defines a parse_service_url method" do
54
+ expect(OpenSLP::SLP).to respond_to(:parse_service_url)
55
+ end
56
+
57
+ example "defines a escape_reserved method" do
58
+ expect(OpenSLP::SLP).to respond_to(:escape_reserved)
59
+ end
60
+
61
+ example "returns the expected value for the escape_reserved method" do
62
+ expected = "\\2Ctag-example\\2C"
63
+ expect(OpenSLP::SLP.escape_reserved(",tag-example,")).to eq(expected)
64
+ end
65
+
66
+ example "defines a unescape_reserved method" do
67
+ expect(OpenSLP::SLP).to respond_to(:unescape_reserved)
68
+ end
69
+ end
70
+
71
+ after do
72
+ @slp.close if @slp
73
+ @slp = nil
74
+ @lang = nil
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rslp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel J. Berger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
14
+ cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
15
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
16
+ ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
17
+ bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
18
+ A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
19
+ u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
20
+ 75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
21
+ 6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
22
+ iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
23
+ ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
24
+ 74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
25
+ 058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
26
+ HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
27
+ AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
28
+ YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
29
+ /3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
30
+ h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
31
+ 6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
32
+ ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
33
+ 1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
34
+ DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
35
+ ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
+ -----END CERTIFICATE-----
38
+ date: 2021-07-02 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: ffi
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.1'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.1'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rake
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rspec
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.9'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.9'
82
+ description: |2
83
+ The rslp library is an FFI interface for the OpenSLP service
84
+ location protocol library.
85
+ email: djberg96@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files:
89
+ - README.md
90
+ - CHANGES.md
91
+ - MANIFEST.md
92
+ - LICENSE
93
+ files:
94
+ - CHANGES.md
95
+ - Gemfile
96
+ - LICENSE
97
+ - MANIFEST.md
98
+ - README.md
99
+ - Rakefile
100
+ - certs/djberg96_pub.pem
101
+ - lib/rslp.rb
102
+ - lib/slp/constants.rb
103
+ - lib/slp/functions.rb
104
+ - lib/slp/helper.rb
105
+ - lib/slp/structs.rb
106
+ - rslp.gemspec
107
+ - spec/rslp_spec.rb
108
+ homepage: https://github.com/djberg96/rslp
109
+ licenses:
110
+ - Apache-2.0
111
+ metadata:
112
+ homepage_uri: https://github.com/djberg96/rslp
113
+ bug_tracker_uri: https://github.com/djberg96/rslp/issues
114
+ changelog_uri: https://github.com/djberg96/rslp/blob/main/CHANGES.md
115
+ documentation_uri: https://github.com/djberg96/rslp/wiki
116
+ source_code_uri: https://github.com/djberg96/rslp
117
+ wiki_uri: https://github.com/djberg96/rslp/wiki
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubygems_version: 3.2.15
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Interface for the OpenSLP library
137
+ test_files:
138
+ - spec/rslp_spec.rb
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ "��y��b�i� o�[Zb�S��D�Y�@P,k���̘�����K
2
+ �V��A��/�ɢ�`L��^�4kw`m<D�6��2�R�h<ѩ��� ��0���j��c2�k�� ҹ�0u�S�0�ۃ<��c�44�)��cK�]k�f��dt]�C}.;C s����YYX����x���c��?C�