Mercurial > libpst
comparison src/getidblock.c @ 164:ab384fed78c5
Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Don't produce empty attachment files in separate mode.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 16 Mar 2009 18:31:39 -0700 |
parents | 06aa84023b48 |
children | 6954d315aaa8 |
comparison
equal
deleted
inserted
replaced
163:03fbb0269f3c | 164:ab384fed78c5 |
---|---|
15 printf("\t\t-p\tProcess the block before finishing.\n"); | 15 printf("\t\t-p\tProcess the block before finishing.\n"); |
16 printf("\t\t\tView the debug log for information\n"); | 16 printf("\t\t\tView the debug log for information\n"); |
17 } | 17 } |
18 | 18 |
19 | 19 |
20 void dumper(uint64_t id); | 20 void dumper(uint64_t i_id); |
21 void dumper(uint64_t id) | 21 void dumper(uint64_t i_id) |
22 { | 22 { |
23 char *buf = NULL; | 23 char *buf = NULL; |
24 size_t readSize; | 24 size_t readSize; |
25 pst_desc_ll *ptr; | 25 pst_desc_ll *ptr; |
26 | 26 |
27 DEBUG_MAIN(("\n\n\nLooking at block index1 id %#"PRIx64"\n", id)); | 27 DEBUG_MAIN(("\n\n\nLooking at block index1 id %#"PRIx64"\n", i_id)); |
28 | 28 |
29 if ((readSize = pst_ff_getIDblock_dec(&pstfile, id, &buf)) <= 0 || buf == 0) { | 29 if ((readSize = pst_ff_getIDblock_dec(&pstfile, i_id, &buf)) <= 0 || buf == 0) { |
30 DIE(("Error loading block\n")); | 30 DIE(("Error loading block\n")); |
31 } | 31 } |
32 | 32 |
33 DEBUG_MAIN(("Printing block id %#"PRIx64", size %#"PRIx64"\n", id, (uint64_t)readSize)); | 33 DEBUG_MAIN(("Printing block id %#"PRIx64", size %#"PRIx64"\n", i_id, (uint64_t)readSize)); |
34 if (binary) { | 34 if (binary) { |
35 if (fwrite(buf, 1, readSize, stdout) != 0) { | 35 if (fwrite(buf, 1, readSize, stdout) != 0) { |
36 DIE(("Error occured during writing of buf to stdout\n")); | 36 DIE(("Error occured during writing of buf to stdout\n")); |
37 } | 37 } |
38 } else { | 38 } else { |
39 printf("Block id %#"PRIx64", size %#"PRIx64"\n", id, (uint64_t)readSize); | 39 printf("Block id %#"PRIx64", size %#"PRIx64"\n", i_id, (uint64_t)readSize); |
40 pst_debug_hexdumper(stdout, buf, readSize, 0x10, 0); | 40 pst_debug_hexdumper(stdout, buf, readSize, 0x10, 0); |
41 } | 41 } |
42 if (buf) free(buf); | 42 if (buf) free(buf); |
43 | 43 |
44 if (process) { | 44 if (process) { |
45 DEBUG_MAIN(("Parsing block id %#"PRIx64"\n", id)); | 45 DEBUG_MAIN(("Parsing block id %#"PRIx64"\n", i_id)); |
46 ptr = pstfile.d_head; | 46 ptr = pstfile.d_head; |
47 while (ptr) { | 47 while (ptr) { |
48 if (ptr->assoc_tree && ptr->assoc_tree->id == id) | 48 if (ptr->assoc_tree && ptr->assoc_tree->i_id == i_id) |
49 break; | 49 break; |
50 if (ptr->desc && ptr->desc->id == id) | 50 if (ptr->desc && ptr->desc->i_id == i_id) |
51 break; | 51 break; |
52 ptr = pst_getNextDptr(ptr); | 52 ptr = pst_getNextDptr(ptr); |
53 } | 53 } |
54 if (!ptr) { | 54 if (!ptr) { |
55 ptr = (pst_desc_ll *) xmalloc(sizeof(pst_desc_ll)); | 55 ptr = (pst_desc_ll *) xmalloc(sizeof(pst_desc_ll)); |
56 memset(ptr, 0, sizeof(pst_desc_ll)); | 56 memset(ptr, 0, sizeof(pst_desc_ll)); |
57 ptr->desc = pst_getID(&pstfile, id); | 57 ptr->desc = pst_getID(&pstfile, i_id); |
58 } | 58 } |
59 pst_item *item = pst_parse_item(&pstfile, ptr, NULL); | 59 pst_item *item = pst_parse_item(&pstfile, ptr, NULL); |
60 if (item) pst_freeItem(item); | 60 if (item) pst_freeItem(item); |
61 } | 61 } |
62 } | 62 } |
65 void dump_desc(pst_desc_ll *ptr); | 65 void dump_desc(pst_desc_ll *ptr); |
66 void dump_desc(pst_desc_ll *ptr) | 66 void dump_desc(pst_desc_ll *ptr) |
67 { | 67 { |
68 while (ptr) { | 68 while (ptr) { |
69 DEBUG_MAIN(("\n\n\nLooking at block desc id %#"PRIx64"\n", ptr->d_id)); | 69 DEBUG_MAIN(("\n\n\nLooking at block desc id %#"PRIx64"\n", ptr->d_id)); |
70 if (ptr->desc && ptr->desc->id) dumper(ptr->desc->id); | 70 if (ptr->desc && ptr->desc->i_id) dumper(ptr->desc->i_id); |
71 if (ptr->assoc_tree && ptr->assoc_tree->id) dumper(ptr->assoc_tree->id); | 71 if (ptr->assoc_tree && ptr->assoc_tree->i_id) dumper(ptr->assoc_tree->i_id); |
72 if (ptr->child) dump_desc(ptr->child); | 72 if (ptr->child) dump_desc(ptr->child); |
73 ptr = ptr->next; | 73 ptr = ptr->next; |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 | 77 |
78 int main(int argc, char* const* argv) | 78 int main(int argc, char* const* argv) |
79 { | 79 { |
80 // pass the id number to display on the command line | 80 // pass the id number to display on the command line |
81 char *fname, *sid; | 81 char *fname, *sid; |
82 uint64_t id; | 82 uint64_t i_id; |
83 int c; | 83 int c; |
84 | 84 |
85 DEBUG_INIT("getidblock.log"); | 85 DEBUG_INIT("getidblock.log"); |
86 DEBUG_REGISTER_CLOSE(); | 86 DEBUG_REGISTER_CLOSE(); |
87 DEBUG_ENT("main"); | 87 DEBUG_ENT("main"); |
107 usage(); | 107 usage(); |
108 exit(EXIT_FAILURE); | 108 exit(EXIT_FAILURE); |
109 } | 109 } |
110 fname = argv[optind]; | 110 fname = argv[optind]; |
111 sid = argv[optind + 1]; | 111 sid = argv[optind + 1]; |
112 id = (uint64_t)strtoll(sid, NULL, 0); | 112 i_id = (uint64_t)strtoll(sid, NULL, 0); |
113 | 113 |
114 DEBUG_MAIN(("Opening file\n")); | 114 DEBUG_MAIN(("Opening file\n")); |
115 memset(&pstfile, 0, sizeof(pstfile)); | 115 memset(&pstfile, 0, sizeof(pstfile)); |
116 if (pst_open(&pstfile, fname)) { | 116 if (pst_open(&pstfile, fname)) { |
117 DIE(("Error opening file\n")); | 117 DIE(("Error opening file\n")); |
120 DEBUG_MAIN(("Loading Index\n")); | 120 DEBUG_MAIN(("Loading Index\n")); |
121 if (pst_load_index(&pstfile) != 0) { | 121 if (pst_load_index(&pstfile) != 0) { |
122 DIE(("Error loading file index\n")); | 122 DIE(("Error loading file index\n")); |
123 } | 123 } |
124 | 124 |
125 if (id) { | 125 if (i_id) { |
126 dumper(id); | 126 dumper(i_id); |
127 } | 127 } |
128 else { | 128 else { |
129 pst_index_ll *ptr = pstfile.i_head; | 129 pst_index_ll *ptr = pstfile.i_head; |
130 while (ptr) { | 130 while (ptr) { |
131 dumper(ptr->id); | 131 dumper(ptr->i_id); |
132 ptr = ptr->next; | 132 ptr = ptr->next; |
133 } | 133 } |
134 dump_desc(pstfile.d_head); | 134 dump_desc(pstfile.d_head); |
135 } | 135 } |
136 | 136 |