File: info.c

package info (click to toggle)
unar 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,664 kB
  • sloc: ansic: 52,939; objc: 39,563; cpp: 4,074; makefile: 99; perl: 10
file content (374 lines) | stat: -rwxr-xr-x 10,457 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#ifndef XADMASTER_INFO_C
#define XADMASTER_INFO_C

/*  $Id: info.c,v 1.13 2005/06/23 14:54:37 stoecker Exp $
    information handling functions

    XAD library system for archive handling
    Copyright (C) 1998 and later by Dirk Stcker <soft@dstoecker.de>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "include/functions.h"

FUNCxadGetSystemInfo /* no args */
{
  return &xadMasterBase->xmb_System;
}
ENDFUNC

FUNCxadRecogFile /* xadSize size, const void *mem, xadTAGPTR tags */
{
#ifdef AMIGA
  struct xadClient *xc = xadGetClientInfo();
#else
  struct xadClient *xc = xadGetClientInfo(xadMasterBase);
#endif

  xadINT32 noext = 0;
  xadUINT32 onlyflags = 0, ignoreflags = 0;
  xadTAGPTR ti, ti2 = tags;

#ifdef DEBUG
  xadUINT32 crc, crc2;

  crc = xadCalcCRC32(XADM_PRIV XADCRC32_ID1, ~0, size, mem);
#endif

  while((ti = NextTagItem(&ti2)))
  {
    switch(ti->ti_Tag)
    {
    case XAD_NOEXTERN:    noext = ti->ti_Data; break;
    case XAD_IGNOREFLAGS: ignoreflags = ti->ti_Data; break;
    case XAD_ONLYFLAGS:   onlyflags = ti->ti_Data; break;
    }
  }

  if(noext)
    ignoreflags |= XADCF_EXTERN;

#ifdef DEBUG
  DebugRunTime("xadRecogFileA: %s (%08lx, %ld)", noext ? "NOEXTERN" : "EXTERN", mem, size);
#endif

  while(xc)
  {
    if((xc->xc_Flags & (XADCF_FILEARCHIVER|XADCF_DISKARCHIVER)) && xc->xc_RecogData &&
    !(xc->xc_Flags & ignoreflags) && ((xc->xc_Flags & onlyflags) == onlyflags))
    {
      if((size >= xc->xc_RecogSize) || (xc->xc_Flags & XADCF_NOCHECKSIZE))
      {
#ifdef DEBUG
  crc2 = xadCalcCRC32(XADM XADCRC32_ID1, ~0, size, mem);
#endif
        if(Callback_RecogData(xc, MinVal(size, xc->xc_RecogSize), mem,
        xadMasterBase))
        {
#ifdef DEBUG
  DebugRunTime("xadRecogFileA: found %s", xc->xc_ArchiverName);
  if(crc2 != xadCalcCRC32(XADM XADCRC32_ID1, ~0, size, mem))
    DebugError("xadRecogFileA: The input buffer was modified by this client.");
#endif
          return xc;
        }
#ifdef DEBUG
  if(crc2 != xadCalcCRC32(XADM XADCRC32_ID1, ~0, size, mem))
    DebugError("xadRecogFileA: The input buffer was modified by %s.",
    xc->xc_ArchiverName);
#endif
      }
    }
    xc = xc->xc_Next;
  }
#ifdef DEBUG
  if(crc != xadCalcCRC32(XADM XADCRC32_ID1, ~0, size, mem))
    DebugError("xadRecogFileA: The input buffer was modified.");
#endif

  return 0;
}
ENDFUNC

FUNCxadGetInfo /* struct xadArchiveInfoP *ai, xadTAGPTR tags */
{
  xadERROR err;

#ifdef DEBUG
  DebugTagList("xadGetInfoA", tags);
#endif

  /* Validate tag arguments, fill out some ArchiveInfo fields from tags,
   * and initialise hook if required. Only "input" tags are allowed, tags
   * that would generate output are not allowed. */
  ai->xaip_ArchiveInfo.xai_Flags |= XADAIF_ONLYIN;
  err = xadGetHookAccessA(XADM_PRIV XADM_AI(ai), tags);
  ai->xaip_ArchiveInfo.xai_Flags &= ~XADAIF_ONLYIN;

  /* if a full file path has been provided, extract the filename part */
  if(ai->xaip_InFileName)
  {
    /* FIXME: use an appropriate ConvertName function, as this code is
     * hacky, only working for Amiga and UNIX */
    xadSTRPTR pos, f;

    for(f = pos = ai->xaip_InFileName; *pos; ++pos)
    {
#ifdef AMIGA
      if(*pos == ':' || *pos == '/')
#else
      if(*pos == '/')
#endif
        f = pos+1;
    }
    if(*f)
      ai->xaip_ArchiveInfo.xai_InName = f;
  }
  if(!err)
  {
// GOA -->
    struct xadClient *xc = 0;
    xadUINT32 client_id = GetTagData(XAD_CLIENT, 0, tags);

    if(!client_id)
    {
      xadPTR buf;
      xadSignSize size;

      size = MinVal(xadMasterBase->xmb_RecogSize,
      ai->xaip_ArchiveInfo.xai_InSize);

      if((buf = xadAllocVec(XADM size, XADMEMF_ANY|XADMEMF_PUBLIC)))
      {
        if(!(err = xadHookAccess(XADM XADAC_READ, size, buf, XADM_AI(ai))))
        {
          if(!(err = xadHookAccess(XADM XADAC_INPUTSEEK, -size, 0,
          XADM_AI(ai))))
          {
            if(!(xc = xadRecogFileA(XADM size, buf, tags)))
              err = XADERR_FILETYPE;
          }
        }
        xadFreeObjectA(XADM buf, 0);
      }
      else
        err = XADERR_NOMEMORY;
    }
    else
    {
#ifdef AMIGA
      xc = xadGetClientInfo();
#else
      xc = xadGetClientInfo(xadMasterBase);
#endif
      while(xc)
      {
        if(xc->xc_Identifier == client_id) break;
        xc = xc->xc_Next;
      }
    }
// <-- GOA

    if(xc)
    {
      ai->xaip_ArchiveInfo.xai_Client = xc;
      err = Callback_GetInfo(xc, ai, xadMasterBase);
    }
  }

  callprogress(ai, err, err ? XADPMODE_ERROR : XADPMODE_GETINFOEND,
  xadMasterBase);
  ai->xaip_ArchiveInfo.xai_InName = 0;
  /* it is no longer valid after leaving that function */

  if(err)
  {
    xadFreeInfo(XADM XADM_AI(ai));
#ifdef DEBUG
    DebugError("xadGetInfo returns \"%s\" (%ld)", xadGetErrorText(XADM err),
    err);
#endif
  }

  return err;
}
ENDFUNC

FUNCxadFreeInfo /* struct xadArchiveInfoP *ai */
{
  const struct xadClient *xc;

#ifdef DEBUG
  DebugRunTime("xadFreeInfo");
#endif

  if((xc = ai->xaip_ArchiveInfo.xai_Client))
  {
    if(xc->xc_Free)
      Callback_Free(xc, ai, xadMasterBase);

    if(ai->xaip_ArchiveInfo.xai_SkipInfo
    && (xc->xc_Flags & XADCF_FREESKIPINFO))
    {
      struct xadSkipInfo *si, *si2;

      for(si = ai->xaip_ArchiveInfo.xai_SkipInfo; si; si = si2)
      {
        si2 = si->xsi_Next;
        xadFreeObjectA(XADM si, 0);
      }
#ifdef DEBUG
      /* not needed in non DEBUG state, because of memset */
      ai->xaip_ArchiveInfo.xai_SkipInfo = 0;
#endif
    }

    if(ai->xaip_ArchiveInfo.xai_FileInfo && (xc->xc_Flags &
    (XADCF_FREEFILEINFO|XADCF_FREESPECIALINFO|XADCF_FREEXADSTRINGS)))
    {
      struct xadFileInfo *fi, *fi2;
      struct xadSpecial *s, *s2;

      for(fi = ai->xaip_ArchiveInfo.xai_FileInfo; fi; fi = fi2)
      {
        if(xc->xc_Flags & XADCF_FREESPECIALINFO)
        {
          for(s = fi->xfi_Special; s; s = s2)
          {
            s2 = s->xfis_Next;
              xadFreeObjectA(XADM s, 0);
          }
#ifdef DEBUG
          /* not needed in non DEBUG state, because of memset */
          fi->xfi_Special = 0;
#endif
        }
        if(xc->xc_Flags & XADCF_FREEXADSTRINGS)
        {
          if(fi->xfi_Flags & XADFIF_XADSTRFILENAME)
          {
            xadFreeObjectA(XADM fi->xfi_FileName, 0);
#ifdef DEBUG
            fi->xfi_FileName = 0;
#endif
          }
          if(fi->xfi_Flags & XADFIF_XADSTRLINKNAME)
          {
            xadFreeObjectA(XADM fi->xfi_LinkName, 0);
#ifdef DEBUG
            fi->xfi_FileName = 0;
#endif
          }
          if(fi->xfi_Flags & XADFIF_XADSTRCOMMENT)
          {
            xadFreeObjectA(XADM fi->xfi_Comment, 0);
#ifdef DEBUG
            fi->xfi_FileName = 0;
#endif
          }
        }

#ifdef DEBUG
  if(fi->xfi_Special)
    DebugMemError("xadFreeInfo: still some Special entries in list for "
    "entry %ld", fi->xfi_EntryNumber);
  if(fi->xfi_FileName && (fi->xfi_Flags & XADFIF_XADSTRFILENAME))
    DebugMemError("xadFreeInfo: FileName string not released for "
    "entry %ld", fi->xfi_EntryNumber);
  if(fi->xfi_LinkName && (fi->xfi_Flags & XADFIF_XADSTRLINKNAME))
    DebugMemError("xadFreeInfo: LinkName string not released for "
    "entry %ld", fi->xfi_EntryNumber);
  if(fi->xfi_Comment && (fi->xfi_Flags & XADFIF_XADSTRCOMMENT))
    DebugMemError("xadFreeInfo: Comment string not released for "
    "entry %ld", fi->xfi_EntryNumber);
#endif
        fi2 = fi->xfi_Next;
        if(xc->xc_Flags & XADCF_FREEFILEINFO)
          xadFreeObjectA(XADM fi, 0);
      }
#ifdef DEBUG
      /* not needed in non DEBUG state, because of memset */
      if(xc->xc_Flags & XADCF_FREEFILEINFO)
        ai->xaip_ArchiveInfo.xai_FileInfo = 0;
#endif
    }

    if(ai->xaip_ArchiveInfo.xai_DiskInfo && (xc->xc_Flags
    & (XADCF_FREEDISKINFO|XADCF_FREETEXTINFO|XADCF_FREETEXTINFOTEXT)))
    {
      struct xadDiskInfo *di, *di2;
      struct xadTextInfo *ti, *ti2;

      for(di = ai->xaip_ArchiveInfo.xai_DiskInfo; di; di = di2)
      {
        di2 = di->xdi_Next;

        for(ti = di->xdi_TextInfo; ti; ti = ti2)
        {
          ti2 = ti->xti_Next;
          if(ti->xti_Text && (xc->xc_Flags & XADCF_FREETEXTINFOTEXT))
          {
            xadFreeObjectA(XADM ti->xti_Text, 0);
            ti->xti_Text = 0;
          }
#ifdef DEBUG
  if(ti->xti_Text)
    DebugMemError("xadFreeInfo: still some Texts for entry %ld", di->xdi_EntryNumber);
#endif
          if(xc->xc_Flags & XADCF_FREETEXTINFO)
            xadFreeObjectA(XADM ti, 0);
        }
        if(xc->xc_Flags & XADCF_FREETEXTINFO)
          di->xdi_TextInfo = 0;

#ifdef DEBUG
  if(di->xdi_TextInfo)
    DebugMemError("xadFreeInfo: still some xadTextInfo for entry %ld", di->xdi_EntryNumber);
#endif
        if(xc->xc_Flags & XADCF_FREEDISKINFO)
          xadFreeObjectA(XADM di, 0);
      }
#ifdef DEBUG
      /* not needed in non DEBUG state, because of memset */
      if(xc->xc_Flags & XADCF_FREEDISKINFO)
        ai->xaip_ArchiveInfo.xai_DiskInfo = 0;
#endif
    }
  }

  if(ai->xaip_ArchiveInfo.xai_ImageInfo)
    xadFreeObjectA(XADM ai->xaip_ArchiveInfo.xai_ImageInfo, 0);

#ifdef DEBUG
  if(ai->xaip_ArchiveInfo.xai_DiskInfo)
    DebugMemError("xadFreeInfo: xai_DiskInfo entry not cleared");
  if(ai->xaip_ArchiveInfo.xai_FileInfo)
    DebugMemError("xadFreeInfo: xai_FileInfo entry not cleared");
  if(ai->xaip_ArchiveInfo.xai_SkipInfo)
    DebugMemError("xadFreeInfo: xai_SkipInfo entry not cleared");
  if(ai->xaip_ArchiveInfo.xai_PrivateClient)
    DebugMemError("xadFreeInfo: xai_PrivateClient entry not cleared");
#endif

  ai->xaip_ArchiveInfo.xai_Flags |= XADAIF_ONLYIN; /* cleared afterwards by memset */
  xadFreeHookAccessA(XADM_PRIV XADM_AI(ai), 0);

  /* clear the structure to allow reuse */
  memset(ai, 0, sizeof(struct xadArchiveInfoP));
}
ENDFUNC

#endif  /* XADMASTER_INFO_C */