cupsffi 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -59,3 +59,12 @@ Nothing required. libcups is used to find and read all configuration.
59
59
 
60
60
  # Cancel all outstanding jobs on the printer
61
61
  printer.cancel_all_jobs
62
+
63
+ == Remote CUPS Server
64
+
65
+ You may pass in :hostname and :port arguments when creating a CupsPrinter instance or querying
66
+ for available printers.
67
+
68
+ remote_printers = CupsPrinter.get_all_printer_names(:hostname => 'print.example.com')
69
+ print = CupsPrinter.new(remote_printers.first, :hostname => 'print.example.com')
70
+
data/lib/cupsffi/lib.rb CHANGED
@@ -25,14 +25,12 @@ require 'ffi'
25
25
  module CupsFFI
26
26
  extend FFI::Library
27
27
 
28
- paths =
29
- Array(
30
- ENV['CUPS_LIB'] ||
31
- Dir['/{opt,usr}/{,local/}lib{,64}/{,x86_64-linux-gnu/,i386-linux-gnu/}libcups.{dylib,so*}']
32
- )
33
- raise LoadError, "Didn't find libcups on your system." if paths.empty?
34
28
  begin
35
- ffi_lib(*paths)
29
+ if ENV['CUPS_LIB']
30
+ ffi_lib(ENV['CUPS_LIB'])
31
+ else
32
+ ffi_lib('cups')
33
+ end
36
34
  rescue LoadError => le
37
35
  raise LoadError, "Didn't find libcups on your system."
38
36
  end
@@ -172,10 +170,14 @@ module CupsFFI
172
170
 
173
171
 
174
172
 
173
+ attach_function 'cupsEncryption', [], :int
174
+ attach_function 'httpConnectEncrypt', [ :string, :int, :int], :pointer
175
175
 
176
176
 
177
177
  attach_function 'cupsGetDests', [ :pointer ], :int
178
178
 
179
+ attach_function 'cupsGetDests2', [ :pointer, :pointer ], :int
180
+
179
181
  # :int is the number of CupsDestS structs to free
180
182
  # :pointer is the first one
181
183
  attach_function 'cupsFreeDests', [ :int, :pointer ], :void
@@ -190,6 +192,8 @@ module CupsFFI
190
192
  # - job number or 0 on error
191
193
  attach_function 'cupsPrintFile', [ :string, :string, :string, :int, :pointer ], :int
192
194
 
195
+ attach_function 'cupsPrintFile2', [ :pointer, :string, :string, :string, :int, :pointer ], :int
196
+
193
197
  attach_function 'cupsLastErrorString', [], :string
194
198
 
195
199
  # Parameters
@@ -197,6 +201,8 @@ module CupsFFI
197
201
  # - job id
198
202
  attach_function 'cupsCancelJob', [:string, :int], :void
199
203
 
204
+ attach_function 'cupsCancelJob2', [:pointer, :string, :int], :void
205
+
200
206
  # Parameters
201
207
  # - pointer to struct CupsJobS to populate
202
208
  # - printer name
@@ -252,6 +258,7 @@ module CupsFFI
252
258
  # Returns
253
259
  # - filename for PPD file
254
260
  attach_function 'cupsGetPPD', [:string], :string
261
+ attach_function 'cupsGetPPD2', [:pointer, :string], :string
255
262
 
256
263
  # Parameters
257
264
  # - option name
data/lib/cupsffi/ppd.rb CHANGED
@@ -21,8 +21,8 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  class CupsPPD
24
- def initialize(printer_name)
25
- @file = CupsFFI::cupsGetPPD(printer_name)
24
+ def initialize(printer_name, connection)
25
+ @file = CupsFFI::cupsGetPPD2(connection, printer_name)
26
26
  raise "No PPD found for #{printer_name}" if @file.nil?
27
27
 
28
28
  @pointer = CupsFFI::ppdOpenFile(@file)
@@ -21,16 +21,33 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  class CupsPrinter
24
- attr_reader :name
24
+ attr_reader :name, :connection
25
25
 
26
- def initialize(name)
27
- raise "Printer not found" unless CupsPrinter.get_all_printer_names.include? name
26
+ def self.get_connection(args = {})
27
+ hostname = args[:hostname]
28
+ port = args[:port] || 631
29
+
30
+ if hostname.nil?
31
+ return CupsFFI::CUPS_HTTP_DEFAULT
32
+ else
33
+ connection = CupsFFI::httpConnectEncrypt(hostname, port.to_i, CupsFFI::cupsEncryption())
34
+ raise "Printserver at #{hostname}:#{port} not available" if connection.null?
35
+
36
+ return connection
37
+ end
38
+ end
39
+
40
+ def initialize(name, args = {})
41
+ raise "Printer not found" unless CupsPrinter.get_all_printer_names(args).include? name
28
42
  @name = name
43
+ @connection = CupsPrinter.get_connection(args)
29
44
  end
30
45
 
31
- def self.get_all_printer_names
46
+ def self.get_all_printer_names(args = {})
47
+ connection = get_connection(args)
48
+
32
49
  p = FFI::MemoryPointer.new :pointer
33
- dest_count = CupsFFI::cupsGetDests(p)
50
+ dest_count = CupsFFI::cupsGetDests2(connection, p)
34
51
  ary = []
35
52
  dest_count.times do |i|
36
53
  d = CupsFFI::CupsDestS.new(p.get_pointer(0) + (CupsFFI::CupsDestS.size * i))
@@ -42,7 +59,7 @@ class CupsPrinter
42
59
 
43
60
  def attributes
44
61
  p = FFI::MemoryPointer.new :pointer
45
- dest_count = CupsFFI::cupsGetDests(p)
62
+ dest_count = CupsFFI::cupsGetDests2(@connection, p)
46
63
  hash = {}
47
64
  dest_count.times do |i|
48
65
  dest = CupsFFI::CupsDestS.new(p.get_pointer(0) + (CupsFFI::CupsDestS.size * i))
@@ -85,7 +102,7 @@ class CupsPrinter
85
102
  options_pointer = options_pointer.get_pointer(0)
86
103
  end
87
104
 
88
- job_id = CupsFFI::cupsPrintFile(@name, file_name, file_name, num_options, options_pointer)
105
+ job_id = CupsFFI::cupsPrintFile2(@connection, @name, file_name, file_name, num_options, options_pointer)
89
106
 
90
107
  if job_id == 0
91
108
  last_error = CupsFFI::cupsLastErrorString()
@@ -109,19 +126,19 @@ class CupsPrinter
109
126
  options_pointer = options_pointer.get_pointer(0)
110
127
  end
111
128
 
112
- job_id = CupsFFI::cupsCreateJob(CupsFFI::CUPS_HTTP_DEFAULT, @name, 'data job', num_options, options_pointer)
129
+ job_id = CupsFFI::cupsCreateJob(@connection, @name, 'data job', num_options, options_pointer)
113
130
  if job_id == 0
114
131
  last_error = CupsFFI::cupsLastErrorString()
115
132
  CupsFFI::cupsFreeOptions(num_options, options_pointer) unless options_pointer.nil?
116
133
  raise last_error
117
134
  end
118
135
 
119
- http_status = CupsFFI::cupsStartDocument(CupsFFI::CUPS_HTTP_DEFAULT, @name,
136
+ http_status = CupsFFI::cupsStartDocument(@connection, @name,
120
137
  job_id, 'my doc', mime_type, 1)
121
138
 
122
- http_status = CupsFFI::cupsWriteRequestData(CupsFFI::CUPS_HTTP_DEFAULT, data, data.length)
139
+ http_status = CupsFFI::cupsWriteRequestData(@connection, data, data.length)
123
140
 
124
- ipp_status = CupsFFI::cupsFinishDocument(CupsFFI::CUPS_HTTP_DEFAULT, @name)
141
+ ipp_status = CupsFFI::cupsFinishDocument(@connection, @name)
125
142
 
126
143
  unless ipp_status == :ipp_ok
127
144
  CupsFFI::cupsFreeOptions(num_options, options_pointer) unless options_pointer.nil?
@@ -133,14 +150,14 @@ class CupsPrinter
133
150
  end
134
151
 
135
152
  def cancel_all_jobs
136
- r = CupsFFI::cupsCancelJob(@name, CupsFFI::CUPS_JOBID_ALL)
153
+ r = CupsFFI::cupsCancelJob2(@connection, @name, CupsFFI::CUPS_JOBID_ALL)
137
154
  raise CupsFFI::cupsLastErrorString() if r == 0
138
155
  end
139
156
 
140
157
 
141
158
  private
142
159
  def validate_options(options)
143
- ppd = CupsPPD.new(@name)
160
+ ppd = CupsPPD.new(@name, @connection)
144
161
 
145
162
  # Build a hash of the ppd options for quick lookup
146
163
  ppd_options = {}
@@ -1,3 +1,3 @@
1
1
  module Cupsffi
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,49 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cupsffi
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
4
5
  prerelease:
5
- version: 0.0.9
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Nathan Ehresman
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-12-03 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2013-04-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: ffi
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: ffi
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: ffi
32
+ requirement: !ruby/object:Gem::Requirement
30
33
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
35
38
  type: :runtime
36
- version_requirements: *id002
37
- description: Simple wrapper around libcups to give CUPS printing capabilities to Ruby apps.
38
- email:
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Simple wrapper around libcups to give CUPS printing capabilities to Ruby
47
+ apps.
48
+ email:
39
49
  - nehresma@gmail.com
40
50
  executables: []
41
-
42
51
  extensions: []
43
-
44
52
  extra_rdoc_files: []
45
-
46
- files:
53
+ files:
47
54
  - .gitignore
48
55
  - COPYING
49
56
  - Gemfile
@@ -58,30 +65,26 @@ files:
58
65
  - lib/cupsffi/version.rb
59
66
  homepage: http://www.tebros.com/
60
67
  licenses: []
61
-
62
68
  post_install_message:
63
69
  rdoc_options: []
64
-
65
- require_paths:
70
+ require_paths:
66
71
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
72
+ required_ruby_version: !ruby/object:Gem::Requirement
68
73
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: "0"
73
- required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
79
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
79
84
  requirements: []
80
-
81
85
  rubyforge_project: cupsffi
82
- rubygems_version: 1.8.13
86
+ rubygems_version: 1.8.24
83
87
  signing_key:
84
88
  specification_version: 3
85
89
  summary: FFI wrapper around libcups
86
90
  test_files: []
87
-