1 /* wvWare
2  * Copyright (C) Caolan McNamara, Dom Lachowicz, and others
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "wv.h"
28 
29 #include <gsf/gsf-infile-msole.h>
30 #include <gsf/gsf-infile.h>
31 #include <gsf/gsf-input-stdio.h>
32 
wvOLEDecode_gsf(wvParseStruct * ps,GsfInput * path,wvStream ** mainfd,wvStream ** tablefd0,wvStream ** tablefd1,wvStream ** data,wvStream ** summary)33 int wvOLEDecode_gsf (wvParseStruct * ps, GsfInput *path, wvStream ** mainfd, wvStream ** tablefd0,
34 		     wvStream ** tablefd1, wvStream ** data, wvStream ** summary)
35 {
36     GsfInfile *ole_file = NULL;
37     int result = 5;
38 
39     if (!path) {
40       return result;
41     }
42 
43     ole_file = gsf_infile_msole_new (path, NULL);
44 
45     if (ole_file != NULL)
46       {
47 	  GsfInput *temp_stream;
48 
49 	  ps->ole_file = GSF_INPUT(ole_file);
50 
51 	  wvTrace (("Opened VFS\n"));
52 	  if ((temp_stream = gsf_infile_child_by_name (ole_file, "WordDocument")) == NULL)
53 	    {
54 		*mainfd = NULL;
55 		wvTrace (("Opening \"WordDocument\" stream\n"));
56 	    }
57 	  else
58 	    {
59 		wvTrace (("Opened \"WordDocument\" stream\n"));
60 		wvStream_gsf_create (mainfd, temp_stream);
61 	    }
62 
63 	  if ((temp_stream = gsf_infile_child_by_name (ole_file, "1Table")) == NULL)
64 	    {
65 		*tablefd1 = NULL;
66 		wvTrace (("Opening \"1Table\" stream\n"));
67 	    }
68 	  else
69 	    {
70 		wvTrace (("Opened \"1Table\" stream\n"));
71 		wvStream_gsf_create (tablefd1, temp_stream);
72 	    }
73 
74 	  if ((temp_stream = gsf_infile_child_by_name (ole_file, "0Table")) == NULL)
75 	    {
76 		*tablefd0 = NULL;
77 		wvTrace (("Opening \"0Table\" stream\n"));
78 	    }
79 	  else
80 	    {
81 		wvTrace (("Opened \"0Table\" stream\n"));
82 		wvStream_gsf_create (tablefd0, temp_stream);
83 
84 	    }
85 
86 	  if ((temp_stream = gsf_infile_child_by_name (ole_file, "Data")) == NULL)
87 	    {
88 		*data = NULL;
89 		wvTrace (("Opening \"Data\" stream\n"));
90 	    }
91 	  else
92 	    {
93 		wvTrace (("Opened \"Data\" stream\n"));
94 		wvStream_gsf_create (data, temp_stream);
95 	    }
96 
97 	  if ((temp_stream = gsf_infile_child_by_name (ole_file, "\005SummaryInformation")) == NULL)
98 	    {
99 		*summary = NULL;
100 		wvTrace (("Opening \"\\005SummaryInformation\" stream\n"));
101 	    }
102 	  else
103 	    {
104 		wvTrace (("Opened \"\\005SummaryInformation\" stream\n"));
105 		wvStream_gsf_create (summary, temp_stream);
106 	    }
107 
108 	  result = 0;
109       }
110 
111     return (result);
112 }
113 
114 int
wvOLEDecode(wvParseStruct * ps,char * path,wvStream ** mainfd,wvStream ** tablefd0,wvStream ** tablefd1,wvStream ** data,wvStream ** summary)115 wvOLEDecode (wvParseStruct * ps, char *path, wvStream ** mainfd, wvStream ** tablefd0,
116 	     wvStream ** tablefd1, wvStream ** data, wvStream ** summary)
117 {
118   GsfInput * input = gsf_input_stdio_new (path, NULL);
119 
120   int rval = wvOLEDecode_gsf (ps, input, mainfd, tablefd0, tablefd1, data, summary);
121 
122   return rval;
123 }
124