noggin 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,10 +48,23 @@ static void __gcpool_Keep_del(VALUE val);
48
48
 
49
49
  /* Inline C code */
50
50
 
51
+ inline VALUE as_string(const char *string);
52
+ int hash_to_cups_options_it(VALUE key, VALUE val, VALUE data);
53
+ static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count);
54
+ static VALUE rb_ipp_value(ipp_attribute_t* attr);
55
+ VALUE job_state(ipp_jstate_t state);
56
+ static VALUE renew_subscription(int subscription_id, int duration);
57
+ static void debug_ipp(ipp_t *ipp);
58
+ static VALUE create_subscription(int duration, char *uri, char *printer);
59
+ static void cancel_subscription(int subscription_id);
60
+ static VALUE list_subscriptions(bool my_subscriptions);
51
61
 
52
- inline VALUE as_string(const char *string) { return string ? rb_str_new2(string) : Qnil; }
53
62
 
54
- #define TO_STRING(v) ((v) ? rb_str_new2((v)) : Qnil)
63
+
64
+ inline VALUE as_string(const char *string)
65
+ {
66
+ return string ? rb_str_new2(string) : Qnil;
67
+ }
55
68
 
56
69
  static VALUE sym_aborted = Qnil;
57
70
  static VALUE sym_cancelled = Qnil;
@@ -63,7 +76,7 @@ static VALUE sym_stopped = Qnil;
63
76
 
64
77
  #define SUBSCRIPTION_DURATION 3600
65
78
  #define STATIC_STR(name) static VALUE str_##name = Qnil;
66
- #define STATIC_STR_INIT(name) KEEP_ADD(str_##name = rb_str_new2(#name)); rb_obj_freeze(str_##name);
79
+ #define STATIC_STR_INIT(name) KEEP_ADD(str_##name = rb_str_new2(#name));
67
80
  STATIC_STR(completed_time);
68
81
  STATIC_STR(creation_time);
69
82
  STATIC_STR(dest);
@@ -86,14 +99,16 @@ struct svp_it {
86
99
  cups_option_t *options;
87
100
  };
88
101
 
89
- int hash_to_cups_options_it(VALUE key, VALUE val, VALUE data) {
102
+ int hash_to_cups_options_it(VALUE key, VALUE val, VALUE data)
103
+ {
90
104
  struct svp_it *svp = (struct svp_it *)data;
91
105
  svp->num_options = cupsAddOption(StringValuePtr(key), StringValuePtr(val), svp->num_options, &(svp->options));
92
106
  return ST_CONTINUE;
93
107
  }
94
108
 
95
- static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count) {
96
- char *lang = NULL;
109
+ static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count)
110
+ {
111
+ const char *lang = NULL;
97
112
  char block[4096] = "";
98
113
 
99
114
  /*char block[4096] = "";
@@ -102,7 +117,10 @@ static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count) {
102
117
 
103
118
  switch (ippGetValueTag(attr)) {
104
119
  case IPP_TAG_INTEGER:
120
+ case IPP_TAG_JOB:
105
121
  return INT2NUM(ippGetInteger(attr, count));
122
+ case IPP_TAG_ZERO:
123
+ return INT2FIX(0);
106
124
  case IPP_TAG_RESERVED_STRING:
107
125
  case IPP_TAG_STRING:
108
126
  case IPP_TAG_SUBSCRIPTION:
@@ -120,6 +138,32 @@ static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count) {
120
138
  return as_string(ippGetString(attr, count, &lang));
121
139
  case IPP_TAG_BOOLEAN:
122
140
  return ippGetBoolean(attr, count) ? Qtrue : Qfalse;
141
+ case IPP_TAG_CUPS_INVALID:
142
+ return Qnil;
143
+ /* Are these just groups tags? */
144
+ case IPP_TAG_OPERATION:
145
+ case IPP_TAG_END:
146
+ case IPP_TAG_PRINTER:
147
+ case IPP_TAG_UNSUPPORTED_GROUP:
148
+ case IPP_TAG_EVENT_NOTIFICATION:
149
+ case IPP_TAG_RESOURCE:
150
+ case IPP_TAG_DOCUMENT:
151
+ case IPP_TAG_UNSUPPORTED_VALUE:
152
+ case IPP_TAG_DEFAULT:
153
+ case IPP_TAG_UNKNOWN:
154
+ case IPP_TAG_NOVALUE:
155
+ case IPP_TAG_NOTSETTABLE:
156
+ case IPP_TAG_DELETEATTR:
157
+ case IPP_TAG_ADMINDEFINE:
158
+ case IPP_TAG_ENUM:
159
+ case IPP_TAG_DATE:
160
+ case IPP_TAG_RESOLUTION:
161
+ case IPP_TAG_RANGE:
162
+ case IPP_TAG_BEGIN_COLLECTION:
163
+ case IPP_TAG_END_COLLECTION:
164
+ case IPP_TAG_EXTENSION:
165
+ case IPP_TAG_MASK:
166
+ case IPP_TAG_COPY:
123
167
  default:
124
168
  ippAttributeString(attr, block, 4096);
125
169
  printf("[UNSUPPORTED] %s: (%i) %s\n", ippGetName(attr), ippGetValueTag(attr), block);
@@ -128,7 +172,8 @@ static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count) {
128
172
  }
129
173
  }
130
174
 
131
- static VALUE rb_ipp_value(ipp_attribute_t* attr) {
175
+ static VALUE rb_ipp_value(ipp_attribute_t* attr)
176
+ {
132
177
  int num = ippGetCount(attr), i = 0;
133
178
  VALUE val = Qnil;
134
179
 
@@ -147,8 +192,10 @@ static VALUE rb_ipp_value(ipp_attribute_t* attr) {
147
192
  }
148
193
 
149
194
 
150
- VALUE job_state(ipp_jstate_t state) {
151
- switch(state) {
195
+ VALUE job_state(ipp_jstate_t state)
196
+ {
197
+ switch(state)
198
+ {
152
199
  case IPP_JOB_ABORTED:
153
200
  return sym_aborted;
154
201
  case IPP_JOB_CANCELED:
@@ -163,15 +210,15 @@ VALUE job_state(ipp_jstate_t state) {
163
210
  return sym_processing;
164
211
  case IPP_JOB_STOPPED:
165
212
  return sym_stopped;
166
- }
167
- return INT2FIX(state);
213
+ default:
214
+ return INT2FIX(state);
215
+ }
168
216
  }
169
217
 
170
- static VALUE renew_subscription(int subscription_id, int duration) {
171
- ipp_attribute_t *attr = NULL;
218
+ static VALUE renew_subscription(int subscription_id, int duration)
219
+ {
172
220
  http_t *http;
173
221
  ipp_t *request;
174
- ipp_t *response;
175
222
 
176
223
  if ((http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption ())) == NULL) {
177
224
  return Qnil;
@@ -193,7 +240,8 @@ static VALUE renew_subscription(int subscription_id, int duration) {
193
240
  return INT2NUM(subscription_id);
194
241
  }
195
242
 
196
- static void debug_ipp(ipp_t *ipp) {
243
+ static void debug_ipp(ipp_t *ipp)
244
+ {
197
245
  char block[4096] = "";
198
246
  ipp_attribute_t *attr = NULL;
199
247
 
@@ -204,7 +252,8 @@ static void debug_ipp(ipp_t *ipp) {
204
252
 
205
253
  }
206
254
 
207
- static VALUE create_subscription(int duration, char *uri, char *printer) {
255
+ static VALUE create_subscription(int duration, char *uri, char *printer)
256
+ {
208
257
  ipp_attribute_t *attr = NULL;
209
258
  http_t *http;
210
259
  ipp_t *request;
@@ -260,8 +309,7 @@ static VALUE create_subscription(int duration, char *uri, char *printer) {
260
309
  return subscription_id;
261
310
  }
262
311
 
263
- static void
264
- cancel_subscription(int subscription_id)
312
+ static void cancel_subscription(int subscription_id)
265
313
  {
266
314
  http_t *http;
267
315
  ipp_t *request;
@@ -282,12 +330,12 @@ cancel_subscription(int subscription_id)
282
330
  }
283
331
  }
284
332
 
285
- static VALUE list_subscriptions(bool my_subscriptions) {
333
+ static VALUE list_subscriptions(bool my_subscriptions)
334
+ {
286
335
  ipp_attribute_t *attr = NULL;
287
336
  http_t *http;
288
337
  ipp_t *request;
289
338
  ipp_t *response;
290
- VALUE subscription_id = 0;
291
339
  VALUE ary = rb_ary_new();
292
340
  static const char * const req_attr[] = {
293
341
  "all"
@@ -308,8 +356,12 @@ static VALUE list_subscriptions(bool my_subscriptions) {
308
356
  my_subscriptions);
309
357
  response = cupsDoRequest (http, request, "/");
310
358
 
311
- if (response != NULL && ippGetStatusCode(response) <= IPP_OK_CONFLICT) {
312
- char block[4096] = "", *name;
359
+ if (response == NULL) {
360
+ goto out;
361
+ }
362
+
363
+ if (ippGetStatusCode(response) <= IPP_OK_CONFLICT) {
364
+ const char *name;
313
365
  VALUE hash = rb_hash_new();
314
366
 
315
367
  attr = ippFirstAttribute(response);
@@ -326,18 +378,17 @@ static VALUE list_subscriptions(bool my_subscriptions) {
326
378
  rb_ary_push(ary, hash);
327
379
  } else {
328
380
  rb_hash_aset(hash, as_string(name), rb_ipp_value(attr));
329
- /*puts(ippGetName(attr));
381
+ /*{ char block[4096] = ""; puts(ippGetName(attr));
330
382
  if (ippAttributeString(attr, block, 4096) > 0) {
331
383
  puts(block);
332
- }*/
384
+ }}*/
333
385
  }
334
386
  }
335
387
  }
336
388
 
337
- if (response) {
338
- ippDelete(response);
339
- }
389
+ ippDelete(response);
340
390
 
391
+ out:
341
392
  httpClose (http);
342
393
 
343
394
  return ary;
@@ -350,7 +401,7 @@ Noggin_CLASS_destinations(VALUE self OPTIONAL_ATTR )
350
401
  {
351
402
  VALUE __p_retval OPTIONAL_ATTR = Qnil;
352
403
 
353
- #line 356 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
404
+ #line 408 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
354
405
 
355
406
  do {
356
407
  VALUE list =
@@ -359,7 +410,6 @@ Noggin_CLASS_destinations(VALUE self OPTIONAL_ATTR )
359
410
  int num_dests = cupsGetDests(&dests);
360
411
  cups_dest_t * dest ;
361
412
  int i ;
362
- const char * value ;
363
413
  int j ;
364
414
  list = rb_ary_new2(num_dests);
365
415
  for (i = num_dests, dest = dests;
@@ -372,7 +422,7 @@ Noggin_CLASS_destinations(VALUE self OPTIONAL_ATTR )
372
422
  rb_hash_aset(hash, str_options, options);
373
423
  for (j = 0;
374
424
  j < dest->num_options;
375
- j++) { rb_hash_aset(options, as_string(dest->options[j].name), as_string(dest->options[j].value));
425
+ j++) { rb_hash_aset(options, as_string((dest->options[j].name)), as_string((dest->options[j].value)));
376
426
  } rb_ary_push(list, hash);
377
427
  } cupsFreeDests(num_dests, dests);
378
428
  do { __p_retval = list; goto out; } while(0);
@@ -394,7 +444,7 @@ Noggin_CLASS_jobs(VALUE self OPTIONAL_ATTR , VALUE printer OPTIONAL_ATTR, VALUE
394
444
  __orig_mine = mine = RTEST(__v_mine);
395
445
  __orig_whichjobs = whichjobs = NUM2INT(__v_whichjobs);
396
446
 
397
- #line 386 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
447
+ #line 437 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
398
448
 
399
449
  do {
400
450
  VALUE list =
@@ -457,7 +507,7 @@ Noggin_CLASS_printFile(int __p_argc, VALUE *__p_argv, VALUE self)
457
507
  rb_raise(rb_eArgError, "options argument must be one of Hash, Nil");
458
508
 
459
509
 
460
- #line 417 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
510
+ #line 468 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
461
511
 
462
512
  do {
463
513
  struct svp_it info =
@@ -482,7 +532,7 @@ Job_CLASS_cancel(VALUE self OPTIONAL_ATTR , VALUE __v_printer OPTIONAL_ATTR, VAL
482
532
  __orig_printer = printer = ( NIL_P(__v_printer) ? NULL : StringValuePtr(__v_printer) );
483
533
  __orig_job_id = job_id = NUM2INT(__v_job_id);
484
534
 
485
- #line 347 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
535
+ #line 399 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
486
536
  if (cupsCancelJob(printer, job_id) == 0) { rb_raise(rb_eRuntimeError, "CUPS Error: %d - %s", cupsLastError(), cupsLastErrorString());
487
537
  }
488
538
  return Qnil;
@@ -511,15 +561,15 @@ Subscription_CLASS_create(int __p_argc, VALUE *__p_argv, VALUE self)
511
561
  if (__p_argc > 1)
512
562
  __orig_notify_uri = notify_uri = ( NIL_P(__v_notify_uri) ? NULL : StringValuePtr(__v_notify_uri) );
513
563
  else
514
- notify_uri = "dbus://";
564
+ notify_uri = (char*)"dbus://";
515
565
 
516
566
  if (__p_argc > 2)
517
567
  __orig_printer = printer = ( NIL_P(__v_printer) ? NULL : StringValuePtr(__v_printer) );
518
568
  else
519
- printer = "/";
569
+ printer = (char*)"/";
520
570
 
521
571
 
522
- #line 435 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
572
+ #line 486 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
523
573
  do { __p_retval = create_subscription(duration, notify_uri, printer); goto out; } while(0);
524
574
  out:
525
575
  return __p_retval;
@@ -546,7 +596,7 @@ Subscription_CLASS_renew(int __p_argc, VALUE *__p_argv, VALUE self)
546
596
  duration = 0;
547
597
 
548
598
 
549
- #line 438 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
599
+ #line 489 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
550
600
  do { __p_retval = renew_subscription(id, duration); goto out; } while(0);
551
601
  out:
552
602
  return __p_retval;
@@ -558,7 +608,7 @@ Subscription_CLASS_cancel(VALUE self OPTIONAL_ATTR , VALUE __v_id OPTIONAL_ATTR)
558
608
  int id; int __orig_id;
559
609
  __orig_id = id = NUM2INT(__v_id);
560
610
 
561
- #line 441 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
611
+ #line 492 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
562
612
  cancel_subscription(id);
563
613
 
564
614
  return Qnil;
@@ -581,7 +631,7 @@ Subscription_CLASS_list(int __p_argc, VALUE *__p_argv, VALUE self)
581
631
  my_subscriptions = 1;
582
632
 
583
633
 
584
- #line 444 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
634
+ #line 495 "/home/geoff/Projects/noggin/ext/noggin/noggin.cr"
585
635
  do { __p_retval = list_subscriptions(my_subscriptions); goto out; } while(0);
586
636
  out:
587
637
  return __p_retval;
@@ -636,6 +686,7 @@ Init_noggin(void)
636
686
  rb_define_singleton_method(mSubscription, "list", Subscription_CLASS_list, -1);
637
687
  rb_gc_register_address(&_gcpool_Keep);
638
688
 
689
+ KEEP_DEL(Qnil);
639
690
  KEEP_ADD(sym_cancelled = ID2SYM(rb_intern("cancelled")));
640
691
  KEEP_ADD(sym_completed = ID2SYM(rb_intern("completed")));
641
692
  KEEP_ADD(sym_held = ID2SYM(rb_intern("held")));
@@ -7,10 +7,23 @@
7
7
  %lib cups
8
8
 
9
9
  %{
10
+ inline VALUE as_string(const char *string);
11
+ int hash_to_cups_options_it(VALUE key, VALUE val, VALUE data);
12
+ static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count);
13
+ static VALUE rb_ipp_value(ipp_attribute_t* attr);
14
+ VALUE job_state(ipp_jstate_t state);
15
+ static VALUE renew_subscription(int subscription_id, int duration);
16
+ static void debug_ipp(ipp_t *ipp);
17
+ static VALUE create_subscription(int duration, char *uri, char *printer);
18
+ static void cancel_subscription(int subscription_id);
19
+ static VALUE list_subscriptions(bool my_subscriptions);
10
20
 
11
- inline VALUE as_string(const char *string) { return string ? rb_str_new2(string) : Qnil; }
12
21
 
13
- #define TO_STRING(v) ((v) ? rb_str_new2((v)) : Qnil)
22
+
23
+ inline VALUE as_string(const char *string)
24
+ {
25
+ return string ? rb_str_new2(string) : Qnil;
26
+ }
14
27
 
15
28
  static VALUE sym_aborted = Qnil;
16
29
  static VALUE sym_cancelled = Qnil;
@@ -22,7 +35,7 @@ static VALUE sym_stopped = Qnil;
22
35
 
23
36
  #define SUBSCRIPTION_DURATION 3600
24
37
  #define STATIC_STR(name) static VALUE str_##name = Qnil;
25
- #define STATIC_STR_INIT(name) KEEP_ADD(str_##name = rb_str_new2(#name)); rb_obj_freeze(str_##name);
38
+ #define STATIC_STR_INIT(name) KEEP_ADD(str_##name = rb_str_new2(#name));
26
39
  STATIC_STR(completed_time);
27
40
  STATIC_STR(creation_time);
28
41
  STATIC_STR(dest);
@@ -45,14 +58,16 @@ struct svp_it {
45
58
  cups_option_t *options;
46
59
  };
47
60
 
48
- int hash_to_cups_options_it(VALUE key, VALUE val, VALUE data) {
61
+ int hash_to_cups_options_it(VALUE key, VALUE val, VALUE data)
62
+ {
49
63
  struct svp_it *svp = (struct svp_it *)data;
50
64
  svp->num_options = cupsAddOption(StringValuePtr(key), StringValuePtr(val), svp->num_options, &(svp->options));
51
65
  return ST_CONTINUE;
52
66
  }
53
67
 
54
- static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count) {
55
- char *lang = NULL;
68
+ static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count)
69
+ {
70
+ const char *lang = NULL;
56
71
  char block[4096] = "";
57
72
 
58
73
  /*char block[4096] = "";
@@ -61,7 +76,10 @@ static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count) {
61
76
 
62
77
  switch (ippGetValueTag(attr)) {
63
78
  case IPP_TAG_INTEGER:
79
+ case IPP_TAG_JOB:
64
80
  return INT2NUM(ippGetInteger(attr, count));
81
+ case IPP_TAG_ZERO:
82
+ return INT2FIX(0);
65
83
  case IPP_TAG_RESERVED_STRING:
66
84
  case IPP_TAG_STRING:
67
85
  case IPP_TAG_SUBSCRIPTION:
@@ -79,6 +97,32 @@ static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count) {
79
97
  return as_string(ippGetString(attr, count, &lang));
80
98
  case IPP_TAG_BOOLEAN:
81
99
  return ippGetBoolean(attr, count) ? Qtrue : Qfalse;
100
+ case IPP_TAG_CUPS_INVALID:
101
+ return Qnil;
102
+ /* Are these just groups tags? */
103
+ case IPP_TAG_OPERATION:
104
+ case IPP_TAG_END:
105
+ case IPP_TAG_PRINTER:
106
+ case IPP_TAG_UNSUPPORTED_GROUP:
107
+ case IPP_TAG_EVENT_NOTIFICATION:
108
+ case IPP_TAG_RESOURCE:
109
+ case IPP_TAG_DOCUMENT:
110
+ case IPP_TAG_UNSUPPORTED_VALUE:
111
+ case IPP_TAG_DEFAULT:
112
+ case IPP_TAG_UNKNOWN:
113
+ case IPP_TAG_NOVALUE:
114
+ case IPP_TAG_NOTSETTABLE:
115
+ case IPP_TAG_DELETEATTR:
116
+ case IPP_TAG_ADMINDEFINE:
117
+ case IPP_TAG_ENUM:
118
+ case IPP_TAG_DATE:
119
+ case IPP_TAG_RESOLUTION:
120
+ case IPP_TAG_RANGE:
121
+ case IPP_TAG_BEGIN_COLLECTION:
122
+ case IPP_TAG_END_COLLECTION:
123
+ case IPP_TAG_EXTENSION:
124
+ case IPP_TAG_MASK:
125
+ case IPP_TAG_COPY:
82
126
  default:
83
127
  ippAttributeString(attr, block, 4096);
84
128
  printf("[UNSUPPORTED] %s: (%i) %s\n", ippGetName(attr), ippGetValueTag(attr), block);
@@ -87,7 +131,8 @@ static VALUE rb_ipp_value_entry(ipp_attribute_t* attr, int count) {
87
131
  }
88
132
  }
89
133
 
90
- static VALUE rb_ipp_value(ipp_attribute_t* attr) {
134
+ static VALUE rb_ipp_value(ipp_attribute_t* attr)
135
+ {
91
136
  int num = ippGetCount(attr), i = 0;
92
137
  VALUE val = Qnil;
93
138
 
@@ -106,8 +151,10 @@ static VALUE rb_ipp_value(ipp_attribute_t* attr) {
106
151
  }
107
152
 
108
153
 
109
- VALUE job_state(ipp_jstate_t state) {
110
- switch(state) {
154
+ VALUE job_state(ipp_jstate_t state)
155
+ {
156
+ switch(state)
157
+ {
111
158
  case IPP_JOB_ABORTED:
112
159
  return sym_aborted;
113
160
  case IPP_JOB_CANCELED:
@@ -122,15 +169,15 @@ VALUE job_state(ipp_jstate_t state) {
122
169
  return sym_processing;
123
170
  case IPP_JOB_STOPPED:
124
171
  return sym_stopped;
125
- }
126
- return INT2FIX(state);
172
+ default:
173
+ return INT2FIX(state);
174
+ }
127
175
  }
128
176
 
129
- static VALUE renew_subscription(int subscription_id, int duration) {
130
- ipp_attribute_t *attr = NULL;
177
+ static VALUE renew_subscription(int subscription_id, int duration)
178
+ {
131
179
  http_t *http;
132
180
  ipp_t *request;
133
- ipp_t *response;
134
181
 
135
182
  if ((http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption ())) == NULL) {
136
183
  return Qnil;
@@ -152,7 +199,8 @@ static VALUE renew_subscription(int subscription_id, int duration) {
152
199
  return INT2NUM(subscription_id);
153
200
  }
154
201
 
155
- static void debug_ipp(ipp_t *ipp) {
202
+ static void debug_ipp(ipp_t *ipp)
203
+ {
156
204
  char block[4096] = "";
157
205
  ipp_attribute_t *attr = NULL;
158
206
 
@@ -163,7 +211,8 @@ static void debug_ipp(ipp_t *ipp) {
163
211
 
164
212
  }
165
213
 
166
- static VALUE create_subscription(int duration, char *uri, char *printer) {
214
+ static VALUE create_subscription(int duration, char *uri, char *printer)
215
+ {
167
216
  ipp_attribute_t *attr = NULL;
168
217
  http_t *http;
169
218
  ipp_t *request;
@@ -219,8 +268,7 @@ static VALUE create_subscription(int duration, char *uri, char *printer) {
219
268
  return subscription_id;
220
269
  }
221
270
 
222
- static void
223
- cancel_subscription(int subscription_id)
271
+ static void cancel_subscription(int subscription_id)
224
272
  {
225
273
  http_t *http;
226
274
  ipp_t *request;
@@ -241,12 +289,12 @@ cancel_subscription(int subscription_id)
241
289
  }
242
290
  }
243
291
 
244
- static VALUE list_subscriptions(bool my_subscriptions) {
292
+ static VALUE list_subscriptions(bool my_subscriptions)
293
+ {
245
294
  ipp_attribute_t *attr = NULL;
246
295
  http_t *http;
247
296
  ipp_t *request;
248
297
  ipp_t *response;
249
- VALUE subscription_id = 0;
250
298
  VALUE ary = rb_ary_new();
251
299
  static const char * const req_attr[] = {
252
300
  "all"
@@ -267,8 +315,12 @@ static VALUE list_subscriptions(bool my_subscriptions) {
267
315
  my_subscriptions);
268
316
  response = cupsDoRequest (http, request, "/");
269
317
 
270
- if (response != NULL && ippGetStatusCode(response) <= IPP_OK_CONFLICT) {
271
- char block[4096] = "", *name;
318
+ if (response == NULL) {
319
+ goto out;
320
+ }
321
+
322
+ if (ippGetStatusCode(response) <= IPP_OK_CONFLICT) {
323
+ const char *name;
272
324
  VALUE hash = rb_hash_new();
273
325
 
274
326
  attr = ippFirstAttribute(response);
@@ -285,18 +337,17 @@ static VALUE list_subscriptions(bool my_subscriptions) {
285
337
  rb_ary_push(ary, hash);
286
338
  } else {
287
339
  rb_hash_aset(hash, as_string(name), rb_ipp_value(attr));
288
- /*puts(ippGetName(attr));
340
+ /*{ char block[4096] = ""; puts(ippGetName(attr));
289
341
  if (ippAttributeString(attr, block, 4096) > 0) {
290
342
  puts(block);
291
- }*/
343
+ }}*/
292
344
  }
293
345
  }
294
346
  }
295
347
 
296
- if (response) {
297
- ippDelete(response);
298
- }
348
+ ippDelete(response);
299
349
 
350
+ out:
300
351
  httpClose (http);
301
352
 
302
353
  return ary;
@@ -305,6 +356,7 @@ static VALUE list_subscriptions(bool my_subscriptions) {
305
356
  %}
306
357
 
307
358
  %post_init{
359
+ KEEP_DEL(Qnil);
308
360
  KEEP_ADD(sym_cancelled = ID2SYM(rb_intern("cancelled")));
309
361
  KEEP_ADD(sym_completed = ID2SYM(rb_intern("completed")));
310
362
  KEEP_ADD(sym_held = ID2SYM(rb_intern("held")));
@@ -359,7 +411,6 @@ module Noggin
359
411
  int num_dests = cupsGetDests(&dests);
360
412
  cups_dest_t *dest;
361
413
  int i;
362
- const char *value;
363
414
  int j;
364
415
 
365
416
  list = rb_ary_new2(num_dests);
@@ -372,7 +423,7 @@ module Noggin
372
423
  rb_hash_aset(hash, str_options, options);
373
424
 
374
425
  for (j = 0; j < dest->num_options; j++) {
375
- rb_hash_aset(options, as_string(dest->options[j].name), as_string(dest->options[j].value));
426
+ rb_hash_aset(options, as_string((dest->options[j].name)), as_string((dest->options[j].value)));
376
427
  }
377
428
 
378
429
  rb_ary_push(list, hash);
@@ -432,7 +483,7 @@ module Noggin
432
483
  end
433
484
 
434
485
  module Subscription
435
- def self.create(int duration=0, char *notify_uri="dbus://", char *printer="/")
486
+ def self.create(int duration=0, char *notify_uri=(char*)"dbus://", char *printer=(char*)"/")
436
487
  return create_subscription(duration, notify_uri, printer);
437
488
  end
438
489
  def self.renew(int id, int duration=0)
@@ -1,4 +1,4 @@
1
1
  module Noggin
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noggin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-21 00:00:00.000000000 Z
12
+ date: 2013-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubber-generate
@@ -75,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  segments:
77
77
  - 0
78
- hash: 211198722336226809
78
+ hash: 434593855864309664
79
79
  required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  none: false
81
81
  requirements: