Mercurial > libpst
comparison src/dumpblocks.c @ 73:3cb02cb1e6cd stable-0-6-10
Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
More changes for Fedora packaging (#434727)
Fixes for const correctness.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 29 May 2008 18:51:02 -0700 |
parents | 7d5c637aaafb |
children | 87216aefc6df |
comparison
equal
deleted
inserted
replaced
72:c21e9c001256 | 73:3cb02cb1e6cd |
---|---|
4 #include <stdlib.h> | 4 #include <stdlib.h> |
5 #include <unistd.h> | 5 #include <unistd.h> |
6 #include "libpst.h" | 6 #include "libpst.h" |
7 | 7 |
8 #define OUT_BUF 20 | 8 #define OUT_BUF 20 |
9 int main(int argc, char **argv) { | 9 int main(int argc, char **argv) |
10 pst_file pstfile; | 10 { |
11 pst_index_ll *ptr; | 11 pst_file pstfile; |
12 char *outdir=NULL, *file=NULL, *outname=NULL; | 12 pst_index_ll *ptr; |
13 char *buf=NULL; | 13 char *outdir = NULL, *file = NULL, *outname = NULL; |
14 int c; | 14 char *buf = NULL; |
15 FILE *fp; | 15 int c; |
16 FILE *fp; | |
16 | 17 |
17 while ((c=getopt(argc, argv, "o:"))!=-1) { | 18 while ((c = getopt(argc, argv, "o:")) != -1) { |
18 switch(c) { | 19 switch (c) { |
19 case 'o': | 20 case 'o': |
20 outdir=optarg; | 21 outdir = optarg; |
21 break; | 22 break; |
22 default: | 23 default: |
23 printf("Unknown switch %c\n", c); | 24 printf("Unknown switch %c\n", c); |
25 } | |
24 } | 26 } |
25 } | 27 if (optind < argc) { |
26 if (optind < argc) { | 28 file = argv[optind]; |
27 file = argv[optind]; | 29 } else { |
28 } else { | 30 printf("Usage: dumpblocks [options] pstfile\n"); |
29 printf("Usage: dumpblocks [options] pstfile\n"); | 31 printf("\tcopies the datablocks from the pst file into seperate files\n"); |
30 printf("\tcopies the datablocks from the pst file into seperate files\n"); | 32 printf("Options: \n"); |
31 printf("Options: \n"); | 33 printf("\t-o target\tSpecify the output directory\n"); |
32 printf("\t-o target\tSpecify the output directory\n"); | 34 exit(1); |
33 exit(1); | 35 } |
34 } | 36 DEBUG_INIT("dumpblocks.log"); |
35 DEBUG_INIT("dumpblocks.log"); | 37 DEBUG_REGISTER_CLOSE(); |
36 DEBUG_REGISTER_CLOSE(); | 38 DEBUG_ENT("main"); |
37 DEBUG_ENT("main"); | |
38 | 39 |
39 printf("Opening file %s\n",file); | 40 printf("Opening file %s\n", file); |
40 if (pst_open(&pstfile, file)) { | 41 if (pst_open(&pstfile, file)) { |
41 printf("Failed to open file %s\n", file); | 42 printf("Failed to open file %s\n", file); |
42 exit(1); | 43 exit(1); |
43 } | |
44 | |
45 printf("Reading Indexes\n"); | |
46 if (pst_load_index(&pstfile)) { | |
47 printf("Failed to load indexes in file %s\n", argv[1]); | |
48 exit(1); | |
49 } | |
50 | |
51 if (outdir != NULL) | |
52 if (chdir(outdir)) { | |
53 printf("Failed to change into directory %s\n", outdir); | |
54 exit(1); | |
55 } | 44 } |
56 | 45 |
57 ptr = pstfile.i_head; | 46 printf("Reading Indexes\n"); |
58 outname = (char*) xmalloc(OUT_BUF); | 47 if (pst_load_index(&pstfile)) { |
59 printf("Saving blocks\n"); | 48 printf("Failed to load indexes in file %s\n", argv[1]); |
60 while (ptr != NULL) { | 49 exit(1); |
61 /* if (pstfile.encryption == PST_ENC) { | |
62 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, buf); | |
63 } else {*/ | |
64 if ((ptr->id & 0x02)==0 && pstfile.encryption == PST_ENC) { | |
65 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf); | |
66 } else { | |
67 c = pst_ff_getIDblock(&pstfile, ptr->id, &buf); | |
68 } | 50 } |
69 | 51 |
70 if (c > 0) { | 52 if (outdir != NULL) |
71 snprintf(outname, OUT_BUF, "%llx", ptr->id); | 53 if (chdir(outdir)) { |
72 if ((fp = fopen(outname, "wb")) == NULL) { | 54 printf("Failed to change into directory %s\n", outdir); |
73 printf("Failed to open file %s\n", outname); | 55 exit(1); |
74 continue; | 56 } |
75 } | 57 |
76 fwrite(buf, 1, c, fp); | 58 ptr = pstfile.i_head; |
77 fclose(fp); | 59 outname = (char *) xmalloc(OUT_BUF); |
78 } else { | 60 printf("Saving blocks\n"); |
79 printf("Failed to read block id %#llx\n", ptr->id); | 61 while (ptr != NULL) { |
62 /* if (pstfile.encryption == PST_ENC) { | |
63 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, buf); | |
64 } else { */ | |
65 if ((ptr->id & 0x02) == 0 && pstfile.encryption == PST_ENC) { | |
66 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf); | |
67 } else { | |
68 c = pst_ff_getIDblock(&pstfile, ptr->id, &buf); | |
69 } | |
70 | |
71 if (c > 0) { | |
72 snprintf(outname, OUT_BUF, "%llx", ptr->id); | |
73 if ((fp = fopen(outname, "wb")) == NULL) { | |
74 printf("Failed to open file %s\n", outname); | |
75 continue; | |
76 } | |
77 pst_fwrite(buf, 1, c, fp); | |
78 fclose(fp); | |
79 } else { | |
80 printf("Failed to read block id %#llx\n", ptr->id); | |
81 } | |
82 ptr = ptr->next; | |
80 } | 83 } |
81 ptr = ptr->next; | 84 pst_close(&pstfile); |
82 } | 85 DEBUG_RET(); |
83 pst_close(&pstfile); | 86 return 0; |
84 DEBUG_RET(); | |
85 return 0; | |
86 } | 87 } |