cups 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/cups.c +36 -35
- data/ext/ruby_cups.h +2 -7
- metadata +2 -2
data/ext/cups.c
CHANGED
@@ -10,7 +10,7 @@ VALUE ipp_state_to_symbol(int state)
|
|
10
10
|
|
11
11
|
switch (state) {
|
12
12
|
case IPP_JOB_PENDING :
|
13
|
-
jstate = ID2SYM(rb_intern("pending"));
|
13
|
+
jstate = ID2SYM(rb_intern("pending"));
|
14
14
|
break;
|
15
15
|
case IPP_JOB_HELD :
|
16
16
|
jstate = ID2SYM(rb_intern("held"));
|
@@ -53,12 +53,12 @@ int printer_exists(VALUE printer){
|
|
53
53
|
static VALUE job_init(int argc, VALUE* argv, VALUE self)
|
54
54
|
{
|
55
55
|
VALUE filename, printer, job_options;
|
56
|
-
|
56
|
+
|
57
57
|
rb_scan_args(argc, argv, "12", &filename, &printer, &job_options);
|
58
|
-
|
58
|
+
|
59
59
|
rb_iv_set(self, "@filename", filename);
|
60
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());
|
64
64
|
} else {
|
@@ -75,7 +75,7 @@ static VALUE job_init(int argc, VALUE* argv, VALUE self)
|
|
75
75
|
} else {
|
76
76
|
rb_iv_set(self, "@printer", def_p);
|
77
77
|
}
|
78
|
-
|
78
|
+
|
79
79
|
} else {
|
80
80
|
if (printer_exists(printer)) {
|
81
81
|
rb_iv_set(self, "@printer", printer);
|
@@ -150,15 +150,16 @@ static VALUE cups_print(VALUE self)
|
|
150
150
|
if(NIL_P(url)) {
|
151
151
|
url = cupsServer();
|
152
152
|
}
|
153
|
-
|
153
|
+
|
154
154
|
int encryption = (http_encryption_t)cupsEncryption();
|
155
|
-
http_t *http =
|
155
|
+
http_t *http = httpConnect2(url, port, NULL, AF_UNSPEC, (http_encryption_t) encryption, 1, 30000, NULL);
|
156
|
+
|
156
157
|
job_id = cupsPrintFile2(http, target, fname, title, num_options, options); // Do it. "rCups" should be the filename/path
|
157
|
-
//
|
158
|
+
//
|
158
159
|
// cupsFreeOptions(num_options, options);
|
159
|
-
|
160
|
+
|
160
161
|
rb_iv_set(self, "@job_id", INT2NUM(job_id));
|
161
|
-
return Qtrue;
|
162
|
+
return Qtrue;
|
162
163
|
}
|
163
164
|
|
164
165
|
/*
|
@@ -173,13 +174,13 @@ static VALUE cups_show_dests(VALUE self)
|
|
173
174
|
int i;
|
174
175
|
int num_dests = cupsGetDests(&dests); // Size of dest_list array
|
175
176
|
dest_list = rb_ary_new2(num_dests);
|
176
|
-
|
177
|
+
|
177
178
|
for (i = num_dests, dest = dests; i > 0; i --, dest ++) {
|
178
179
|
VALUE destination = rb_str_new2(dest->name);
|
179
180
|
rb_ary_push(dest_list, destination); // Add this testination name to dest_list string
|
180
181
|
}
|
181
|
-
|
182
|
-
cupsFreeDests(num_dests, dests);
|
182
|
+
|
183
|
+
cupsFreeDests(num_dests, dests);
|
183
184
|
return dest_list;
|
184
185
|
}
|
185
186
|
|
@@ -214,7 +215,7 @@ static VALUE cups_cancel(VALUE self)
|
|
214
215
|
VALUE printer, job_id;
|
215
216
|
printer = rb_iv_get(self, "@printer");
|
216
217
|
job_id = rb_iv_get(self, "@job_id");
|
217
|
-
|
218
|
+
|
218
219
|
if (NIL_P(job_id)) {
|
219
220
|
return Qfalse; // If @job_id is nil
|
220
221
|
} else { // Otherwise attempt to cancel
|
@@ -252,7 +253,7 @@ static VALUE cups_job_failed(VALUE self)
|
|
252
253
|
static VALUE cups_get_error_reason(VALUE self)
|
253
254
|
{
|
254
255
|
VALUE job_id = rb_iv_get(self, "@job_id");
|
255
|
-
|
256
|
+
|
256
257
|
if (NIL_P(job_id) || !NUM2INT(job_id) == 0) {
|
257
258
|
return Qnil;
|
258
259
|
} else {
|
@@ -270,7 +271,7 @@ static VALUE cups_get_error_reason(VALUE self)
|
|
270
271
|
static VALUE cups_get_error_code(VALUE self)
|
271
272
|
{
|
272
273
|
VALUE job_id = rb_iv_get(self, "@job_id");
|
273
|
-
|
274
|
+
|
274
275
|
if (NIL_P(job_id) || !NUM2INT(job_id) == 0) {
|
275
276
|
return Qnil;
|
276
277
|
} else {
|
@@ -290,13 +291,13 @@ static VALUE cups_get_job_state(VALUE self)
|
|
290
291
|
VALUE job_id = rb_iv_get(self, "@job_id");
|
291
292
|
VALUE printer = rb_iv_get(self, "@printer");
|
292
293
|
VALUE jstate;
|
293
|
-
|
294
|
+
|
294
295
|
int num_jobs;
|
295
296
|
cups_job_t *jobs;
|
296
297
|
ipp_jstate_t job_state = IPP_JOB_PENDING;
|
297
298
|
int i;
|
298
299
|
char *printer_arg = RSTRING_PTR(printer);
|
299
|
-
|
300
|
+
|
300
301
|
if (NIL_P(job_id)) {
|
301
302
|
return Qnil;
|
302
303
|
} else {
|
@@ -311,7 +312,7 @@ static VALUE cups_get_job_state(VALUE self)
|
|
311
312
|
|
312
313
|
// Free job array
|
313
314
|
cupsFreeJobs(num_jobs, jobs);
|
314
|
-
|
315
|
+
|
315
316
|
jstate = ipp_state_to_symbol(job_state);
|
316
317
|
return jstate;
|
317
318
|
}
|
@@ -378,7 +379,7 @@ static VALUE cups_get_jobs(VALUE self, VALUE printer)
|
|
378
379
|
if (!printer_exists(printer)){
|
379
380
|
rb_raise(rb_eRuntimeError, "The printer or destination doesn't exist!");
|
380
381
|
}
|
381
|
-
|
382
|
+
|
382
383
|
VALUE job_list, job_info_hash, jid, jtitle, juser, jsize, jformat, jstate;
|
383
384
|
int job_id;
|
384
385
|
int num_jobs;
|
@@ -386,10 +387,10 @@ static VALUE cups_get_jobs(VALUE self, VALUE printer)
|
|
386
387
|
ipp_jstate_t state;
|
387
388
|
int i;
|
388
389
|
char *printer_arg = RSTRING_PTR(printer);
|
389
|
-
|
390
|
+
|
390
391
|
num_jobs = cupsGetJobs(&jobs, printer_arg, 1, -1); // Get jobs
|
391
392
|
job_list = rb_hash_new();
|
392
|
-
|
393
|
+
|
393
394
|
for (i = 0; i < num_jobs; i ++) { // Construct a hash of individual job info
|
394
395
|
job_info_hash = rb_hash_new();
|
395
396
|
jid = INT2NUM(jobs[i].id);
|
@@ -404,7 +405,7 @@ static VALUE cups_get_jobs(VALUE self, VALUE printer)
|
|
404
405
|
rb_hash_aset(job_info_hash, ID2SYM(rb_intern("size")), jsize);
|
405
406
|
rb_hash_aset(job_info_hash, ID2SYM(rb_intern("format")), jformat);
|
406
407
|
rb_hash_aset(job_info_hash, ID2SYM(rb_intern("state")), jstate);
|
407
|
-
|
408
|
+
|
408
409
|
rb_hash_aset(job_list, jid, job_info_hash); // And push it all into job_list hash
|
409
410
|
}
|
410
411
|
|
@@ -423,7 +424,7 @@ static VALUE cups_cancel_print(int argc, VALUE* argv, VALUE self)
|
|
423
424
|
{
|
424
425
|
VALUE printer, job_id;
|
425
426
|
rb_scan_args(argc, argv, "20", &job_id, &printer);
|
426
|
-
|
427
|
+
|
427
428
|
if (NIL_P(job_id)) {
|
428
429
|
return Qfalse; // If @job_id is nil
|
429
430
|
} else { // Otherwise attempt to cancel
|
@@ -431,7 +432,7 @@ static VALUE cups_cancel_print(int argc, VALUE* argv, VALUE self)
|
|
431
432
|
char *target = RSTRING_PTR(printer); // Target printer string
|
432
433
|
int cancellation;
|
433
434
|
cancellation = cupsCancelJob(target, job);
|
434
|
-
|
435
|
+
|
435
436
|
return Qtrue;
|
436
437
|
}
|
437
438
|
}
|
@@ -442,29 +443,29 @@ static VALUE cups_cancel_print(int argc, VALUE* argv, VALUE self)
|
|
442
443
|
*
|
443
444
|
* Return uri for requested printer.
|
444
445
|
*/
|
445
|
-
static VALUE cups_get_device_uri(VALUE self, VALUE printer)
|
446
|
+
static VALUE cups_get_device_uri(VALUE self, VALUE printer)
|
446
447
|
{
|
447
|
-
if (!printer_exists(printer))
|
448
|
+
if (!printer_exists(printer))
|
448
449
|
{
|
449
450
|
rb_raise(rb_eRuntimeError, "The printer or destination doesn't exist!");
|
450
451
|
}
|
451
|
-
|
452
|
+
|
452
453
|
VALUE options_list;
|
453
454
|
http_t *http;
|
454
455
|
ipp_t *request;
|
455
456
|
ipp_t *response;
|
456
457
|
ipp_attribute_t *attr;
|
457
458
|
char uri[1024];
|
458
|
-
char *location;
|
459
|
+
char *location;
|
459
460
|
char *name = RSTRING_PTR(printer);
|
460
|
-
|
461
|
+
|
461
462
|
request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
|
462
463
|
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/printers/%s", name);
|
463
464
|
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
|
464
|
-
|
465
|
-
if ((response = cupsDoRequest(http, request, "/")) != NULL)
|
465
|
+
|
466
|
+
if ((response = cupsDoRequest(http, request, "/")) != NULL)
|
466
467
|
{
|
467
|
-
if((attr = ippFindAttribute(response, "device-uri", IPP_TAG_URI)) != NULL)
|
468
|
+
if((attr = ippFindAttribute(response, "device-uri", IPP_TAG_URI)) != NULL)
|
468
469
|
{
|
469
470
|
return rb_str_new2(attr->values[0].string.text);
|
470
471
|
}
|
@@ -498,7 +499,7 @@ static VALUE cups_get_options(VALUE self, VALUE printer)
|
|
498
499
|
cups_dest_t *dest = cupsGetDest(printer_arg, NULL, num_dests, dests);
|
499
500
|
|
500
501
|
if (dest == NULL) {
|
501
|
-
cupsFreeDests(num_dests, dests);
|
502
|
+
cupsFreeDests(num_dests, dests);
|
502
503
|
return Qnil;
|
503
504
|
} else {
|
504
505
|
for(i =0; i< dest->num_options; i++) {
|
@@ -543,4 +544,4 @@ void Init_cups() {
|
|
543
544
|
rb_define_singleton_method(rubyCups, "options_for", cups_get_options, 1);
|
544
545
|
rb_define_singleton_method(rubyCups, "device_uri_for", cups_get_device_uri, 1);
|
545
546
|
rb_define_singleton_method(rubyCups, "get_connection_for", cups_get_device_uri, 1);
|
546
|
-
}
|
547
|
+
}
|
data/ext/ruby_cups.h
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
#include <cups/cups.h>
|
2
2
|
|
3
3
|
// st.h is needed for ST_CONTINUE constant
|
4
|
-
#
|
5
|
-
|
6
|
-
#include <ruby/st.h>
|
7
|
-
#else
|
8
|
-
#include <ruby.h>
|
9
|
-
#include <st.h>
|
10
|
-
#endif
|
4
|
+
#include <ruby.h>
|
5
|
+
#include <st.h>
|
11
6
|
|
12
7
|
#ifndef MAXOPTS
|
13
8
|
#define MAXOPTS 100
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cups
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
16
16
|
dependencies: []
|
17
17
|
description: ! ' Ruby CUPS provides a wrapper for the Common UNIX Printing System,
|
18
18
|
allowing rubyists to perform basic tasks like printer discovery, job submission
|