thorsson_cups 0.0.22 → 0.0.25
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/cups.c +32 -1
- metadata +3 -3
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) {
|
@@ -436,6 +435,37 @@ static VALUE cups_cancel_print(int argc, VALUE* argv, VALUE self)
|
|
436
435
|
}
|
437
436
|
}
|
438
437
|
|
438
|
+
/*
|
439
|
+
* call-seq:
|
440
|
+
* Cups.device_uri_for(printer_name) -> String
|
441
|
+
*
|
442
|
+
* Return uri for requested printer.
|
443
|
+
*/
|
444
|
+
static VALUE cups_get_device_uri(VALUE self, VALUE printerName) {
|
445
|
+
// Don't have to lift a finger unless the printer exists.
|
446
|
+
if (!printer_exists(printerName)){
|
447
|
+
rb_raise(rb_eRuntimeError, "The printer or destination doesn't exist!");
|
448
|
+
}
|
449
|
+
|
450
|
+
http_t *http;
|
451
|
+
ipp_t *request, *response;
|
452
|
+
ipp_attribute_t *attr;
|
453
|
+
char uri[1024];
|
454
|
+
char *location;
|
455
|
+
char *printer = RSTRING_PTR(printerName);
|
456
|
+
|
457
|
+
request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
|
458
|
+
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/printers/%s", printer);
|
459
|
+
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
|
460
|
+
|
461
|
+
if ((response = cupsDoRequest(http, request, "/")) != NULL) {
|
462
|
+
if((attr = ippFindAttribute(response, "device-uri", IPP_TAG_URI)) != NULL) {
|
463
|
+
// sprintf(location, "%s", attr->values[0].string.text);
|
464
|
+
}
|
465
|
+
ippDelete(response);
|
466
|
+
}
|
467
|
+
}
|
468
|
+
|
439
469
|
/*
|
440
470
|
* call-seq:
|
441
471
|
* Cups.options_for(name) -> Hash or nil
|
@@ -504,4 +534,5 @@ void Init_cups() {
|
|
504
534
|
rb_define_singleton_method(rubyCups, "all_jobs", cups_get_jobs, 1);
|
505
535
|
rb_define_singleton_method(rubyCups, "cancel_print", cups_cancel_print, -1);
|
506
536
|
rb_define_singleton_method(rubyCups, "options_for", cups_get_options, 1);
|
537
|
+
rb_define_singleton_method(rubyCups, "device_uri_for", cups_get_device_uri, 1);
|
507
538
|
}
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 25
|
9
|
+
version: 0.0.25
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ivan Turkovic
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-19 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|