cups 0.0.7 → 0.1.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/ext/cups.c CHANGED
@@ -6,7 +6,6 @@ VALUE rubyCups, printJobs;
6
6
  // Need to abstract this out of cups.c
7
7
  VALUE ipp_state_to_symbol(int state)
8
8
  {
9
-
10
9
  VALUE jstate;
11
10
 
12
11
  switch (state) {
@@ -58,6 +57,7 @@ static VALUE job_init(int argc, VALUE* argv, VALUE self)
58
57
  rb_scan_args(argc, argv, "12", &filename, &printer, &job_options);
59
58
 
60
59
  rb_iv_set(self, "@filename", filename);
60
+ rb_iv_set(self, "@url_path", rb_str_new2(cupsServer()));
61
61
 
62
62
  if (NIL_P(job_options)) {
63
63
  rb_iv_set(self, "@job_options", rb_hash_new());
@@ -110,55 +110,53 @@ static VALUE cups_print(VALUE self)
110
110
  int job_id;
111
111
  VALUE file = rb_iv_get(self, "@filename");
112
112
  VALUE printer = rb_iv_get(self, "@printer");
113
+ VALUE url_path = rb_iv_get(self, "@url_path");
113
114
 
114
115
  char *fname = RSTRING_PTR(file); // Filename
115
116
  char *target = RSTRING_PTR(printer); // Target printer string
117
+ char *url = RSTRING_PTR(url_path); // Server URL address
118
+ int port = 631; // Default CUPS port
119
+
120
+ VALUE job_options = rb_iv_get(self, "@job_options");
116
121
 
117
- FILE *fp = fopen(fname,"r");
118
- // Check @filename actually exists...
119
- if( fp ) {
120
- fclose(fp);
121
-
122
- VALUE job_options = rb_iv_get(self, "@job_options");
123
-
124
- // Create an array of the keys from the job_options hash
125
- VALUE job_options_keys = rb_ary_new();
126
- rb_hash_foreach(job_options, cups_keys_i, job_options_keys);
122
+ // Create an array of the keys from the job_options hash
123
+ VALUE job_options_keys = rb_ary_new();
124
+ rb_hash_foreach(job_options, cups_keys_i, job_options_keys);
127
125
 
128
- VALUE iter;
129
- int num_options = 0;
130
- cups_option_t *options = NULL;
131
-
132
- // foreach option in the job options array
133
- while (! NIL_P(iter = rb_ary_pop(job_options_keys))) {
126
+ VALUE iter;
127
+ int num_options = 0;
128
+ cups_option_t *options = NULL;
134
129
 
135
- VALUE value = rb_hash_aref(job_options, iter);
130
+ // foreach option in the job options array
131
+ while (! NIL_P(iter = rb_ary_pop(job_options_keys))) {
136
132
 
137
- // assert the key and value are strings
138
- if (NIL_P(rb_check_string_type(iter)) || NIL_P(rb_check_string_type(value))) {
139
- cupsFreeOptions(num_options, options);
140
- rb_raise(rb_eTypeError, "job options is not string => string hash");
141
- return Qfalse;
142
- }
133
+ VALUE value = rb_hash_aref(job_options, iter);
143
134
 
144
- // convert to char pointers and add to cups optoins
145
- char * iter_str = rb_string_value_ptr(&iter);
146
- char * value_str = rb_string_value_ptr(&value);
147
- cupsAddOption(iter_str, value_str, num_options++, &options);
135
+ // assert the key and value are strings
136
+ if (NIL_P(rb_check_string_type(iter)) || NIL_P(rb_check_string_type(value))) {
137
+ cupsFreeOptions(num_options, options);
138
+ rb_raise(rb_eTypeError, "job options is not string => string hash");
139
+ return Qfalse;
148
140
  }
149
141
 
150
- job_id = cupsPrintFile(target, fname, "rCUPS", num_options, options); // Do it. "rCups" should be the filename/path
151
-
152
- cupsFreeOptions(num_options, options);
153
-
154
- rb_iv_set(self, "@job_id", INT2NUM(job_id));
142
+ // convert to char pointers and add to cups optoins
143
+ char * iter_str = rb_string_value_ptr(&iter);
144
+ char * value_str = rb_string_value_ptr(&value);
145
+ cupsAddOption(iter_str, value_str, num_options++, &options);
146
+ }
155
147
 
156
- return Qtrue;
157
- } else {
158
- // and if it doesn't...
159
- rb_raise(rb_eRuntimeError, "Couldn't find file");
160
- return Qfalse;
148
+ if(NIL_P(url)) {
149
+ url = cupsServer();
161
150
  }
151
+
152
+ int encryption = (http_encryption_t)cupsEncryption();
153
+ http_t *http = httpConnectEncrypt (url, port, (http_encryption_t) encryption);
154
+ job_id = cupsPrintFile2(http, target, fname, "rCups", num_options, options); // Do it. "rCups" should be the filename/path
155
+ //
156
+ // cupsFreeOptions(num_options, options);
157
+
158
+ rb_iv_set(self, "@job_id", INT2NUM(job_id));
159
+ return Qtrue;
162
160
  }
163
161
 
164
162
  /*
@@ -178,6 +176,8 @@ static VALUE cups_show_dests(VALUE self)
178
176
  VALUE destination = rb_str_new2(dest->name);
179
177
  rb_ary_push(dest_list, destination); // Add this testination name to dest_list string
180
178
  }
179
+
180
+ cupsFreeDests(num_dests, dests);
181
181
  return dest_list;
182
182
  }
183
183
 
@@ -194,6 +194,7 @@ static VALUE cups_get_default(VALUE self)
194
194
 
195
195
  if (default_printer != NULL) {
196
196
  VALUE def_p = rb_str_new2(default_printer);
197
+
197
198
  return def_p;
198
199
  }
199
200
  // should return nil if no default printer is found!
@@ -309,7 +310,6 @@ static VALUE cups_get_job_state(VALUE self)
309
310
  cupsFreeJobs(num_jobs, jobs);
310
311
 
311
312
  jstate = ipp_state_to_symbol(job_state);
312
-
313
313
  return jstate;
314
314
  }
315
315
  }
@@ -407,10 +407,69 @@ static VALUE cups_get_jobs(VALUE self, VALUE printer)
407
407
 
408
408
  // Free job array
409
409
  cupsFreeJobs(num_jobs, jobs);
410
-
411
410
  return job_list;
412
411
  }
413
412
 
413
+ /*
414
+ * call-seq:
415
+ * Cups.cancel_print(cups_id, printer_name) -> true or false
416
+ *
417
+ * Cancel the print job. Returns true if successful, false otherwise.
418
+ */
419
+ static VALUE cups_cancel_print(int argc, VALUE* argv, VALUE self)
420
+ {
421
+ VALUE printer, job_id;
422
+ rb_scan_args(argc, argv, "20", &job_id, &printer);
423
+
424
+ if (NIL_P(job_id)) {
425
+ return Qfalse; // If @job_id is nil
426
+ } else { // Otherwise attempt to cancel
427
+ int job = NUM2INT(job_id);
428
+ char *target = RSTRING_PTR(printer); // Target printer string
429
+ int cancellation;
430
+ cancellation = cupsCancelJob(target, job);
431
+
432
+ return Qtrue;
433
+ }
434
+ }
435
+
436
+ /*
437
+ * call-seq:
438
+ * Cups.device_uri_for(printer_name) -> String
439
+ *
440
+ * Return uri for requested printer.
441
+ */
442
+ static VALUE cups_get_device_uri(VALUE self, VALUE printer)
443
+ {
444
+ if (!printer_exists(printer))
445
+ {
446
+ rb_raise(rb_eRuntimeError, "The printer or destination doesn't exist!");
447
+ }
448
+
449
+ VALUE options_list;
450
+ http_t *http;
451
+ ipp_t *request;
452
+ ipp_t *response;
453
+ ipp_attribute_t *attr;
454
+ char uri[1024];
455
+ char *location;
456
+ char *name = RSTRING_PTR(printer);
457
+
458
+ request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
459
+ httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/printers/%s", name);
460
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
461
+
462
+ if ((response = cupsDoRequest(http, request, "/")) != NULL)
463
+ {
464
+ if((attr = ippFindAttribute(response, "device-uri", IPP_TAG_URI)) != NULL)
465
+ {
466
+ return rb_str_new2(attr->values[0].string.text);
467
+ }
468
+ ippDelete(response);
469
+ }
470
+ return Qtrue;
471
+ }
472
+
414
473
  /*
415
474
  * call-seq:
416
475
  * Cups.options_for(name) -> Hash or nil
@@ -436,13 +495,12 @@ static VALUE cups_get_options(VALUE self, VALUE printer)
436
495
  cups_dest_t *dest = cupsGetDest(printer_arg, NULL, num_dests, dests);
437
496
 
438
497
  if (dest == NULL) {
439
- cupsFreeDests(num_dests, dests);
498
+ cupsFreeDests(num_dests, dests);
440
499
  return Qnil;
441
500
  } else {
442
501
  for(i =0; i< dest->num_options; i++) {
443
502
  rb_hash_aset(options_list, rb_str_new2(dest->options[i].name), rb_str_new2(dest->options[i].value));
444
503
  }
445
-
446
504
  cupsFreeDests(num_dests, dests);
447
505
  return options_list;
448
506
  }
@@ -459,6 +517,7 @@ void Init_cups() {
459
517
  // Cups::PrintJob Attributes
460
518
  rb_define_attr(printJobs, "printer", 1, 0);
461
519
  rb_define_attr(printJobs, "filename", 1, 0);
520
+ rb_define_attr(printJobs, "url_path", 1, 0);
462
521
  rb_define_attr(printJobs, "job_id", 1, 0);
463
522
  rb_define_attr(printJobs, "job_options", 1, 0);
464
523
 
@@ -476,5 +535,8 @@ void Init_cups() {
476
535
  rb_define_singleton_method(rubyCups, "show_destinations", cups_show_dests, 0);
477
536
  rb_define_singleton_method(rubyCups, "default_printer", cups_get_default, 0);
478
537
  rb_define_singleton_method(rubyCups, "all_jobs", cups_get_jobs, 1);
538
+ rb_define_singleton_method(rubyCups, "cancel_print", cups_cancel_print, -1);
479
539
  rb_define_singleton_method(rubyCups, "options_for", cups_get_options, 1);
480
- }
540
+ rb_define_singleton_method(rubyCups, "device_uri_for", cups_get_device_uri, 1);
541
+ rb_define_singleton_method(rubyCups, "get_connection_for", cups_get_device_uri, 1);
542
+ }
data/ext/extconf.rb CHANGED
@@ -5,11 +5,18 @@ unless have_library("cups") && find_executable("cups-config")
5
5
  exit
6
6
  end
7
7
 
8
+ def has_cups_1_6_installed?
9
+ puts 'cups version:'
10
+ puts `cups-config --version`
11
+ `cups-config --version`.scan(/1.6/).size > 0
12
+ end
13
+
8
14
  cups_cflags = `cups-config --cflags`.chomp || ""
15
+ cups_cflags += ' -D_IPP_PRIVATE_STRUCTURES' if has_cups_1_6_installed?
9
16
  cups_libs = `cups-config --libs`.chomp || ""
10
17
 
11
18
  with_cflags(cups_cflags) {
12
19
  with_ldflags(cups_libs) {
13
20
  create_makefile("cups")
14
21
  }
15
- }
22
+ }
data/ext/ruby_cups.h CHANGED
File without changes
File without changes
File without changes
data/test/cups_test.rb CHANGED
File without changes
data/test/sample.txt CHANGED
File without changes
File without changes
metadata CHANGED
@@ -1,72 +1,62 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cups
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 7
9
- version: 0.0.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
8
+ - Tadej Murovec
9
+ - Ivan Turkovic
12
10
  - Chris Mowforth
13
11
  autorequire:
14
12
  bindir: bin
15
13
  cert_chain: []
16
-
17
- date: 2010-11-12 00:00:00 +00:00
18
- default_executable:
14
+ date: 2013-04-28 00:00:00.000000000 Z
19
15
  dependencies: []
20
-
21
- description: " Ruby CUPS provides a wrapper for the Common UNIX Printing System, allowing rubyists to perform basic tasks like printer discovery, job submission & querying.\n"
22
- email:
16
+ description: ! ' Ruby CUPS provides a wrapper for the Common UNIX Printing System,
17
+ allowing rubyists to perform basic tasks like printer discovery, job submission
18
+ & querying.
19
+
20
+ '
21
+ email:
22
+ - tadej.murovec@gmail.com
23
+ - me@ivanturkovic.com
23
24
  - chris@mowforth.com
24
25
  executables: []
25
-
26
- extensions:
26
+ extensions:
27
27
  - ext/extconf.rb
28
28
  extra_rdoc_files: []
29
-
30
- files:
31
- - test/cups_test.rb
29
+ files:
32
30
  - test/sample.txt
33
31
  - test/sample_blank.txt
32
+ - test/cups_test.rb
34
33
  - ext/cups.c
35
34
  - ext/ruby_cups.h
36
35
  - ext/extconf.rb
37
36
  - lib/cups/print_job/transient.rb
38
37
  - lib/cups/printer/printer.rb
39
- has_rdoc: true
40
- homepage: http://cups.rubyforge.org/
38
+ homepage: https://github.com/m0wfo/cups
41
39
  licenses: []
42
-
43
40
  post_install_message:
44
41
  rdoc_options: []
45
-
46
- require_paths:
42
+ require_paths:
47
43
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
44
+ required_ruby_version: !ruby/object:Gem::Requirement
49
45
  none: false
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- version: "0"
56
- required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
51
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- segments:
62
- - 0
63
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
64
56
  requirements: []
65
-
66
57
  rubyforge_project: cups
67
- rubygems_version: 1.3.7
58
+ rubygems_version: 1.8.23
68
59
  signing_key:
69
60
  specification_version: 3
70
61
  summary: A lightweight Ruby library for printing.
71
62
  test_files: []
72
-