1 /*-
2  ***********************************************************************
3  *
4  * $Id: decoder.c,v 1.25 2014/07/18 06:40:44 mavrik Exp $
5  *
6  ***********************************************************************
7  *
8  * Copyright 2000-2014 The FTimes Project, All Rights Reserved.
9  *
10  ***********************************************************************
11  */
12 #include "all-includes.h"
13 
14 /*-
15  ***********************************************************************
16  *
17  * DecoderInitialize
18  *
19  ***********************************************************************
20  */
21 int
DecoderInitialize(FTIMES_PROPERTIES * psProperties,char * pcError)22 DecoderInitialize(FTIMES_PROPERTIES *psProperties, char *pcError)
23 {
24   /*-
25    *********************************************************************
26    *
27    * Initialize variables.
28    *
29    *********************************************************************
30    */
31   psProperties->pFileLog = stderr;
32   psProperties->pFileOut = stdout;
33 
34   DecodeBuildFromBase64Table();
35 
36   return ER_OK;
37 }
38 
39 
40 /*-
41  ***********************************************************************
42  *
43  * DecoderCheckDependencies
44  *
45  ***********************************************************************
46  */
47 int
DecoderCheckDependencies(FTIMES_PROPERTIES * psProperties,char * pcError)48 DecoderCheckDependencies(FTIMES_PROPERTIES *psProperties, char *pcError)
49 {
50   const char          acRoutine[] = "DecoderCheckDependencies()";
51 
52   if (psProperties->psSnapshotContext->pcFile == NULL || psProperties->psSnapshotContext->pcFile[0] == 0)
53   {
54     snprintf(pcError, MESSAGE_SIZE, "%s: Missing snapshot file.", acRoutine);
55     return ER_MissingControl;
56   }
57 
58   return ER_OK;
59 }
60 
61 
62 /*-
63  ***********************************************************************
64  *
65  * DecoderFinalize
66  *
67  ***********************************************************************
68  */
69 int
DecoderFinalize(FTIMES_PROPERTIES * psProperties,char * pcError)70 DecoderFinalize(FTIMES_PROPERTIES *psProperties, char *pcError)
71 {
72   const char          acRoutine[] = "DecoderFinalize()";
73   char                acLocalError[MESSAGE_SIZE] = "";
74   char                acMessage[MESSAGE_SIZE] = { 0 };
75   int                 iError = 0;
76 
77   /*-
78    *********************************************************************
79    *
80    * Finalize the log stream.
81    *
82    *********************************************************************
83    */
84   strncpy(psProperties->acLogFileName, "stderr", FTIMES_MAX_PATH);
85   psProperties->pFileLog = stderr;
86   MessageSetOutputStream(psProperties->pFileLog);
87   MessageSetAutoFlush(MESSAGE_AUTO_FLUSH_ON);
88 
89   /*-
90    *******************************************************************
91    *
92    * Finalize the out stream.
93    *
94    *******************************************************************
95    */
96   strncpy(psProperties->acOutFileName, "stdout", FTIMES_MAX_PATH);
97   psProperties->pFileOut = stdout;
98   DecodeSetOutputStream(psProperties->pFileOut);
99 
100   /*-
101    *******************************************************************
102    *
103    * Finalize the newline string.
104    *
105    *******************************************************************
106    */
107   MessageSetNewLine(psProperties->acNewLine);
108   DecodeSetNewLine(psProperties->acNewLine);
109 
110   /*-
111    *******************************************************************
112    *
113    * Open the snapshot.
114    *
115    *******************************************************************
116    */
117   iError = DecodeOpenSnapshot(psProperties->psSnapshotContext, acLocalError);
118   if (iError != ER_OK)
119   {
120     snprintf(pcError, MESSAGE_SIZE, "%s: %s", acRoutine, acLocalError);
121     return ER;
122   }
123 
124   /*-
125    *********************************************************************
126    *
127    * Display properties.
128    *
129    *********************************************************************
130    */
131   snprintf(acMessage, MESSAGE_SIZE, "Snapshot=%s", psProperties->psSnapshotContext->pcFile);
132   MessageHandler(MESSAGE_QUEUE_IT, MESSAGE_INFORMATION, MESSAGE_PROPERTY_STRING, acMessage);
133 
134   PropertiesDisplaySettings(psProperties);
135 
136   return ER_OK;
137 }
138 
139 
140 /*-
141  ***********************************************************************
142  *
143  * DecoderWorkHorse
144  *
145  ***********************************************************************
146  */
147 int
DecoderWorkHorse(FTIMES_PROPERTIES * psProperties,char * pcError)148 DecoderWorkHorse(FTIMES_PROPERTIES *psProperties, char *pcError)
149 {
150   const char          acRoutine[] = "DecoderWorkHorse()";
151   char                acLocalError[MESSAGE_SIZE] = "";
152   int                 iError = 0;
153 
154   /*-
155    *******************************************************************
156    *
157    * Write out a header.
158    *
159    *******************************************************************
160    */
161   iError = DecodeWriteHeader(psProperties->psSnapshotContext, acLocalError);
162   if (iError != ER_OK)
163   {
164     snprintf(pcError, MESSAGE_SIZE, "%s: %s", acRoutine, acLocalError);
165     return iError;
166   }
167 
168   /*-
169    *******************************************************************
170    *
171    * Read the snapshot, and process its data.
172    *
173    *******************************************************************
174    */
175   iError = DecodeReadSnapshot(psProperties->psSnapshotContext, acLocalError);
176   if (iError != ER_OK)
177   {
178     snprintf(pcError, MESSAGE_SIZE, "%s: %s", acRoutine, acLocalError);
179     fclose(psProperties->psSnapshotContext->pFile);
180     return iError;
181   }
182   fclose(psProperties->psSnapshotContext->pFile);
183 
184   return ER_OK;
185 }
186 
187 
188 /*-
189  ***********************************************************************
190  *
191  * DecoderFinishUp
192  *
193  ***********************************************************************
194  */
195 int
DecoderFinishUp(FTIMES_PROPERTIES * psProperties,char * pcError)196 DecoderFinishUp(FTIMES_PROPERTIES *psProperties, char *pcError)
197 {
198   char                acMessage[MESSAGE_SIZE] = { 0 };
199 
200   /*-
201    *********************************************************************
202    *
203    * Print output filenames.
204    *
205    *********************************************************************
206    */
207   snprintf(acMessage, MESSAGE_SIZE, "LogFileName=%s", psProperties->acLogFileName);
208   MessageHandler(MESSAGE_QUEUE_IT, MESSAGE_INFORMATION, MESSAGE_PROPERTY_STRING, acMessage);
209 
210   snprintf(acMessage, MESSAGE_SIZE, "OutFileName=%s", psProperties->acOutFileName);
211   MessageHandler(MESSAGE_QUEUE_IT, MESSAGE_INFORMATION, MESSAGE_PROPERTY_STRING, acMessage);
212 
213   /*-
214    *********************************************************************
215    *
216    * Write out the statistics.
217    *
218    *********************************************************************
219    */
220   snprintf(acMessage, MESSAGE_SIZE, "RecordsAnalyzed=%lu", psProperties->psSnapshotContext->sDecodeStats.ulAnalyzed);
221   MessageHandler(MESSAGE_QUEUE_IT, MESSAGE_INFORMATION, MESSAGE_PROPERTY_STRING, acMessage);
222 
223   snprintf(acMessage, MESSAGE_SIZE, "RecordsDecoded=%lu", psProperties->psSnapshotContext->sDecodeStats.ulDecoded);
224   MessageHandler(MESSAGE_QUEUE_IT, MESSAGE_INFORMATION, MESSAGE_PROPERTY_STRING, acMessage);
225 
226   snprintf(acMessage, MESSAGE_SIZE, "RecordsSkipped=%lu", psProperties->psSnapshotContext->sDecodeStats.ulSkipped);
227   MessageHandler(MESSAGE_QUEUE_IT, MESSAGE_INFORMATION, MESSAGE_PROPERTY_STRING, acMessage);
228 
229   SupportDisplayRunStatistics(psProperties);
230 
231   return ER_OK;
232 }
233 
234 
235 /*-
236  ***********************************************************************
237  *
238  * DecoderFinalStage
239  *
240  ***********************************************************************
241  */
242 int
DecoderFinalStage(FTIMES_PROPERTIES * psProperties,char * pcError)243 DecoderFinalStage(FTIMES_PROPERTIES *psProperties, char *pcError)
244 {
245   return ER_OK;
246 }
247