rubyfb 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
data/ext/Backup.c CHANGED
@@ -79,37 +79,30 @@ VALUE cBackup;
79
79
  * @return A reference to the newly initialized Backup object.
80
80
  *
81
81
  */
82
- VALUE initializeBackup(VALUE self, VALUE database, VALUE file)
83
- {
84
- VALUE path = Qnil,
85
- files = rb_hash_new();
86
-
87
- /* Extract the database file details. */
88
- if(TYPE(database) == T_FILE)
89
- {
90
- path = rb_funcall(database, rb_intern("path"), 0);
91
- }
92
- else
93
- {
94
- path = rb_funcall(database, rb_intern("to_s"), 0);
95
- }
96
-
97
- /* Get the back file details. */
98
- if(TYPE(file) == T_FILE)
99
- {
100
- rb_hash_aset(files, rb_funcall(file, rb_intern("path"), 0), Qnil);
101
- }
102
- else
103
- {
104
- rb_hash_aset(files, rb_funcall(file, rb_intern("to_s"), 0), Qnil);
105
- }
106
-
107
- rb_iv_set(self, "@database", path);
108
- rb_iv_set(self, "@files", files);
109
- rb_iv_set(self, "@options", rb_hash_new());
110
- rb_iv_set(self, "@log", Qnil);
111
-
112
- return(self);
82
+ VALUE initializeBackup(VALUE self, VALUE database, VALUE file) {
83
+ VALUE path = Qnil,
84
+ files = rb_hash_new();
85
+
86
+ /* Extract the database file details. */
87
+ if(TYPE(database) == T_FILE) {
88
+ path = rb_funcall(database, rb_intern("path"), 0);
89
+ } else {
90
+ path = rb_funcall(database, rb_intern("to_s"), 0);
91
+ }
92
+
93
+ /* Get the back file details. */
94
+ if(TYPE(file) == T_FILE) {
95
+ rb_hash_aset(files, rb_funcall(file, rb_intern("path"), 0), Qnil);
96
+ } else {
97
+ rb_hash_aset(files, rb_funcall(file, rb_intern("to_s"), 0), Qnil);
98
+ }
99
+
100
+ rb_iv_set(self, "@database", path);
101
+ rb_iv_set(self, "@files", files);
102
+ rb_iv_set(self, "@options", rb_hash_new());
103
+ rb_iv_set(self, "@log", Qnil);
104
+
105
+ return(self);
113
106
  }
114
107
 
115
108
 
@@ -122,11 +115,10 @@ VALUE initializeBackup(VALUE self, VALUE database, VALUE file)
122
115
  * @return A reference to a String containing the backup file path/name.
123
116
  *
124
117
  */
125
- VALUE getBackupFile(VALUE self)
126
- {
127
- VALUE files = rb_iv_get(self, "@files");
118
+ VALUE getBackupFile(VALUE self) {
119
+ VALUE files = rb_iv_get(self, "@files");
128
120
 
129
- return(rb_ary_entry(rb_funcall(files, rb_intern("keys"), 0), 0));
121
+ return(rb_ary_entry(rb_funcall(files, rb_intern("keys"), 0), 0));
130
122
  }
131
123
 
132
124
 
@@ -139,21 +131,17 @@ VALUE getBackupFile(VALUE self)
139
131
  * of the backup file.
140
132
  *
141
133
  */
142
- VALUE setBackupFile(VALUE self, VALUE file)
143
- {
144
- VALUE files = rb_hash_new();
145
-
146
- if(TYPE(file) == T_FILE)
147
- {
148
- rb_hash_aset(files, rb_funcall(file, rb_intern("path"), 0), Qnil);
149
- }
150
- else
151
- {
152
- rb_hash_aset(files, rb_funcall(file, rb_intern("to_s"), 0), Qnil);
153
- }
154
- rb_iv_set(self, "@files", files);
155
-
156
- return(self);
134
+ VALUE setBackupFile(VALUE self, VALUE file) {
135
+ VALUE files = rb_hash_new();
136
+
137
+ if(TYPE(file) == T_FILE) {
138
+ rb_hash_aset(files, rb_funcall(file, rb_intern("path"), 0), Qnil);
139
+ } else {
140
+ rb_hash_aset(files, rb_funcall(file, rb_intern("to_s"), 0), Qnil);
141
+ }
142
+ rb_iv_set(self, "@files", files);
143
+
144
+ return(self);
157
145
  }
158
146
 
159
147
 
@@ -166,9 +154,8 @@ VALUE setBackupFile(VALUE self, VALUE file)
166
154
  * database file to be backed up.
167
155
  *
168
156
  */
169
- VALUE getBackupDatabase(VALUE self)
170
- {
171
- return(rb_iv_get(self, "@database"));
157
+ VALUE getBackupDatabase(VALUE self) {
158
+ return(rb_iv_get(self, "@database"));
172
159
  }
173
160
 
174
161
 
@@ -182,18 +169,14 @@ VALUE getBackupDatabase(VALUE self)
182
169
  * @return A reference to the Backup object that has been updated.
183
170
  *
184
171
  */
185
- VALUE setBackupDatabase(VALUE self, VALUE setting)
186
- {
187
- if(TYPE(setting) == T_FILE)
188
- {
189
- rb_iv_set(self, "@database", rb_funcall(setting, rb_intern("path"), 0));
190
- }
191
- else
192
- {
193
- rb_iv_set(self, "@database", rb_funcall(setting, rb_intern("to_s"), 0));
194
- }
195
-
196
- return(self);
172
+ VALUE setBackupDatabase(VALUE self, VALUE setting) {
173
+ if(TYPE(setting) == T_FILE) {
174
+ rb_iv_set(self, "@database", rb_funcall(setting, rb_intern("path"), 0));
175
+ } else {
176
+ rb_iv_set(self, "@database", rb_funcall(setting, rb_intern("to_s"), 0));
177
+ }
178
+
179
+ return(self);
197
180
  }
198
181
 
199
182
 
@@ -207,11 +190,10 @@ VALUE setBackupDatabase(VALUE self, VALUE setting)
207
190
  * Backup object.
208
191
  *
209
192
  */
210
- VALUE getBackupBlockingFactor(VALUE self)
211
- {
212
- VALUE options = rb_iv_get(self, "@options");
193
+ VALUE getBackupBlockingFactor(VALUE self) {
194
+ VALUE options = rb_iv_get(self, "@options");
213
195
 
214
- return(rb_hash_aref(options, INT2FIX(isc_spb_bkp_factor)));
196
+ return(rb_hash_aref(options, INT2FIX(isc_spb_bkp_factor)));
215
197
  }
216
198
 
217
199
 
@@ -226,17 +208,15 @@ VALUE getBackupBlockingFactor(VALUE self)
226
208
  * @return A reference to the newly updated Backup object.
227
209
  *
228
210
  */
229
- VALUE setBackupBlockingFactor(VALUE self, VALUE setting)
230
- {
231
- VALUE options = rb_iv_get(self, "@options");
211
+ VALUE setBackupBlockingFactor(VALUE self, VALUE setting) {
212
+ VALUE options = rb_iv_get(self, "@options");
232
213
 
233
- if(rb_obj_is_kind_of(setting, rb_cInteger) == Qfalse)
234
- {
235
- rb_fireruby_raise(NULL, "Invalid blocking factor specified for Backup.");
236
- }
237
- rb_hash_aset(options, INT2FIX(isc_spb_bkp_factor), setting);
214
+ if(rb_obj_is_kind_of(setting, rb_cInteger) == Qfalse) {
215
+ rb_fireruby_raise(NULL, "Invalid blocking factor specified for Backup.");
216
+ }
217
+ rb_hash_aset(options, INT2FIX(isc_spb_bkp_factor), setting);
238
218
 
239
- return(self);
219
+ return(self);
240
220
  }
241
221
 
242
222
 
@@ -249,18 +229,16 @@ VALUE setBackupBlockingFactor(VALUE self, VALUE setting)
249
229
  * @return Either true or false.
250
230
  *
251
231
  */
252
- VALUE getBackupIgnoreChecksums(VALUE self)
253
- {
254
- VALUE result = Qfalse,
255
- options = rb_iv_get(self, "@options"),
256
- value = rb_hash_aref(options, IGNORE_CHECKSUMS);
257
-
258
- if(value != Qnil)
259
- {
260
- result = value;
261
- }
262
-
263
- return(result);
232
+ VALUE getBackupIgnoreChecksums(VALUE self) {
233
+ VALUE result = Qfalse,
234
+ options = rb_iv_get(self, "@options"),
235
+ value = rb_hash_aref(options, IGNORE_CHECKSUMS);
236
+
237
+ if(value != Qnil) {
238
+ result = value;
239
+ }
240
+
241
+ return(result);
264
242
  }
265
243
 
266
244
 
@@ -274,16 +252,14 @@ VALUE getBackupIgnoreChecksums(VALUE self)
274
252
  * @return A reference to the newly updated Backup object.
275
253
  *
276
254
  */
277
- VALUE setBackupIgnoreChecksums(VALUE self, VALUE setting)
278
- {
279
- VALUE options = rb_iv_get(self, "@options");
255
+ VALUE setBackupIgnoreChecksums(VALUE self, VALUE setting) {
256
+ VALUE options = rb_iv_get(self, "@options");
280
257
 
281
- if(setting == Qtrue || setting == Qfalse)
282
- {
283
- rb_hash_aset(options, IGNORE_CHECKSUMS, setting);
284
- }
258
+ if(setting == Qtrue || setting == Qfalse) {
259
+ rb_hash_aset(options, IGNORE_CHECKSUMS, setting);
260
+ }
285
261
 
286
- return(self);
262
+ return(self);
287
263
  }
288
264
 
289
265
 
@@ -296,18 +272,16 @@ VALUE setBackupIgnoreChecksums(VALUE self, VALUE setting)
296
272
  * @return Either true or false.
297
273
  *
298
274
  */
299
- VALUE getBackupIgnoreLimbo(VALUE self)
300
- {
301
- VALUE result = Qfalse,
302
- options = rb_iv_get(self, "@options"),
303
- value = rb_hash_aref(options, IGNORE_LIMBO);
304
-
305
- if(value != Qnil)
306
- {
307
- result = value;
308
- }
309
-
310
- return(result);
275
+ VALUE getBackupIgnoreLimbo(VALUE self) {
276
+ VALUE result = Qfalse,
277
+ options = rb_iv_get(self, "@options"),
278
+ value = rb_hash_aref(options, IGNORE_LIMBO);
279
+
280
+ if(value != Qnil) {
281
+ result = value;
282
+ }
283
+
284
+ return(result);
311
285
  }
312
286
 
313
287
 
@@ -321,16 +295,14 @@ VALUE getBackupIgnoreLimbo(VALUE self)
321
295
  * @return A reference to the newly updated Backup object.
322
296
  *
323
297
  */
324
- VALUE setBackupIgnoreLimbo(VALUE self, VALUE setting)
325
- {
326
- VALUE options = rb_iv_get(self, "@options");
298
+ VALUE setBackupIgnoreLimbo(VALUE self, VALUE setting) {
299
+ VALUE options = rb_iv_get(self, "@options");
327
300
 
328
- if(setting == Qtrue || setting == Qfalse)
329
- {
330
- rb_hash_aset(options, IGNORE_LIMBO, setting);
331
- }
301
+ if(setting == Qtrue || setting == Qfalse) {
302
+ rb_hash_aset(options, IGNORE_LIMBO, setting);
303
+ }
332
304
 
333
- return(self);
305
+ return(self);
334
306
  }
335
307
 
336
308
 
@@ -343,18 +315,16 @@ VALUE setBackupIgnoreLimbo(VALUE self, VALUE setting)
343
315
  * @return Either true or false.
344
316
  *
345
317
  */
346
- VALUE getBackupMetadataOnly(VALUE self)
347
- {
348
- VALUE result = Qfalse,
349
- options = rb_iv_get(self, "@options"),
350
- value = rb_hash_aref(options, METADATA_ONLY);
351
-
352
- if(value != Qnil)
353
- {
354
- result = value;
355
- }
356
-
357
- return(result);
318
+ VALUE getBackupMetadataOnly(VALUE self) {
319
+ VALUE result = Qfalse,
320
+ options = rb_iv_get(self, "@options"),
321
+ value = rb_hash_aref(options, METADATA_ONLY);
322
+
323
+ if(value != Qnil) {
324
+ result = value;
325
+ }
326
+
327
+ return(result);
358
328
  }
359
329
 
360
330
 
@@ -368,16 +338,14 @@ VALUE getBackupMetadataOnly(VALUE self)
368
338
  * @return A reference to the newly updated Backup object.
369
339
  *
370
340
  */
371
- VALUE setBackupMetadataOnly(VALUE self, VALUE setting)
372
- {
373
- VALUE options = rb_iv_get(self, "@options");
341
+ VALUE setBackupMetadataOnly(VALUE self, VALUE setting) {
342
+ VALUE options = rb_iv_get(self, "@options");
374
343
 
375
- if(setting == Qtrue || setting == Qfalse)
376
- {
377
- rb_hash_aset(options, METADATA_ONLY, setting);
378
- }
344
+ if(setting == Qtrue || setting == Qfalse) {
345
+ rb_hash_aset(options, METADATA_ONLY, setting);
346
+ }
379
347
 
380
- return(self);
348
+ return(self);
381
349
  }
382
350
 
383
351
 
@@ -390,18 +358,16 @@ VALUE setBackupMetadataOnly(VALUE self, VALUE setting)
390
358
  * @return Either true or false.
391
359
  *
392
360
  */
393
- VALUE getBackupGarbageCollect(VALUE self)
394
- {
395
- VALUE result = Qtrue,
396
- options = rb_iv_get(self, "@options"),
397
- value = rb_hash_aref(options, NO_GARBAGE_COLLECT);
398
-
399
- if(value != Qnil)
400
- {
401
- result = value;
402
- }
403
-
404
- return(result);
361
+ VALUE getBackupGarbageCollect(VALUE self) {
362
+ VALUE result = Qtrue,
363
+ options = rb_iv_get(self, "@options"),
364
+ value = rb_hash_aref(options, NO_GARBAGE_COLLECT);
365
+
366
+ if(value != Qnil) {
367
+ result = value;
368
+ }
369
+
370
+ return(result);
405
371
  }
406
372
 
407
373
 
@@ -415,16 +381,14 @@ VALUE getBackupGarbageCollect(VALUE self)
415
381
  * @return A reference to the newly updated Backup object.
416
382
  *
417
383
  */
418
- VALUE setBackupGarbageCollect(VALUE self, VALUE setting)
419
- {
420
- VALUE options = rb_iv_get(self, "@options");
384
+ VALUE setBackupGarbageCollect(VALUE self, VALUE setting) {
385
+ VALUE options = rb_iv_get(self, "@options");
421
386
 
422
- if(setting == Qtrue || setting == Qfalse)
423
- {
424
- rb_hash_aset(options, NO_GARBAGE_COLLECT, setting);
425
- }
387
+ if(setting == Qtrue || setting == Qfalse) {
388
+ rb_hash_aset(options, NO_GARBAGE_COLLECT, setting);
389
+ }
426
390
 
427
- return(self);
391
+ return(self);
428
392
  }
429
393
 
430
394
 
@@ -437,18 +401,16 @@ VALUE setBackupGarbageCollect(VALUE self, VALUE setting)
437
401
  * @return Either true or false.
438
402
  *
439
403
  */
440
- VALUE getBackupNonTransportable(VALUE self)
441
- {
442
- VALUE result = Qfalse,
443
- options = rb_iv_get(self, "@options"),
444
- value = rb_hash_aref(options, NON_TRANSPORTABLE);
445
-
446
- if(value != Qnil)
447
- {
448
- result = value;
449
- }
450
-
451
- return(result);
404
+ VALUE getBackupNonTransportable(VALUE self) {
405
+ VALUE result = Qfalse,
406
+ options = rb_iv_get(self, "@options"),
407
+ value = rb_hash_aref(options, NON_TRANSPORTABLE);
408
+
409
+ if(value != Qnil) {
410
+ result = value;
411
+ }
412
+
413
+ return(result);
452
414
  }
453
415
 
454
416
 
@@ -462,16 +424,14 @@ VALUE getBackupNonTransportable(VALUE self)
462
424
  * @return A reference to the newly updated Backup object.
463
425
  *
464
426
  */
465
- VALUE setBackupNonTransportable(VALUE self, VALUE setting)
466
- {
467
- VALUE options = rb_iv_get(self, "@options");
427
+ VALUE setBackupNonTransportable(VALUE self, VALUE setting) {
428
+ VALUE options = rb_iv_get(self, "@options");
468
429
 
469
- if(setting == Qtrue || setting == Qfalse)
470
- {
471
- rb_hash_aset(options, NON_TRANSPORTABLE, setting);
472
- }
430
+ if(setting == Qtrue || setting == Qfalse) {
431
+ rb_hash_aset(options, NON_TRANSPORTABLE, setting);
432
+ }
473
433
 
474
- return(self);
434
+ return(self);
475
435
  }
476
436
 
477
437
 
@@ -484,18 +444,16 @@ VALUE setBackupNonTransportable(VALUE self, VALUE setting)
484
444
  * @return Either true or false.
485
445
  *
486
446
  */
487
- VALUE getBackupConvertTables(VALUE self)
488
- {
489
- VALUE result = Qfalse,
490
- options = rb_iv_get(self, "@options"),
491
- value = rb_hash_aref(options, CONVERT_TABLES);
492
-
493
- if(value != Qnil)
494
- {
495
- result = value;
496
- }
497
-
498
- return(result);
447
+ VALUE getBackupConvertTables(VALUE self) {
448
+ VALUE result = Qfalse,
449
+ options = rb_iv_get(self, "@options"),
450
+ value = rb_hash_aref(options, CONVERT_TABLES);
451
+
452
+ if(value != Qnil) {
453
+ result = value;
454
+ }
455
+
456
+ return(result);
499
457
  }
500
458
 
501
459
 
@@ -509,16 +467,14 @@ VALUE getBackupConvertTables(VALUE self)
509
467
  * @return A reference to the newly updated Backup object.
510
468
  *
511
469
  */
512
- VALUE setBackupConvertTables(VALUE self, VALUE setting)
513
- {
514
- VALUE options = rb_iv_get(self, "@options");
470
+ VALUE setBackupConvertTables(VALUE self, VALUE setting) {
471
+ VALUE options = rb_iv_get(self, "@options");
515
472
 
516
- if(setting == Qtrue || setting == Qfalse)
517
- {
518
- rb_hash_aset(options, CONVERT_TABLES, setting);
519
- }
473
+ if(setting == Qtrue || setting == Qfalse) {
474
+ rb_hash_aset(options, CONVERT_TABLES, setting);
475
+ }
520
476
 
521
- return(self);
477
+ return(self);
522
478
  }
523
479
 
524
480
 
@@ -532,36 +488,33 @@ VALUE setBackupConvertTables(VALUE self, VALUE setting)
532
488
  * @return A reference to the Backup object executed.
533
489
  *
534
490
  */
535
- VALUE executeBackup(VALUE self, VALUE manager)
536
- {
537
- ManagerHandle *handle = NULL;
538
- short length = 0;
539
- char *buffer = NULL;
540
- ISC_STATUS status[20];
541
-
542
- /* Check that the service manager is connected. */
543
- Data_Get_Struct(manager, ManagerHandle, handle);
544
- if(handle->handle == 0)
545
- {
546
- rb_fireruby_raise(NULL,
547
- "Database backup error. Service manager not connected.");
548
- }
549
-
550
- createBackupBuffer(rb_iv_get(self, "@database"), rb_iv_get(self, "@files"),
551
- rb_iv_get(self, "@options"), &buffer, &length);
552
-
553
- /* Start the service request. */
554
- if(isc_service_start(status, &handle->handle, NULL, length, buffer))
555
- {
556
- free(buffer);
557
- rb_fireruby_raise(status, "Error performing database backup.");
558
- }
559
- free(buffer);
560
-
561
- /* Query the service until it has completed. */
562
- rb_iv_set(self, "@log", queryService(&handle->handle));
563
-
564
- return(self);
491
+ VALUE executeBackup(VALUE self, VALUE manager) {
492
+ ManagerHandle *handle = NULL;
493
+ short length = 0;
494
+ char *buffer = NULL;
495
+ ISC_STATUS status[ISC_STATUS_LENGTH];
496
+
497
+ /* Check that the service manager is connected. */
498
+ Data_Get_Struct(manager, ManagerHandle, handle);
499
+ if(handle->handle == 0) {
500
+ rb_fireruby_raise(NULL,
501
+ "Database backup error. Service manager not connected.");
502
+ }
503
+
504
+ createBackupBuffer(rb_iv_get(self, "@database"), rb_iv_get(self, "@files"),
505
+ rb_iv_get(self, "@options"), &buffer, &length);
506
+
507
+ /* Start the service request. */
508
+ if(isc_service_start(status, &handle->handle, NULL, length, buffer)) {
509
+ free(buffer);
510
+ rb_fireruby_raise(status, "Error performing database backup.");
511
+ }
512
+ free(buffer);
513
+
514
+ /* Query the service until it has completed. */
515
+ rb_iv_set(self, "@log", queryService(&handle->handle));
516
+
517
+ return(self);
565
518
  }
566
519
 
567
520
 
@@ -573,9 +526,8 @@ VALUE executeBackup(VALUE self, VALUE manager)
573
526
  * @return A reference to the current log attribute value.
574
527
  *
575
528
  */
576
- VALUE getBackupLog(VALUE self)
577
- {
578
- return(rb_iv_get(self, "@log"));
529
+ VALUE getBackupLog(VALUE self) {
530
+ return(rb_iv_get(self, "@log"));
579
531
  }
580
532
 
581
533
 
@@ -597,158 +549,140 @@ VALUE getBackupLog(VALUE self)
597
549
  *
598
550
  */
599
551
  void createBackupBuffer(VALUE from, VALUE to, VALUE options, char **buffer,
600
- short *length)
601
- {
602
- ID id = rb_intern("key?");
603
- VALUE names = rb_funcall(to, rb_intern("keys"), 0),
604
- sizes = rb_funcall(to, rb_intern("values"), 0),
605
- count = rb_funcall(names, rb_intern("size"), 0),
606
- tmp_str = Qnil;
607
- char *position = NULL;
608
- short number,
609
- flags = 0,
610
- extras = 0,
611
- blocking = 0,
612
- size = TYPE(count) == T_FIXNUM ? FIX2INT(count) : NUM2INT(count),
613
- i;
614
-
615
- /* Check if extra options have been provided. */
616
- if(TYPE(options) != T_NIL)
617
- {
618
- VALUE temp = rb_funcall(options, rb_intern("size"), 0);
619
-
620
- extras = TYPE(temp) == T_FIXNUM ? FIX2INT(temp) : NUM2INT(temp);
621
- }
622
-
623
- /* Calculate the length needed for the buffer. */
624
- *length = 2;
625
- *length += strlen(StringValuePtr(from)) + 3;
626
-
627
- /* Count file name and length sizes. */
628
- for(i = 0; i < size; i++)
629
- {
630
- tmp_str = rb_ary_entry(names, i);
631
- *length += strlen(StringValuePtr(tmp_str)) + 3;
632
- if(i != size - 1)
633
- {
634
- VALUE num = rb_funcall(rb_ary_entry(sizes, i), rb_intern("to_s"), 0);
635
-
636
- *length += strlen(StringValuePtr(num)) + 3;
637
- }
638
- }
639
-
640
- if(extras)
641
- {
642
- if(rb_funcall(options, id, 1, INT2FIX(isc_spb_bkp_factor)) == Qtrue)
643
- {
644
- *length += 5;
645
- blocking = 1;
646
- }
647
-
648
- if(rb_funcall(options, id, 1, IGNORE_CHECKSUMS) == Qtrue ||
649
- rb_funcall(options, id, 1, IGNORE_LIMBO) == Qtrue ||
650
- rb_funcall(options, id, 1, METADATA_ONLY) == Qtrue ||
651
- rb_funcall(options, id, 1, NO_GARBAGE_COLLECT) == Qtrue ||
652
- rb_funcall(options, id, 1, NON_TRANSPORTABLE) == Qtrue ||
653
- rb_funcall(options, id, 1, CONVERT_TABLES) == Qtrue)
654
- {
655
- *length += 5;
656
- flags = 1;
657
- }
658
- }
659
-
660
- /* Allocate the buffer. */
661
- *buffer = position = ALLOC_N(char, *length);
662
- if(*buffer == NULL)
663
- {
664
- rb_raise(rb_eNoMemError,
665
- "Memory allocation error preparing database back up.");
666
- }
667
- memset(*buffer, 0, *length);
668
-
669
- /* Populate the buffer. */
670
- *position++ = isc_action_svc_backup;
671
-
672
- *position++ = isc_spb_dbname;
673
- number = strlen(StringValuePtr(from));
674
- ADD_SPB_LENGTH(position, number);
675
- memcpy(position, StringValuePtr(from), number);
676
- position += number;
677
-
678
- for(i = 0; i < size; i++)
679
- {
680
- VALUE name = rb_ary_entry(names, i);
681
-
682
- *position++ = isc_spb_bkp_file;
683
- number = strlen(StringValuePtr(name));
552
+ short *length) {
553
+ ID id = rb_intern("key?");
554
+ VALUE names = rb_funcall(to, rb_intern("keys"), 0),
555
+ sizes = rb_funcall(to, rb_intern("values"), 0),
556
+ count = rb_funcall(names, rb_intern("size"), 0),
557
+ tmp_str = Qnil;
558
+ char *position = NULL;
559
+ short number,
560
+ flags = 0,
561
+ extras = 0,
562
+ blocking = 0,
563
+ size = TYPE(count) == T_FIXNUM ? FIX2INT(count) : NUM2INT(count),
564
+ i;
565
+
566
+ /* Check if extra options have been provided. */
567
+ if(TYPE(options) != T_NIL) {
568
+ VALUE temp = rb_funcall(options, rb_intern("size"), 0);
569
+
570
+ extras = TYPE(temp) == T_FIXNUM ? FIX2INT(temp) : NUM2INT(temp);
571
+ }
572
+
573
+ /* Calculate the length needed for the buffer. */
574
+ *length = 2;
575
+ *length += strlen(StringValuePtr(from)) + 3;
576
+
577
+ /* Count file name and length sizes. */
578
+ for(i = 0; i < size; i++) {
579
+ tmp_str = rb_ary_entry(names, i);
580
+ *length += strlen(StringValuePtr(tmp_str)) + 3;
581
+ if(i != size - 1) {
582
+ VALUE num = rb_funcall(rb_ary_entry(sizes, i), rb_intern("to_s"), 0);
583
+
584
+ *length += strlen(StringValuePtr(num)) + 3;
585
+ }
586
+ }
587
+
588
+ if(extras) {
589
+ if(rb_funcall(options, id, 1, INT2FIX(isc_spb_bkp_factor)) == Qtrue) {
590
+ *length += 5;
591
+ blocking = 1;
592
+ }
593
+
594
+ if(rb_funcall(options, id, 1, IGNORE_CHECKSUMS) == Qtrue ||
595
+ rb_funcall(options, id, 1, IGNORE_LIMBO) == Qtrue ||
596
+ rb_funcall(options, id, 1, METADATA_ONLY) == Qtrue ||
597
+ rb_funcall(options, id, 1, NO_GARBAGE_COLLECT) == Qtrue ||
598
+ rb_funcall(options, id, 1, NON_TRANSPORTABLE) == Qtrue ||
599
+ rb_funcall(options, id, 1, CONVERT_TABLES) == Qtrue) {
600
+ *length += 5;
601
+ flags = 1;
602
+ }
603
+ }
604
+
605
+ /* Allocate the buffer. */
606
+ *buffer = position = ALLOC_N(char, *length);
607
+ if(*buffer == NULL) {
608
+ rb_raise(rb_eNoMemError,
609
+ "Memory allocation error preparing database back up.");
610
+ }
611
+ memset(*buffer, 0, *length);
612
+
613
+ /* Populate the buffer. */
614
+ *position++ = isc_action_svc_backup;
615
+
616
+ *position++ = isc_spb_dbname;
617
+ number = strlen(StringValuePtr(from));
618
+ ADD_SPB_LENGTH(position, number);
619
+ memcpy(position, StringValuePtr(from), number);
620
+ position += number;
621
+
622
+ for(i = 0; i < size; i++) {
623
+ VALUE name = rb_ary_entry(names, i);
624
+
625
+ *position++ = isc_spb_bkp_file;
626
+ number = strlen(StringValuePtr(name));
627
+ ADD_SPB_LENGTH(position, number);
628
+ memcpy(position, StringValuePtr(name), number);
629
+ position += number;
630
+
631
+ if(i != size - 1) {
632
+ VALUE max = rb_ary_entry(sizes, i);
633
+
634
+ max = rb_funcall(max, rb_intern("to_s"), 0);
635
+ *position++ = isc_spb_bkp_length;
636
+ number = strlen(StringValuePtr(max));
684
637
  ADD_SPB_LENGTH(position, number);
685
- memcpy(position, StringValuePtr(name), number);
638
+ memcpy(position, StringValuePtr(max), number);
686
639
  position += number;
640
+ }
641
+ }
642
+
643
+ if(extras && blocking) {
644
+ VALUE key = INT2FIX(isc_spb_bkp_factor),
645
+ temp = rb_funcall(options, rb_intern("fetch"), 1, key);
646
+ unsigned long size = TYPE(temp) == T_FIXNUM ? FIX2INT(temp) : NUM2INT(temp);
647
+
648
+ *position++ = isc_spb_bkp_factor;
649
+ memcpy(position, &size, 4);
650
+ position += 4;
651
+ }
652
+
653
+ if(extras && flags) {
654
+ unsigned long mask = 0;
655
+
656
+ if(rb_funcall(options, id, 1, IGNORE_CHECKSUMS) == Qtrue) {
657
+ mask |= isc_spb_bkp_ignore_checksums;
658
+ }
659
+
660
+ if(rb_funcall(options, id, 1, IGNORE_LIMBO) == Qtrue) {
661
+ mask |= isc_spb_bkp_ignore_limbo;
662
+ }
663
+
664
+ if(rb_funcall(options, id, 1, METADATA_ONLY) == Qtrue) {
665
+ mask |= isc_spb_bkp_metadata_only;
666
+ }
667
+
668
+ if(rb_funcall(options, id, 1, NO_GARBAGE_COLLECT) == Qtrue) {
669
+ mask |= isc_spb_bkp_no_garbage_collect;
670
+ }
671
+
672
+ if(rb_funcall(options, id, 1, NON_TRANSPORTABLE) == Qtrue) {
673
+ mask |= isc_spb_bkp_non_transportable;
674
+ }
675
+
676
+ if(rb_funcall(options, id, 1, CONVERT_TABLES) == Qtrue) {
677
+ mask |= isc_spb_bkp_convert;
678
+ }
679
+
680
+ *position++ = isc_spb_options;
681
+ memcpy(position, &mask, 4);
682
+ position += 4;
683
+ }
687
684
 
688
- if(i != size - 1)
689
- {
690
- VALUE max = rb_ary_entry(sizes, i);
691
-
692
- max = rb_funcall(max, rb_intern("to_s"), 0);
693
- *position++ = isc_spb_bkp_length;
694
- number = strlen(StringValuePtr(max));
695
- ADD_SPB_LENGTH(position, number);
696
- memcpy(position, StringValuePtr(max), number);
697
- position += number;
698
- }
699
- }
700
-
701
- if(extras && blocking)
702
- {
703
- VALUE key = INT2FIX(isc_spb_bkp_factor),
704
- temp = rb_funcall(options, rb_intern("fetch"), 1, key);
705
- unsigned long size = TYPE(temp) == T_FIXNUM ? FIX2INT(temp) : NUM2INT(temp);
706
-
707
- *position++ = isc_spb_bkp_factor;
708
- memcpy(position, &size, 4);
709
- position += 4;
710
- }
711
-
712
- if(extras && flags)
713
- {
714
- unsigned long mask = 0;
715
-
716
- if(rb_funcall(options, id, 1, IGNORE_CHECKSUMS) == Qtrue)
717
- {
718
- mask |= isc_spb_bkp_ignore_checksums;
719
- }
720
-
721
- if(rb_funcall(options, id, 1, IGNORE_LIMBO) == Qtrue)
722
- {
723
- mask |= isc_spb_bkp_ignore_limbo;
724
- }
725
-
726
- if(rb_funcall(options, id, 1, METADATA_ONLY) == Qtrue)
727
- {
728
- mask |= isc_spb_bkp_metadata_only;
729
- }
730
-
731
- if(rb_funcall(options, id, 1, NO_GARBAGE_COLLECT) == Qtrue)
732
- {
733
- mask |= isc_spb_bkp_no_garbage_collect;
734
- }
735
-
736
- if(rb_funcall(options, id, 1, NON_TRANSPORTABLE) == Qtrue)
737
- {
738
- mask |= isc_spb_bkp_non_transportable;
739
- }
740
-
741
- if(rb_funcall(options, id, 1, CONVERT_TABLES) == Qtrue)
742
- {
743
- mask |= isc_spb_bkp_convert;
744
- }
745
-
746
- *position++ = isc_spb_options;
747
- memcpy(position, &mask, 4);
748
- position += 4;
749
- }
750
-
751
- *position++ = isc_spb_verbose;
685
+ *position++ = isc_spb_verbose;
752
686
  }
753
687
 
754
688
 
@@ -758,28 +692,27 @@ void createBackupBuffer(VALUE from, VALUE to, VALUE options, char **buffer,
758
692
  * @param module The module to create the new class definition under.
759
693
  *
760
694
  */
761
- void Init_Backup(VALUE module)
762
- {
763
- cBackup = rb_define_class_under(module, "Backup", rb_cObject);
764
- rb_define_method(cBackup, "initialize", initializeBackup, 2);
765
- rb_define_method(cBackup, "backup_file", getBackupFile, 0);
766
- rb_define_method(cBackup, "backup_file=", setBackupFile, 1);
767
- rb_define_method(cBackup, "database", getBackupDatabase, 0);
768
- rb_define_method(cBackup, "database=", setBackupDatabase, 1);
769
- rb_define_method(cBackup, "blocking_factor", getBackupBlockingFactor, 0);
770
- rb_define_method(cBackup, "blocking_factor=", setBackupBlockingFactor, 1);
771
- rb_define_method(cBackup, "ignore_checksums", getBackupIgnoreChecksums, 0);
772
- rb_define_method(cBackup, "ignore_checksums=", setBackupIgnoreChecksums, 1);
773
- rb_define_method(cBackup, "ignore_limbo", getBackupIgnoreLimbo, 0);
774
- rb_define_method(cBackup, "ignore_limbo=", setBackupIgnoreLimbo, 1);
775
- rb_define_method(cBackup, "metadata_only", getBackupMetadataOnly, 0);
776
- rb_define_method(cBackup, "metadata_only=", setBackupMetadataOnly, 1);
777
- rb_define_method(cBackup, "garbage_collect", getBackupGarbageCollect, 0);
778
- rb_define_method(cBackup, "garbage_collect=", setBackupGarbageCollect, 1);
779
- rb_define_method(cBackup, "non_transportable", getBackupNonTransportable, 0);
780
- rb_define_method(cBackup, "non_transportable=", setBackupNonTransportable, 1);
781
- rb_define_method(cBackup, "convert_tables", getBackupConvertTables, 0);
782
- rb_define_method(cBackup, "convert_tables=", setBackupConvertTables, 1);
783
- rb_define_method(cBackup, "execute", executeBackup, 1);
784
- rb_define_method(cBackup, "log", getBackupLog, 0);
695
+ void Init_Backup(VALUE module) {
696
+ cBackup = rb_define_class_under(module, "Backup", rb_cObject);
697
+ rb_define_method(cBackup, "initialize", initializeBackup, 2);
698
+ rb_define_method(cBackup, "backup_file", getBackupFile, 0);
699
+ rb_define_method(cBackup, "backup_file=", setBackupFile, 1);
700
+ rb_define_method(cBackup, "database", getBackupDatabase, 0);
701
+ rb_define_method(cBackup, "database=", setBackupDatabase, 1);
702
+ rb_define_method(cBackup, "blocking_factor", getBackupBlockingFactor, 0);
703
+ rb_define_method(cBackup, "blocking_factor=", setBackupBlockingFactor, 1);
704
+ rb_define_method(cBackup, "ignore_checksums", getBackupIgnoreChecksums, 0);
705
+ rb_define_method(cBackup, "ignore_checksums=", setBackupIgnoreChecksums, 1);
706
+ rb_define_method(cBackup, "ignore_limbo", getBackupIgnoreLimbo, 0);
707
+ rb_define_method(cBackup, "ignore_limbo=", setBackupIgnoreLimbo, 1);
708
+ rb_define_method(cBackup, "metadata_only", getBackupMetadataOnly, 0);
709
+ rb_define_method(cBackup, "metadata_only=", setBackupMetadataOnly, 1);
710
+ rb_define_method(cBackup, "garbage_collect", getBackupGarbageCollect, 0);
711
+ rb_define_method(cBackup, "garbage_collect=", setBackupGarbageCollect, 1);
712
+ rb_define_method(cBackup, "non_transportable", getBackupNonTransportable, 0);
713
+ rb_define_method(cBackup, "non_transportable=", setBackupNonTransportable, 1);
714
+ rb_define_method(cBackup, "convert_tables", getBackupConvertTables, 0);
715
+ rb_define_method(cBackup, "convert_tables=", setBackupConvertTables, 1);
716
+ rb_define_method(cBackup, "execute", executeBackup, 1);
717
+ rb_define_method(cBackup, "log", getBackupLog, 0);
785
718
  }