File Coverage

BackupPC_XS.xs
Criterion Covered Total %
statement 0 303 0.0
branch 0 262 0.0
condition n/a
subroutine n/a
pod n/a
total 0 565 0.0


line stmt bran cond sub pod time code
1             /*
2             * XS glue for perl interface to BackupPC libraries.
3             *
4             * Copyright (C) 2013 Craig Barratt.
5             *
6             * This program is free software; you can redistribute it and/or modify
7             * it under the terms of the GNU General Public License as published by
8             * the Free Software Foundation; either version 3 of the License, or
9             * (at your option) any later version.
10             *
11             * This program is distributed in the hope that it will be useful,
12             * but WITHOUT ANY WARRANTY; without even the implied warranty of
13             * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14             * GNU General Public License for more details.
15             *
16             * You should have received a copy of the GNU General Public License along
17             * with this program; if not, visit the http://fsf.org website.
18             */
19              
20              
21             #include "EXTERN.h"
22             #include "perl.h"
23             #include "XSUB.h"
24              
25             #include "ppport.h"
26              
27             #include
28              
29             typedef bpc_fileZIO_fd *BackupPC__XS__FileZIO;
30             typedef bpc_refCount_info *BackupPC__XS__PoolRefCnt;
31             typedef bpc_deltaCount_info *BackupPC__XS__DeltaRefCnt;
32             typedef bpc_poolWrite_info *BackupPC__XS__PoolWrite;
33             typedef bpc_attrib_dir *BackupPC__XS__Attrib;
34             typedef bpc_attribCache_info *BackupPC__XS__AttribCache;
35              
36             #define hv_get_int(hv, key, value) { SV** svp = hv_fetch((hv), (key), strlen(key), 0); if ( svp && *svp ) (value) = SvIV(*svp); }
37             #define hv_get_uint(hv, key, value) { SV** svp = hv_fetch((hv), (key), strlen(key), 0); if ( svp && *svp ) (value) = SvUV(*svp); }
38             #define hv_get_str(hv, key, value, len) { SV** svp = hv_fetch((hv), (key), strlen(key), 0); if ( svp && *svp ) (value) = SvPV(*svp, len); }
39              
40 0           static HV* convert_file2hv(bpc_attrib_file *file, char *fileName)
41             {
42             HV *rh;
43             size_t listLen, i;
44              
45 0           rh = newHV();
46 0           (void)hv_store(rh, "uid", 3, newSVuv(file->uid), 0);
47 0           (void)hv_store(rh, "gid", 3, newSVuv(file->gid), 0);
48 0           (void)hv_store(rh, "name", 4, newSVpvn(fileName, strlen(fileName)), 0);
49 0           (void)hv_store(rh, "type", 4, newSVuv(file->type), 0);
50 0           (void)hv_store(rh, "mode", 4, newSVuv(file->mode), 0);
51 0           (void)hv_store(rh, "size", 4, newSVuv(file->size), 0);
52 0           (void)hv_store(rh, "mtime", 5, newSViv(file->mtime), 0);
53 0           (void)hv_store(rh, "inode", 5, newSVuv(file->inode), 0);
54 0           (void)hv_store(rh, "nlinks", 6, newSVuv(file->nlinks), 0);
55 0           (void)hv_store(rh, "digest", 6, newSVpvn((char*)file->digest.digest, file->digest.len), 0);
56 0           (void)hv_store(rh, "compress", 8, newSVuv(file->compress), 0);
57              
58 0 0         if ( (listLen = bpc_attrib_xattrList(file, NULL, 0, 0)) > 0 ) {
59 0           char *keys = malloc(listLen), *p;
60              
61 0 0         if ( keys && bpc_attrib_xattrList(file, keys, listLen, 0) > 0 ) {
    0          
62 0           HV *rhAttr = newHV();
63 0 0         for ( i = 0, p = keys ; i < listLen ; ) {
64 0           int len = strlen(p);
65             /*
66             * xattr keys include the \0 terminating byte in the length, so add 1 here,
67             * and subtract 1 in the hv_store() below.
68             */
69 0           bpc_attrib_xattr *xattr = bpc_attrib_xattrGet(file, p, len + 1, 0);
70 0           p += len + 1;
71 0           i += len + 1;
72 0 0         if ( !xattr ) continue;
73 0           (void)hv_store(rhAttr, xattr->key.key, xattr->key.keyLen - 1, newSVpvn(xattr->value, xattr->valueLen), 0);
74             }
75 0           (void)hv_store(rh, "xattr", 5, newRV_noinc((SV*)rhAttr), 0);
76             }
77 0 0         if ( keys ) free(keys);
78             }
79 0           return rh;
80             }
81              
82 0           static void convert_hv2file(HV *hv, bpc_attrib_file *file)
83             {
84 0           char *digestStr = "";
85 0           STRLEN digestLen = 0;
86             SV** svp;
87              
88 0 0         hv_get_uint(hv, "uid", file->uid);
    0          
    0          
89 0 0         hv_get_uint(hv, "gid", file->gid);
    0          
    0          
90 0 0         hv_get_uint(hv, "type", file->type);
    0          
    0          
91 0 0         hv_get_uint(hv, "mode", file->mode);
    0          
    0          
92 0 0         hv_get_uint(hv, "size", file->size);
    0          
    0          
93 0 0         hv_get_int(hv, "mtime", file->mtime);
    0          
    0          
94 0 0         hv_get_uint(hv, "inode", file->inode);
    0          
    0          
95 0 0         hv_get_uint(hv, "nlinks", file->nlinks);
    0          
    0          
96 0 0         hv_get_uint(hv, "compress", file->compress);
    0          
    0          
97 0 0         hv_get_str(hv, "digest", digestStr, digestLen);
    0          
    0          
98 0 0         if ( 0 < digestLen && digestLen <= sizeof(file->digest.digest) ) {
    0          
99 0           memcpy(file->digest.digest, digestStr, digestLen);
100 0           file->digest.len = digestLen;
101             } else {
102 0           file->digest.len = 0;
103             }
104 0 0         if ( (svp = hv_fetch(hv, "xattr", 5, 0)) && *svp ) {
    0          
105 0 0         if ( SvTYPE(SvRV(*svp)) != SVt_PVHV ) {
106 0           bpc_attrib_xattrDeleteAll(file);
107             } else {
108             HE *he;
109 0           HV *hvXattr = (HV*)SvRV(*svp);
110             /*
111             * clear out the old xattrs, and copy in the new
112             */
113 0           bpc_attrib_xattrDeleteAll(file);
114 0           hv_iterinit(hvXattr);
115 0 0         while ( (he = hv_iternext(hvXattr)) ) {
116             I32 keyLen;
117             STRLEN valueLen;
118 0           char *key = hv_iterkey(he, &keyLen), *value;
119 0           SV *valSV = hv_iterval(hvXattr, he);
120              
121 0 0         value = SvPV(valSV, valueLen);
122 0           bpc_attrib_xattrSetValue(file, key, keyLen + 1, value, valueLen);
123             }
124             }
125             }
126 0           }
127              
128             MODULE = BackupPC::XS PACKAGE = BackupPC::XS::FileZIO
129              
130             PROTOTYPES: DISABLE
131              
132             BackupPC::XS::FileZIO
133             open(fileName, writeFile, compressLevel)
134             char *fileName;
135             int writeFile;
136             int compressLevel;
137             CODE:
138             {
139 0           RETVAL = calloc(1, sizeof(bpc_fileZIO_fd));
140 0 0         if ( bpc_fileZIO_open(RETVAL, fileName, writeFile, compressLevel) < 0 ) {
141 0           free(RETVAL);
142 0           XSRETURN_UNDEF;
143             }
144             }
145             OUTPUT:
146             RETVAL
147              
148             BackupPC::XS::FileZIO
149             fdopen(stream, writeFile, compressLevel)
150             FILE *stream;
151             int writeFile;
152             int compressLevel;
153             CODE:
154             {
155 0           RETVAL = calloc(1, sizeof(bpc_fileZIO_fd));
156 0 0         if ( bpc_fileZIO_fdopen(RETVAL, stream, writeFile, compressLevel) < 0 ) {
157 0           free(RETVAL);
158 0           XSRETURN_UNDEF;
159             }
160             }
161             OUTPUT:
162             RETVAL
163              
164             void
165             DESTROY(fd)
166             BackupPC::XS::FileZIO fd;
167             CODE:
168 0           bpc_fileZIO_close(fd);
169 0           free(fd);
170              
171             void
172             close(fd)
173             BackupPC::XS::FileZIO fd
174             CODE:
175             {
176 0           bpc_fileZIO_close(fd);
177             }
178              
179             int
180             rewind(fd)
181             BackupPC::XS::FileZIO fd
182             CODE:
183             {
184 0           RETVAL = bpc_fileZIO_rewind(fd);
185             }
186             OUTPUT:
187             RETVAL
188              
189             int
190             write(fd, data)
191             BackupPC::XS::FileZIO fd;
192             SV *data;
193             CODE:
194             {
195             char *str;
196             STRLEN len;
197              
198 0 0         if ( SvROK(data) ) {
199 0 0         str = SvPV(SvRV(data), len);
200 0           RETVAL = bpc_fileZIO_write(fd, (unsigned char*)str, len);
201             } else {
202 0           RETVAL = -1;
203             }
204             }
205             OUTPUT:
206             RETVAL
207              
208             int
209             read(fd, data, len)
210             BackupPC::XS::FileZIO fd;
211             SV *data;
212             STRLEN len
213             CODE:
214             {
215             char *str;
216             SV *d;
217             STRLEN dLen;
218              
219 0 0         if ( SvROK(data) ) {
220 0           d = SvRV(data);
221 0 0         if (! SvOK(d))
    0          
    0          
222 0           sv_setpvs(d, "");
223 0 0         SvGROW(d, len);
    0          
224 0 0         str = SvPV(d, dLen);
225 0           RETVAL = bpc_fileZIO_read(fd, (unsigned char*)str, len);
226 0 0         if ( RETVAL >= 0 ) {
227 0           SvCUR_set(d, RETVAL);
228             } else {
229 0           SvCUR_set(d, 0);
230             }
231             } else {
232 0           RETVAL = -1;
233             }
234             }
235             OUTPUT:
236             RETVAL
237              
238             SV*
239             readLine(fd)
240             BackupPC::XS::FileZIO fd;
241             CODE:
242             {
243             char *str;
244             size_t strLen;
245 0 0         if ( bpc_fileZIO_readLine(fd, &str, &strLen) || !str ) XSRETURN_UNDEF;
    0          
246 0           RETVAL = newSVpvn(str, strLen);
247             }
248             OUTPUT:
249             RETVAL
250              
251             void
252             writeTeeStderr(fd, tee)
253             BackupPC::XS::FileZIO fd;
254             int tee;
255             CODE:
256 0           bpc_fileZIO_writeTeeStderr(fd, tee);
257              
258             MODULE = BackupPC::XS PACKAGE = BackupPC::XS::PoolRefCnt
259              
260             BackupPC::XS::PoolRefCnt
261             new(entryCnt = 65536)
262             int entryCnt;
263             CODE:
264             {
265 0           RETVAL = calloc(1, sizeof(bpc_refCount_info));
266 0           bpc_poolRefInit((bpc_refCount_info*)RETVAL, entryCnt);
267             }
268             OUTPUT:
269             RETVAL
270              
271             void
272             DESTROY(info)
273             BackupPC::XS::PoolRefCnt info;
274             CODE:
275             {
276 0           bpc_poolRefDestroy(info);
277 0           free(info);
278             }
279              
280             int
281             get(info, d)
282             BackupPC::XS::PoolRefCnt info;
283             SV *d;
284             CODE:
285             {
286             bpc_digest digest;
287             char *str;
288             STRLEN len;
289             int count;
290              
291 0 0         if ( !SvPOK(d) ) {
292 0           XSRETURN_UNDEF;
293             }
294 0 0         str = SvPV(d, len);
295 0 0         if ( 0 < len && len < sizeof(digest.digest) ) {
    0          
296 0           memcpy(digest.digest, str, len);
297 0           digest.len = len;
298 0 0         if ( bpc_poolRefGet(info, &digest, &count) ) XSRETURN_UNDEF;
299 0           RETVAL = count;
300             } else {
301 0           XSRETURN_UNDEF;
302             }
303             }
304             OUTPUT:
305             RETVAL
306              
307             int
308             set(info, d, count)
309             BackupPC::XS::PoolRefCnt info;
310             SV *d;
311             int count;
312             CODE:
313             {
314             bpc_digest digest;
315             char *str;
316             STRLEN len;
317              
318 0 0         if ( !SvPOK(d) ) {
319 0           XSRETURN_UNDEF;
320             }
321 0 0         str = SvPV(d, len);
322 0 0         if ( 0 < len && len < sizeof(digest.digest) ) {
    0          
323 0           memcpy(digest.digest, str, len);
324 0           digest.len = len;
325 0           bpc_poolRefSet(info, &digest, count);
326 0           RETVAL = count;
327             } else {
328 0           XSRETURN_UNDEF;
329             }
330             }
331             OUTPUT:
332             RETVAL
333              
334             int
335             delete(info, d)
336             BackupPC::XS::PoolRefCnt info;
337             SV *d;
338             CODE:
339             {
340             bpc_digest digest;
341             char *str;
342             STRLEN len;
343              
344 0 0         if ( !SvPOK(d) ) {
345 0           XSRETURN_UNDEF;
346             }
347 0 0         str = SvPV(d, len);
348 0 0         if ( 0 < len && len < sizeof(digest.digest) ) {
    0          
349 0           memcpy(digest.digest, str, len);
350 0           digest.len = len;
351 0 0         if ( bpc_poolRefDelete(info, &digest) ) XSRETURN_UNDEF;
352 0           RETVAL = 1;
353             } else {
354 0           XSRETURN_UNDEF;
355             }
356             }
357             OUTPUT:
358             RETVAL
359              
360             int
361             incr(info, d, delta)
362             BackupPC::XS::PoolRefCnt info;
363             SV *d;
364             int delta;
365             CODE:
366             {
367             bpc_digest digest;
368             char *str;
369             STRLEN len;
370              
371 0 0         if ( !SvPOK(d) ) {
372 0           XSRETURN_UNDEF;
373             }
374 0 0         str = SvPV(d, len);
375 0 0         if ( 0 < len && len < sizeof(digest.digest) ) {
    0          
376 0           memcpy(digest.digest, str, len);
377 0           digest.len = len;
378 0           RETVAL = bpc_poolRefIncr(info, &digest, delta);
379             } else {
380 0           XSRETURN_UNDEF;
381             }
382             }
383             OUTPUT:
384             RETVAL
385              
386             void
387             iterate(info, idx)
388             BackupPC::XS::PoolRefCnt info;
389             unsigned int idx;
390             PREINIT:
391             bpc_digest digest;
392             int count;
393             PPCODE:
394             {
395 0 0         if ( !bpc_poolRefIterate(info, &digest, &count, &idx) ) {
396 0 0         EXTEND(SP, 3);
397 0           PUSHs(sv_2mortal(newSVpvn((char*)digest.digest, digest.len)));
398 0           PUSHs(sv_2mortal(newSViv(count)));
399 0           PUSHs(sv_2mortal(newSViv(idx)));
400             }
401             }
402              
403             int
404             read(info, fileName)
405             BackupPC::XS::PoolRefCnt info;
406             char *fileName;
407             CODE:
408 0           RETVAL = bpc_poolRefFileRead(info, fileName);
409             OUTPUT:
410             RETVAL
411              
412             int
413             write(info, fileName)
414             BackupPC::XS::PoolRefCnt info;
415             char *fileName;
416             CODE:
417 0           RETVAL = bpc_poolRefFileWrite(info, fileName);
418             OUTPUT:
419             RETVAL
420              
421             void
422             print(info)
423             BackupPC::XS::PoolRefCnt info;
424             CODE:
425 0           bpc_poolRefCountPrint(info);
426              
427             void
428             DeltaFileInit(hostDir)
429             char *hostDir;
430             CODE:
431 0           bpc_poolRefDeltaFileInitOld(hostDir);
432              
433             unsigned int
434             DeltaFileFlush()
435             CODE:
436 0           RETVAL = bpc_poolRefDeltaFileFlushOld();
437             OUTPUT:
438             RETVAL
439              
440             void
441             DeltaUpdate(compress, d, count)
442             int compress;
443             SV *d;
444             int count;
445             CODE:
446             {
447             bpc_digest digest;
448             char *str;
449             STRLEN len;
450              
451 0 0         if ( SvPOK(d) ) {
452 0 0         str = SvPV(d, len);
453 0 0         if ( 0 < len && len < sizeof(digest.digest) ) {
    0          
454 0           memcpy(digest.digest, str, len);
455 0           digest.len = len;
456 0           bpc_poolRefDeltaUpdateOld(compress, &digest, count);
457             }
458             }
459             }
460              
461             void
462             DeltaPrint()
463             CODE:
464 0           bpc_poolRefDeltaPrintOld();
465              
466             MODULE = BackupPC::XS PACKAGE = BackupPC::XS::DeltaRefCnt
467              
468             BackupPC::XS::DeltaRefCnt
469             new(targetDir)
470             char *targetDir;
471             CODE:
472             {
473 0           RETVAL = calloc(1, sizeof(bpc_deltaCount_info));
474 0           bpc_poolRefDeltaFileInit((bpc_deltaCount_info*)RETVAL, targetDir);
475             }
476             OUTPUT:
477             RETVAL
478              
479             void
480             DESTROY(info)
481             BackupPC::XS::DeltaRefCnt info;
482             CODE:
483             {
484 0           bpc_poolRefDeltaFileDestroy(info);
485 0           free(info);
486             }
487              
488             unsigned int
489             flush(info)
490             BackupPC::XS::DeltaRefCnt info;
491             CODE:
492 0           RETVAL = bpc_poolRefDeltaFileFlush(info);
493             OUTPUT:
494             RETVAL
495              
496             void
497             update(info, compress, d, count)
498             BackupPC::XS::DeltaRefCnt info;
499             int compress;
500             SV *d;
501             int count;
502             CODE:
503             {
504             bpc_digest digest;
505             char *str;
506             STRLEN len;
507              
508 0 0         if ( SvPOK(d) ) {
509 0 0         str = SvPV(d, len);
510 0 0         if ( 0 < len && len < sizeof(digest.digest) ) {
    0          
511 0           memcpy(digest.digest, str, len);
512 0           digest.len = len;
513 0           bpc_poolRefDeltaUpdate(info, compress, &digest, count);
514             }
515             }
516             }
517              
518             void
519             print(info)
520             BackupPC::XS::DeltaRefCnt info;
521             CODE:
522 0           bpc_poolRefDeltaPrint(info);
523              
524             MODULE = BackupPC::XS PACKAGE = BackupPC::XS::PoolWrite
525              
526             BackupPC::XS::PoolWrite
527             new(compressLevel, d = NULL)
528             int compressLevel;
529             SV *d;
530             CODE:
531             {
532 0           int ret = 0;
533              
534 0           RETVAL = calloc(1, sizeof(bpc_poolWrite_info));
535 0 0         if ( d && SvPOK(d) ) {
    0          
536             bpc_digest digest;
537             char *str;
538             STRLEN len;
539              
540 0 0         str = SvPV(d, len);
541 0 0         if ( 0 < len && len < sizeof(digest.digest) ) {
    0          
542 0           memcpy(digest.digest, str, len);
543 0           digest.len = len;
544 0           ret = bpc_poolWrite_open(RETVAL, compressLevel, &digest);
545             } else {
546 0           ret = bpc_poolWrite_open(RETVAL, compressLevel, NULL);
547             }
548             } else {
549 0           ret = bpc_poolWrite_open(RETVAL, compressLevel, NULL);
550             }
551 0 0         if ( ret ) {
552 0           free(RETVAL);
553 0           RETVAL = NULL;
554             }
555             }
556             OUTPUT:
557             RETVAL
558              
559             void
560             DESTROY(info)
561             BackupPC::XS::PoolWrite info;
562             CODE:
563             {
564 0           bpc_poolWrite_cleanup(info);
565 0           free(info);
566             }
567              
568             void
569             close(info)
570             BackupPC::XS::PoolWrite info;
571             PREINIT:
572             int match;
573             bpc_digest digest;
574             off_t poolFileSize;
575             int errorCnt;
576              
577             PPCODE:
578             {
579 0           bpc_poolWrite_close(info, &match, &digest, &poolFileSize, &errorCnt);
580 0 0         EXTEND(SP, 4);
581 0           PUSHs(sv_2mortal(newSViv(match)));
582 0           PUSHs(sv_2mortal(newSVpvn((char*)digest.digest, digest.len)));
583 0           PUSHs(sv_2mortal(newSViv(poolFileSize)));
584 0           PUSHs(sv_2mortal(newSViv(errorCnt)));
585             }
586              
587             int
588             write(info, data)
589             BackupPC::XS::PoolWrite info;
590             SV *data;
591             CODE:
592             {
593             char *str;
594             STRLEN len;
595              
596 0 0         if ( SvROK(data) ) {
597 0 0         str = SvPV(SvRV(data), len);
598 0           RETVAL = bpc_poolWrite_write(info, (unsigned char*)str, len);
599             } else {
600 0           RETVAL = -1;
601             }
602             }
603             OUTPUT:
604             RETVAL
605              
606             void
607             addToPool(info, fileName, v3PoolFile)
608             BackupPC::XS::PoolWrite info;
609             char *fileName;
610             int v3PoolFile;
611             CODE:
612 0           bpc_poolWrite_addToPool(info, fileName, v3PoolFile);
613              
614             MODULE = BackupPC::XS PACKAGE = BackupPC::XS::Attrib
615              
616             BackupPC::XS::Attrib
617             new(compressLevel)
618             int compressLevel;
619             CODE:
620             {
621 0           RETVAL = calloc(1, sizeof(bpc_attrib_dir));
622 0           bpc_attrib_dirInit(RETVAL, compressLevel);
623             }
624             OUTPUT:
625             RETVAL
626              
627             void
628             DESTROY(dir)
629             BackupPC::XS::Attrib dir;
630             CODE:
631             {
632 0           bpc_attrib_dirDestroy(dir);
633 0           free(dir);
634             }
635              
636             SV*
637             get(dir, fileName = NULL)
638             BackupPC::XS::Attrib dir;
639             char *fileName;
640             CODE:
641             {
642 0 0         if ( fileName ) {
643 0           bpc_attrib_file *file = bpc_attrib_fileGet(dir, fileName, 0);
644 0 0         if ( !file ) XSRETURN_UNDEF;
645 0           RETVAL = newRV_noinc((SV*)convert_file2hv(file, file->name));
646             } else {
647             ssize_t entrySize, i;
648              
649 0           RETVAL = NULL;
650 0 0         if ( (entrySize = bpc_attrib_getEntries(dir, NULL, 0)) > 0 ) {
651 0           char *entries = malloc(entrySize), *p;
652              
653 0 0         if ( entries && bpc_attrib_getEntries(dir, entries, entrySize) > 0 ) {
    0          
654 0           HV *rh = newHV();
655 0 0         for ( i = 0, p = entries ; i < entrySize ; ) {
656 0           int len = strlen(p);
657             bpc_attrib_file *file;
658              
659 0           file = bpc_attrib_fileGet(dir, p, 0);
660 0           p += len + 1;
661 0           i += len + 1;
662 0 0         if ( !file ) continue;
663 0           (void)hv_store(rh, file->name, strlen(file->name), newRV_noinc((SV*)convert_file2hv(file, file->name)), 0);
664             }
665 0           RETVAL = newRV_noinc((SV*)rh);
666             }
667 0 0         if ( entries ) free(entries);
668             }
669 0 0         if ( !RETVAL ) XSRETURN_UNDEF;
670             }
671             }
672             OUTPUT:
673             RETVAL
674              
675             int
676             set(dir, fileName, hv)
677             BackupPC::XS::Attrib dir;
678             char *fileName;
679             HV *hv;
680             CODE:
681             {
682 0           bpc_attrib_file *file = bpc_attrib_fileGet(dir, fileName, 0);
683              
684 0           RETVAL = file ? 1 : 0;
685 0 0         if ( !file ) {
686 0           file = bpc_attrib_fileGet(dir, fileName, 1);
687 0           bpc_attrib_fileInit(file, fileName, 0);
688             }
689 0           convert_hv2file(hv, file);
690             }
691             OUTPUT:
692             RETVAL
693              
694             void
695             digest(dir)
696             BackupPC::XS::Attrib dir;
697             PREINIT:
698             PPCODE:
699             {
700 0           bpc_digest *digest = bpc_attrib_dirDigestGet(dir);
701 0 0         if ( digest && digest->len > 0 ) {
    0          
702 0 0         EXTEND(SP, 1);
703 0           PUSHs(sv_2mortal(newSVpvn((char*)digest->digest, digest->len)));
704             }
705             }
706              
707             void
708             iterate(dir, idx)
709             BackupPC::XS::Attrib dir;
710             unsigned int idx;
711             PREINIT:
712             bpc_attrib_file *file;
713             PPCODE:
714             {
715 0 0         if ( !bpc_attrib_fileIterate(dir, &file, &idx) && file ) {
    0          
716 0 0         EXTEND(SP, 2);
717 0           PUSHs(sv_2mortal(newRV_noinc((SV*)convert_file2hv(file, file->name))));
718 0           PUSHs(sv_2mortal(newSViv(idx)));
719             }
720             }
721              
722             char*
723             errStr(void)
724             CODE:
725 0           RETVAL = "TODO";
726             OUTPUT:
727             RETVAL
728              
729             int
730             count(dir)
731             BackupPC::XS::Attrib dir;
732             CODE:
733 0           RETVAL = bpc_attrib_fileCount(dir);
734             OUTPUT:
735             RETVAL
736              
737             void
738             delete(dir, fileName)
739             BackupPC::XS::Attrib dir;
740             char *fileName;
741             CODE:
742 0           bpc_attrib_fileDeleteName(dir, fileName);
743              
744             int
745             read(dir, dirPath, attribFileName = "attrib")
746             BackupPC::XS::Attrib dir;
747             char *dirPath;
748             char *attribFileName;
749             CODE:
750 0 0         if ( !*dirPath ) dirPath = NULL;
751 0           RETVAL = !bpc_attrib_dirRead(dir, dirPath, attribFileName, 0);
752             OUTPUT:
753             RETVAL
754              
755             int
756             write(dir, dirPath, attribFileName, d = NULL, deltaInfo = NULL)
757             BackupPC::XS::Attrib dir;
758             char *dirPath;
759             char *attribFileName;
760             SV *d;
761             BackupPC::XS::DeltaRefCnt deltaInfo;
762             CODE:
763 0 0         if ( !*dirPath ) dirPath = NULL;
764 0 0         if ( d && SvPOK(d) ) {
    0          
765             bpc_digest digest;
766             char *str;
767             STRLEN len;
768              
769 0 0         str = SvPV(d, len);
770 0 0         if ( 0 < len && len < sizeof(digest.digest) ) {
    0          
771 0           memcpy(digest.digest, str, len);
772 0           digest.len = len;
773 0           RETVAL = !bpc_attrib_dirWrite(deltaInfo, dir, dirPath, attribFileName, &digest);
774             } else {
775 0           RETVAL = !bpc_attrib_dirWrite(deltaInfo, dir, dirPath, attribFileName, NULL);
776             }
777             } else {
778 0           RETVAL = !bpc_attrib_dirWrite(deltaInfo, dir, dirPath, attribFileName, NULL);
779             }
780             OUTPUT:
781             RETVAL
782              
783             char *
784             fileType2Text(type)
785             int type;
786             CODE:
787 0           RETVAL = bpc_attrib_fileType2Text(type);
788             OUTPUT:
789             RETVAL
790              
791             void
792             backwardCompat(writeOldStyleAttribFile, keepOldAttribFiles)
793             int writeOldStyleAttribFile;
794             int keepOldAttribFiles;
795             CODE:
796 0           bpc_attrib_backwardCompat(writeOldStyleAttribFile, keepOldAttribFiles);
797              
798             MODULE = BackupPC::XS PACKAGE = BackupPC::XS::AttribCache
799              
800             BackupPC::XS::AttribCache
801             new(host, backupNum, shareNameUM, compress)
802             char *host;
803             int backupNum;
804             char *shareNameUM;
805             int compress;
806             CODE:
807             {
808 0           RETVAL = calloc(1, sizeof(bpc_attribCache_info));
809 0           bpc_attribCache_init(RETVAL, host, backupNum, shareNameUM, compress);
810             }
811             OUTPUT:
812             RETVAL
813              
814             void
815             DESTROY(ac)
816             BackupPC::XS::AttribCache ac;
817             CODE:
818             {
819 0           bpc_attribCache_destroy(ac);
820 0           free(ac);
821             }
822              
823             void
824             setDeltaInfo(ac, deltaInfo)
825             BackupPC::XS::AttribCache ac;
826             BackupPC::XS::DeltaRefCnt deltaInfo;
827             CODE:
828             {
829 0           bpc_attribCache_setDeltaInfo(ac, deltaInfo);
830             }
831              
832             SV*
833             get(ac, fileName, allocateIfMissing = 0, dontReadInode = 0)
834             BackupPC::XS::AttribCache ac;
835             char *fileName;
836             int allocateIfMissing;
837             int dontReadInode;
838             CODE:
839             {
840 0           bpc_attrib_file *file = bpc_attribCache_getFile(ac, fileName, allocateIfMissing, dontReadInode);
841              
842 0 0         if ( !file ) XSRETURN_UNDEF;
843              
844 0           RETVAL = newRV_noinc((SV*)convert_file2hv(file, file->name));
845             }
846             OUTPUT:
847             RETVAL
848              
849             int
850             set(ac, fileName, hv, dontOverwriteInode = 0)
851             BackupPC::XS::AttribCache ac;
852             char *fileName;
853             HV *hv;
854             int dontOverwriteInode;
855             CODE:
856             {
857 0           bpc_attrib_file *file = bpc_attribCache_getFile(ac, fileName, 1, 0);
858              
859 0           convert_hv2file(hv, file);
860 0           RETVAL = bpc_attribCache_setFile(ac, fileName, file, dontOverwriteInode);
861             }
862             OUTPUT:
863             RETVAL
864              
865             int
866             delete(ac, fileName)
867             BackupPC::XS::AttribCache ac;
868             char *fileName;
869             CODE:
870 0           RETVAL = bpc_attribCache_deleteFile(ac, fileName);
871             OUTPUT:
872             RETVAL
873              
874             SV*
875             getInode(ac, inode, allocateIfMissing = 0)
876             BackupPC::XS::AttribCache ac;
877             unsigned long inode;
878             int allocateIfMissing;
879             CODE:
880             {
881 0           bpc_attrib_file *file = bpc_attribCache_getInode(ac, inode, allocateIfMissing);
882              
883 0 0         if ( !file ) XSRETURN_UNDEF;
884              
885 0           RETVAL = newRV_noinc((SV*)convert_file2hv(file, file->name));
886             }
887             OUTPUT:
888             RETVAL
889              
890             int
891             setInode(ac, inode, hv)
892             BackupPC::XS::AttribCache ac;
893             unsigned long inode;
894             HV *hv;
895             CODE:
896             {
897 0           bpc_attrib_file *file = bpc_attribCache_getInode(ac, inode, 1);
898              
899 0           convert_hv2file(hv, file);
900 0           RETVAL = bpc_attribCache_setInode(ac, inode, file);
901             }
902             OUTPUT:
903             RETVAL
904              
905             int
906             deleteInode(ac, inode)
907             BackupPC::XS::AttribCache ac;
908             unsigned long inode;
909             CODE:
910 0           RETVAL = bpc_attribCache_deleteInode(ac, inode);
911             OUTPUT:
912             RETVAL
913              
914             int
915             count(ac, path)
916             BackupPC::XS::AttribCache ac;
917             char *path;
918             CODE:
919 0           RETVAL = bpc_attribCache_getDirEntryCnt(ac, path);
920             OUTPUT:
921             RETVAL
922              
923             SV*
924             getAll(ac, path, dontReadInode = 0)
925             BackupPC::XS::AttribCache ac;
926             char *path;
927             int dontReadInode;
928             CODE:
929             {
930             ssize_t entrySize, i;
931             char pathCopy[BPC_MAXPATHLEN];
932              
933 0           snprintf(pathCopy, sizeof(pathCopy), "%s", path);
934 0           RETVAL = NULL;
935 0 0         if ( (entrySize = bpc_attribCache_getDirEntries(ac, pathCopy, NULL, 0)) > 0 ) {
936 0           char *entries = malloc(entrySize), *p;
937              
938 0 0         if ( entries && bpc_attribCache_getDirEntries(ac, pathCopy, entries, entrySize) > 0 ) {
    0          
939 0           HV *rh = newHV();
940 0 0         for ( i = 0, p = entries ; i < entrySize ; ) {
941 0           int len = strlen(p);
942 0           char *fileNameSave = p;
943             char filePath[BPC_MAXPATHLEN];
944             bpc_attrib_file *file;
945              
946 0           snprintf(filePath, sizeof(filePath), "%s/%s", path, p);
947 0           file = bpc_attribCache_getFile(ac, filePath, 0, dontReadInode);
948 0           p += len + 1 + sizeof(ino_t);
949 0           i += len + 1 + sizeof(ino_t);
950 0 0         if ( !file ) continue;
951             /* printf("Storing file name %s for path %s\n", fileNameSave, path); */
952 0           (void)hv_store(rh, fileNameSave, strlen(fileNameSave), newRV_noinc((SV*)convert_file2hv(file, fileNameSave)), 0);
953             }
954 0           RETVAL = newRV_noinc((SV*)rh);
955             }
956 0 0         if ( entries ) free(entries);
957             }
958 0 0         if ( !RETVAL ) XSRETURN_UNDEF;
959             }
960             OUTPUT:
961             RETVAL
962              
963             void
964             flush(ac, all = 1, path = NULL)
965             BackupPC::XS::AttribCache ac;
966             int all
967             char *path;
968             CODE:
969 0           bpc_attribCache_flush(ac, all, path);
970              
971             SV*
972             getFullMangledPath(ac, dirName)
973             BackupPC::XS::AttribCache ac;
974             char *dirName;
975             CODE:
976             {
977             char path[BPC_MAXPATHLEN];
978 0           bpc_attribCache_getFullMangledPath(ac, path, dirName, -1);
979 0           RETVAL = newSVpvn(path, strlen(path));
980             }
981             OUTPUT:
982             RETVAL
983              
984             MODULE = BackupPC::XS PACKAGE = BackupPC::XS::FileDigest
985              
986             void
987             digest(fileName, compress)
988             char *fileName;
989             int compress;
990             PREINIT:
991             PPCODE:
992             {
993             bpc_digest digest;
994 0 0         if ( bpc_fileDigest(fileName, compress, &digest) == 0 ) {
995 0 0         EXTEND(SP, 1);
996 0           PUSHs(sv_2mortal(newSVpvn((char*)digest.digest, digest.len)));
997             }
998             }
999              
1000             MODULE = BackupPC::XS PACKAGE = BackupPC::XS::DirOps
1001              
1002             int
1003             path_create(path)
1004             char *path;
1005             CODE:
1006 0           RETVAL = bpc_path_create(path);
1007             OUTPUT:
1008             RETVAL
1009              
1010             int
1011             path_remove(path, compress, deltaInfo = NULL)
1012             char *path;
1013             int compress;
1014             BackupPC::XS::DeltaRefCnt deltaInfo;
1015             CODE:
1016 0           RETVAL = bpc_path_remove(deltaInfo, path, compress);
1017             OUTPUT:
1018             RETVAL
1019              
1020             int
1021             refCountAll(path, compress, incr = 1, deltaInfo = NULL)
1022             char *path;
1023             int compress;
1024             int incr;
1025             BackupPC::XS::DeltaRefCnt deltaInfo;
1026             CODE:
1027 0           RETVAL = bpc_path_refCountAll(deltaInfo, path, compress, incr);
1028             OUTPUT:
1029             RETVAL
1030              
1031             void
1032             refCountAllInodeMax(path, compress, incr = 1, deltaInfo = NULL)
1033             char *path;
1034             int compress;
1035             int incr;
1036             BackupPC::XS::DeltaRefCnt deltaInfo;
1037             PREINIT:
1038             int retVal;
1039 0           unsigned int inodeMax = 0;
1040             PPCODE:
1041             {
1042 0           retVal = bpc_path_refCountAllInodeMax(deltaInfo, path, compress, incr, &inodeMax);
1043 0 0         EXTEND(SP, 2);
1044 0           PUSHs(sv_2mortal(newSViv(retVal)));
1045 0           PUSHs(sv_2mortal(newSViv(inodeMax)));
1046             }
1047              
1048             int
1049             lockRangeFd(fd, offset, len, block)
1050             int fd;
1051             unsigned int offset;
1052             unsigned int len;
1053             int block;
1054             CODE:
1055 0           RETVAL = bpc_lockRangeFd(fd, offset, len, block);
1056             OUTPUT:
1057             RETVAL
1058              
1059             int
1060             unlockRangeFd(fd, offset, len)
1061             int fd;
1062             unsigned int offset;
1063             unsigned int len;
1064             CODE:
1065 0           RETVAL = bpc_unlockRangeFd(fd, offset, len);
1066             OUTPUT:
1067             RETVAL
1068              
1069             int
1070             lockRangeFile(lockFile, offset, len, block)
1071             char *lockFile;
1072             unsigned int offset;
1073             unsigned int len;
1074             int block;
1075             CODE:
1076 0           RETVAL = bpc_lockRangeFile(lockFile, offset, len, block);
1077             OUTPUT:
1078             RETVAL
1079              
1080             void
1081             unlockRangeFile(lockFd)
1082             int lockFd;
1083             CODE:
1084 0           bpc_unlockRangeFile(lockFd);
1085            
1086             MODULE = BackupPC::XS PACKAGE = BackupPC::XS::Lib
1087              
1088             void
1089             ConfInit(topDir, hardLinkMax, poolV3Enabled, logLevel = 0)
1090             char *topDir;
1091             int hardLinkMax;
1092             int poolV3Enabled;
1093             int logLevel;
1094             CODE:
1095 0           bpc_lib_conf_init(topDir, hardLinkMax, poolV3Enabled, logLevel);
1096              
1097             SV*
1098             logMsgGet()
1099             CODE:
1100             {
1101             char *mesg, *p;
1102             size_t mesgLen, i;
1103             AV *ra;
1104              
1105 0           RETVAL = NULL;
1106 0           bpc_logMsgGet(&mesg, &mesgLen);
1107 0 0         if ( mesgLen == 0 ) XSRETURN_UNDEF;
1108              
1109 0           ra = newAV();
1110 0 0         for ( i = 0, p = mesg ; i < mesgLen ; ) {
1111 0           int len = strlen(p);
1112              
1113 0           av_push(ra, newSVpvn(p, len));
1114 0           p += len + 1;
1115 0           i += len + 1;
1116             }
1117 0           RETVAL = newRV_noinc((SV*)ra);
1118             }
1119             OUTPUT:
1120             RETVAL
1121              
1122             int
1123             logErrorCntGet()
1124             CODE:
1125             {
1126             unsigned long errorCnt;
1127 0           bpc_logMsgErrorCntGet(&errorCnt);
1128 0           RETVAL = errorCnt;
1129             }
1130             OUTPUT:
1131             RETVAL
1132              
1133             void
1134             logLevelSet(logLevel)
1135             int logLevel;
1136             CODE:
1137 0           bpc_lib_setLogLevel(logLevel);