thorsson_cups 0.0.31 → 0.0.32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/ext/cups.c +107 -10
  2. data/ext/extconf.rb +1 -1
  3. metadata +25 -37
data/ext/cups.c CHANGED
@@ -156,7 +156,21 @@ static VALUE cups_print(VALUE self)
156
156
  cupsFreeOptions(num_options, options);
157
157
 
158
158
  rb_iv_set(self, "@job_id", INT2NUM(job_id));
159
-
159
+
160
+
161
+ // 25.03 free memory
162
+ if(fname != NULL)
163
+ free(fname);
164
+
165
+ if(url != NULL)
166
+ free(url);
167
+
168
+ if(target != NULL)
169
+ free(target);
170
+
171
+ if(http != NULL)
172
+ free(http);
173
+
160
174
  return Qtrue;
161
175
  }
162
176
 
@@ -177,6 +191,10 @@ static VALUE cups_show_dests(VALUE self)
177
191
  VALUE destination = rb_str_new2(dest->name);
178
192
  rb_ary_push(dest_list, destination); // Add this testination name to dest_list string
179
193
  }
194
+
195
+ if(dests != NULL)
196
+ free(dests);
197
+
180
198
  return dest_list;
181
199
  }
182
200
 
@@ -193,6 +211,8 @@ static VALUE cups_get_default(VALUE self)
193
211
 
194
212
  if (default_printer != NULL) {
195
213
  VALUE def_p = rb_str_new2(default_printer);
214
+ if(default_printer != NULL)
215
+ free(default_printer);
196
216
  return def_p;
197
217
  }
198
218
  // should return nil if no default printer is found!
@@ -217,6 +237,8 @@ static VALUE cups_cancel(VALUE self)
217
237
  char *target = RSTRING_PTR(printer); // Target printer string
218
238
  int cancellation;
219
239
  cancellation = cupsCancelJob(target, job);
240
+ if(target != NULL)
241
+ free(target);
220
242
  return Qtrue;
221
243
  }
222
244
  }
@@ -309,6 +331,12 @@ static VALUE cups_get_job_state(VALUE self)
309
331
 
310
332
  jstate = ipp_state_to_symbol(job_state);
311
333
 
334
+ if(jobs != NULL)
335
+ free(jobs);
336
+
337
+ if(printer_arg != NULL)
338
+ free(printer_arg);
339
+
312
340
  return jstate;
313
341
  }
314
342
  }
@@ -346,6 +374,12 @@ static VALUE cups_job_completed(VALUE self)
346
374
  // Free job array
347
375
  cupsFreeJobs(num_jobs, jobs);
348
376
 
377
+ if(jobs != NULL)
378
+ free(jobs);
379
+
380
+ if(printer_arg != NULL)
381
+ free(printer_arg);
382
+
349
383
  if (job_state == IPP_JOB_COMPLETED) {
350
384
  return Qtrue;
351
385
  } else {
@@ -407,6 +441,12 @@ static VALUE cups_get_jobs(VALUE self, VALUE printer)
407
441
  // Free job array
408
442
  cupsFreeJobs(num_jobs, jobs);
409
443
 
444
+ if(jobs != NULL)
445
+ free(jobs);
446
+ if(printer_arg != NULL)
447
+ free(printer_arg);
448
+
449
+
410
450
  return job_list;
411
451
  }
412
452
 
@@ -420,10 +460,7 @@ static VALUE cups_cancel_print(int argc, VALUE* argv, VALUE self)
420
460
  {
421
461
  VALUE printer, job_id;
422
462
  rb_scan_args(argc, argv, "20", &job_id, &printer);
423
-
424
- VALUE url_path = cupsServer();
425
- char *url = RSTRING_PTR(url_path);
426
-
463
+
427
464
  if (NIL_P(job_id)) {
428
465
  return Qfalse; // If @job_id is nil
429
466
  } else { // Otherwise attempt to cancel
@@ -431,6 +468,10 @@ static VALUE cups_cancel_print(int argc, VALUE* argv, VALUE self)
431
468
  char *target = RSTRING_PTR(printer); // Target printer string
432
469
  int cancellation;
433
470
  cancellation = cupsCancelJob(target, job);
471
+
472
+ if(target != NULL)
473
+ free(target);
474
+
434
475
  return Qtrue;
435
476
  }
436
477
  }
@@ -454,10 +495,9 @@ static VALUE cups_get_device_uri(VALUE self, VALUE printer)
454
495
  ipp_t *response;
455
496
  ipp_attribute_t *attr;
456
497
  char uri[1024];
457
- char *location;
458
-
498
+ char *location;
459
499
  char *name = RSTRING_PTR(printer);
460
-
500
+
461
501
  request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
462
502
  httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL, "localhost", 0, "/printers/%s", name);
463
503
  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
@@ -466,10 +506,47 @@ static VALUE cups_get_device_uri(VALUE self, VALUE printer)
466
506
  {
467
507
  if((attr = ippFindAttribute(response, "device-uri", IPP_TAG_URI)) != NULL)
468
508
  {
469
- return rb_str_new2(attr->values[0].string.text);
509
+ if(http != NULL)
510
+ free(http);
511
+
512
+ if(request != NULL)
513
+ free(request);
514
+
515
+ if(response != NULL)
516
+ free(response);
517
+
518
+ if(attr != NULL)
519
+ free(attr);
520
+
521
+ if(location != NULL)
522
+ free(location);
523
+
524
+ if(name != NULL)
525
+ free(name);
526
+ return rb_str_new2(attr->values[0].string.text);
470
527
  }
471
528
  ippDelete(response);
472
- }
529
+ }
530
+
531
+
532
+ if(http != NULL)
533
+ free(http);
534
+
535
+ if(request != NULL)
536
+ free(request);
537
+
538
+ if(response != NULL)
539
+ free(response);
540
+
541
+ if(attr != NULL)
542
+ free(attr);
543
+
544
+ if(location != NULL)
545
+ free(location);
546
+
547
+ if(name != NULL)
548
+ free(name);
549
+
473
550
  return Qtrue;
474
551
  }
475
552
 
@@ -499,6 +576,16 @@ static VALUE cups_get_options(VALUE self, VALUE printer)
499
576
 
500
577
  if (dest == NULL) {
501
578
  cupsFreeDests(num_dests, dests);
579
+
580
+ if(printer_arg != NULL)
581
+ free(printer_arg);
582
+
583
+ if(dests != NULL)
584
+ free(dests);
585
+
586
+ if(dest != NULL)
587
+ free(dest);
588
+
502
589
  return Qnil;
503
590
  } else {
504
591
  for(i =0; i< dest->num_options; i++) {
@@ -506,6 +593,16 @@ static VALUE cups_get_options(VALUE self, VALUE printer)
506
593
  }
507
594
 
508
595
  cupsFreeDests(num_dests, dests);
596
+
597
+ if(printer_arg != NULL)
598
+ free(printer_arg);
599
+
600
+ if(dests != NULL)
601
+ free(dests);
602
+
603
+ if(dest != NULL)
604
+ free(dest);
605
+
509
606
  return options_list;
510
607
  }
511
608
 
data/ext/extconf.rb CHANGED
@@ -12,4 +12,4 @@ with_cflags(cups_cflags) {
12
12
  with_ldflags(cups_libs) {
13
13
  create_makefile("cups")
14
14
  }
15
- }
15
+ }
metadata CHANGED
@@ -1,35 +1,31 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: thorsson_cups
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 31
9
- version: 0.0.31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.32
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Ivan Turkovic
13
9
  - Chris Mowforth
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2011-01-21 00:00:00 +01:00
13
+ date: 2011-03-25 00:00:00.000000000 +01:00
19
14
  default_executable:
20
15
  dependencies: []
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.
21
19
 
22
- 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"
23
- email:
20
+ '
21
+ email:
24
22
  - me@ivanturkovic.com
25
23
  - chris@mowforth.com
26
24
  executables: []
27
-
28
- extensions:
25
+ extensions:
29
26
  - ext/extconf.rb
30
27
  extra_rdoc_files: []
31
-
32
- files:
28
+ files:
33
29
  - test/cups_test.rb
34
30
  - test/sample.txt
35
31
  - test/sample_blank.txt
@@ -41,34 +37,26 @@ files:
41
37
  has_rdoc: true
42
38
  homepage: https://github.com/Thorsson/cups
43
39
  licenses: []
44
-
45
40
  post_install_message:
46
41
  rdoc_options: []
47
-
48
- require_paths:
42
+ require_paths:
49
43
  - lib
50
- required_ruby_version: !ruby/object:Gem::Requirement
44
+ required_ruby_version: !ruby/object:Gem::Requirement
51
45
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- version: "0"
58
- 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
59
51
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- segments:
64
- - 0
65
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
66
56
  requirements: []
67
-
68
57
  rubyforge_project: thorsson_cups
69
- rubygems_version: 1.3.7
58
+ rubygems_version: 1.5.2
70
59
  signing_key:
71
60
  specification_version: 3
72
61
  summary: A lightweight Ruby library for printing.
73
62
  test_files: []
74
-