Deleted Added
full compact
cdf.c (302408) cdf.c (309847)
1/*-
2 * Copyright (c) 2008 Christos Zoulas
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

30 *
31 * N.B. This is the "Composite Document File" format, and not the
32 * "Compound Document Format", nor the "Channel Definition Format".
33 */
34
35#include "file.h"
36
37#ifndef lint
1/*-
2 * Copyright (c) 2008 Christos Zoulas
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

30 *
31 * N.B. This is the "Composite Document File" format, and not the
32 * "Compound Document Format", nor the "Channel Definition Format".
33 */
34
35#include "file.h"
36
37#ifndef lint
38FILE_RCSID("@(#)$File: cdf.c,v 1.82 2016/06/01 22:25:25 christos Exp $")
38FILE_RCSID("@(#)$File: cdf.c,v 1.85 2016/10/24 18:02:17 christos Exp $")
39#endif
40
41#include <assert.h>
42#ifdef CDF_DEBUG
43#include <err.h>
44#endif
45#include <stdlib.h>
46#include <unistd.h>

--- 214 unchanged lines hidden (view full) ---

261 CDF_UNPACK(d->d_flags);
262 CDF_UNPACK(d->d_created);
263 CDF_UNPACK(d->d_modified);
264 CDF_UNPACK(d->d_stream_first_sector);
265 CDF_UNPACK(d->d_size);
266 CDF_UNPACK(d->d_unused0);
267}
268
39#endif
40
41#include <assert.h>
42#ifdef CDF_DEBUG
43#include <err.h>
44#endif
45#include <stdlib.h>
46#include <unistd.h>

--- 214 unchanged lines hidden (view full) ---

261 CDF_UNPACK(d->d_flags);
262 CDF_UNPACK(d->d_created);
263 CDF_UNPACK(d->d_modified);
264 CDF_UNPACK(d->d_stream_first_sector);
265 CDF_UNPACK(d->d_size);
266 CDF_UNPACK(d->d_unused0);
267}
268
269static int
269int
270cdf_zero_stream(cdf_stream_t *scn)
271{
272 scn->sst_len = 0;
273 scn->sst_dirlen = 0;
274 scn->sst_ss = 0;
275 free(scn->sst_tab);
276 scn->sst_tab = NULL;
277 return -1;

--- 448 unchanged lines hidden (view full) ---

726 const cdf_directory_t *d;
727
728 *root = NULL;
729 for (i = 0; i < dir->dir_len; i++)
730 if (dir->dir_tab[i].d_type == CDF_DIR_TYPE_ROOT_STORAGE)
731 break;
732
733 /* If the it is not there, just fake it; some docs don't have it */
270cdf_zero_stream(cdf_stream_t *scn)
271{
272 scn->sst_len = 0;
273 scn->sst_dirlen = 0;
274 scn->sst_ss = 0;
275 free(scn->sst_tab);
276 scn->sst_tab = NULL;
277 return -1;

--- 448 unchanged lines hidden (view full) ---

726 const cdf_directory_t *d;
727
728 *root = NULL;
729 for (i = 0; i < dir->dir_len; i++)
730 if (dir->dir_tab[i].d_type == CDF_DIR_TYPE_ROOT_STORAGE)
731 break;
732
733 /* If the it is not there, just fake it; some docs don't have it */
734 if (i == dir->dir_len)
734 if (i == dir->dir_len) {
735 DPRINTF(("Cannot find root storage dir\n"));
735 goto out;
736 goto out;
737 }
736 d = &dir->dir_tab[i];
737 *root = d;
738
739 /* If the it is not there, just fake it; some docs don't have it */
738 d = &dir->dir_tab[i];
739 *root = d;
740
741 /* If the it is not there, just fake it; some docs don't have it */
740 if (d->d_stream_first_sector < 0)
742 if (d->d_stream_first_sector < 0) {
743 DPRINTF(("No first secror in dir\n"));
741 goto out;
744 goto out;
745 }
742
743 return cdf_read_long_sector_chain(info, h, sat,
744 d->d_stream_first_sector, d->d_size, scn);
745out:
746 scn->sst_tab = NULL;
747 (void)cdf_zero_stream(scn);
746
747 return cdf_read_long_sector_chain(info, h, sat,
748 d->d_stream_first_sector, d->d_size, scn);
749out:
750 scn->sst_tab = NULL;
751 (void)cdf_zero_stream(scn);
748 errno = EFTYPE;
749 return -1;
752 return 0;
750}
751
752static int
753cdf_namecmp(const char *d, const uint16_t *s, size_t l)
754{
755 for (; l--; d++, s++)
756 if (*d != CDF_TOLE2(*s))
757 return (unsigned char)*d - CDF_TOLE2(*s);
758 return 0;
759}
760
761int
753}
754
755static int
756cdf_namecmp(const char *d, const uint16_t *s, size_t l)
757{
758 for (; l--; d++, s++)
759 if (*d != CDF_TOLE2(*s))
760 return (unsigned char)*d - CDF_TOLE2(*s);
761 return 0;
762}
763
764int
765cdf_read_doc_summary_info(const cdf_info_t *info, const cdf_header_t *h,
766 const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
767 const cdf_dir_t *dir, cdf_stream_t *scn)
768{
769 return cdf_read_user_stream(info, h, sat, ssat, sst, dir,
770 "\05DocumentSummaryInformation", scn);
771}
772
773int
762cdf_read_summary_info(const cdf_info_t *info, const cdf_header_t *h,
763 const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
764 const cdf_dir_t *dir, cdf_stream_t *scn)
765{
766 return cdf_read_user_stream(info, h, sat, ssat, sst, dir,
767 "\05SummaryInformation", scn);
768}
769

--- 323 unchanged lines hidden (view full) ---

1093 }
1094
1095 cep->ce_namlen = __arraycount(cep->ce_name) - 1;
1096 rlen = reclen - 14;
1097 if (cep->ce_namlen > rlen)
1098 cep->ce_namlen = rlen;
1099
1100 np = CAST(const uint16_t *, CAST(const void *, (b + 16)));
774cdf_read_summary_info(const cdf_info_t *info, const cdf_header_t *h,
775 const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,
776 const cdf_dir_t *dir, cdf_stream_t *scn)
777{
778 return cdf_read_user_stream(info, h, sat, ssat, sst, dir,
779 "\05SummaryInformation", scn);
780}
781

--- 323 unchanged lines hidden (view full) ---

1105 }
1106
1107 cep->ce_namlen = __arraycount(cep->ce_name) - 1;
1108 rlen = reclen - 14;
1109 if (cep->ce_namlen > rlen)
1110 cep->ce_namlen = rlen;
1111
1112 np = CAST(const uint16_t *, CAST(const void *, (b + 16)));
1101 if (CAST(const char *, np + cep->ce_namlen) > eb) {
1113 if (RCAST(const char *, np + cep->ce_namlen) > eb) {
1102 cep->ce_namlen = 0;
1103 break;
1104 }
1105
1106 for (k = 0; k < cep->ce_namlen; k++)
1107 cep->ce_name[k] = np[k]; /* XXX: CDF_TOLE2? */
1108 cep->ce_name[cep->ce_namlen] = 0;
1109 j = i;

--- 160 unchanged lines hidden (view full) ---

1270 (void)fprintf(stderr, "%s\n%.4" SIZE_T_FORMAT "x: ",
1271 abuf, i + 1);
1272 }
1273 }
1274 (void)fprintf(stderr, "\n");
1275}
1276
1277void
1114 cep->ce_namlen = 0;
1115 break;
1116 }
1117
1118 for (k = 0; k < cep->ce_namlen; k++)
1119 cep->ce_name[k] = np[k]; /* XXX: CDF_TOLE2? */
1120 cep->ce_name[cep->ce_namlen] = 0;
1121 j = i;

--- 160 unchanged lines hidden (view full) ---

1282 (void)fprintf(stderr, "%s\n%.4" SIZE_T_FORMAT "x: ",
1283 abuf, i + 1);
1284 }
1285 }
1286 (void)fprintf(stderr, "\n");
1287}
1288
1289void
1278cdf_dump_stream(const cdf_header_t *h, const cdf_stream_t *sst)
1290cdf_dump_stream(const cdf_stream_t *sst)
1279{
1280 size_t ss = sst->sst_ss;
1281 cdf_dump(sst->sst_tab, ss * sst->sst_len);
1282}
1283
1284void
1285cdf_dump_dir(const cdf_info_t *info, const cdf_header_t *h,
1286 const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,

--- 39 unchanged lines hidden (view full) ---

1326 if (sst == NULL)
1327 break;
1328 if (cdf_read_sector_chain(info, h, sat, ssat, sst,
1329 d->d_stream_first_sector, d->d_size, &scn) == -1) {
1330 warn("Can't read stream for %s at %d len %d",
1331 name, d->d_stream_first_sector, d->d_size);
1332 break;
1333 }
1291{
1292 size_t ss = sst->sst_ss;
1293 cdf_dump(sst->sst_tab, ss * sst->sst_len);
1294}
1295
1296void
1297cdf_dump_dir(const cdf_info_t *info, const cdf_header_t *h,
1298 const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst,

--- 39 unchanged lines hidden (view full) ---

1338 if (sst == NULL)
1339 break;
1340 if (cdf_read_sector_chain(info, h, sat, ssat, sst,
1341 d->d_stream_first_sector, d->d_size, &scn) == -1) {
1342 warn("Can't read stream for %s at %d len %d",
1343 name, d->d_stream_first_sector, d->d_size);
1344 break;
1345 }
1334 cdf_dump_stream(h, &scn);
1346 cdf_dump_stream(&scn);
1335 free(scn.sst_tab);
1336 break;
1337 default:
1338 break;
1339 }
1340
1341 }
1342}

--- 159 unchanged lines hidden (view full) ---

1502
1503 if (cdf_read_dir(&info, &h, &sat, &dir) == -1)
1504 err(1, "Cannot read dir");
1505
1506 if (cdf_read_short_stream(&info, &h, &sat, &dir, &sst, &root)
1507 == -1)
1508 err(1, "Cannot read short stream");
1509#ifdef CDF_DEBUG
1347 free(scn.sst_tab);
1348 break;
1349 default:
1350 break;
1351 }
1352
1353 }
1354}

--- 159 unchanged lines hidden (view full) ---

1514
1515 if (cdf_read_dir(&info, &h, &sat, &dir) == -1)
1516 err(1, "Cannot read dir");
1517
1518 if (cdf_read_short_stream(&info, &h, &sat, &dir, &sst, &root)
1519 == -1)
1520 err(1, "Cannot read short stream");
1521#ifdef CDF_DEBUG
1510 cdf_dump_stream(&h, &sst);
1522 cdf_dump_stream(&sst);
1511#endif
1512
1513#ifdef CDF_DEBUG
1514 cdf_dump_dir(&info, &h, &sat, &ssat, &sst, &dir);
1515#endif
1516
1517
1518 if (cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,

--- 20 unchanged lines hidden ---
1523#endif
1524
1525#ifdef CDF_DEBUG
1526 cdf_dump_dir(&info, &h, &sat, &ssat, &sst, &dir);
1527#endif
1528
1529
1530 if (cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,

--- 20 unchanged lines hidden ---