plptools
Loading...
Searching...
No Matches
sisreqrecord.cpp
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 2002 Daniel Brahneborg <basic.chello@se>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
18 */
19#include "config.h"
20
21#include "sisreqrecord.h"
22#include "sisfile.h"
23#include "plpintl.h"
24
25#include <stdio.h>
26
28SISReqRecord::fillFrom(uint8_t* buf, int* base, off_t len, SISFile* sisFile)
29{
30 int n = sisFile->m_header.m_nlangs;
31 if (*base + 12 + n * 4 * 2 > len)
32 return SIS_TRUNCATED;
33
34 uint8_t* p = buf + *base;
35 int size = 0;
36
37 m_uid = read32(p);
38 m_major = read16(p + 4);
39 m_minor = read16(p + 6);
40 m_variant = read32(p + 8);
41 m_nameLengths = new uint32_t[n];
42 m_namePtrs = new uint32_t[n];
43 if (logLevel >= 2)
44 printf(_("Requisite: uid=%08x, version=%d.%d-%d.\n"),
46
47 // First read lengths.
48 //
49 size = 12;
50 for (int i = 0; i < n; ++i)
51 {
52 m_nameLengths[i] = read32(p + size);
53 if (logLevel >= 2)
54 printf(_("Got namelength %d\n"), m_nameLengths[i]);
55 size += 4;
56 }
57
58 // Then read ptrs.
59 //
60 for (int i = 0; i < n; ++i)
61 {
62 m_namePtrs[i] = read32(p + size);
63 if (logLevel >= 2)
64 printf(_("Got namepos %d\n"), m_namePtrs[i]);
65 if (m_namePtrs[i] + m_nameLengths[i] > len)
66 {
67 printf(_("Position/length too large for req record %d.\n"), i);
68 return SIS_CORRUPTED;
69 }
70 size += 4;
71 if (logLevel >= 2)
72 printf(_("Name of requisite for %s is %.*s\n"),
73 sisFile->getLanguage(i)->m_name,
75 buf + m_namePtrs[i]);
76 }
77 if (logLevel >= 1)
78 printf(_("%d .. %d (%d bytes): Req record for uid %08x\n"),
79 *base, *base + size, size, m_uid);
80 *base += size;
81 return SIS_OK;
82}
uint16_t m_nlangs
Definition: sisfileheader.h:87
The top level container of a SIS file.
Definition: sisfile.h:36
SISFileHeader m_header
Definition: sisfile.h:108
int getLanguage()
Return the currently selected installation language.
Definition: sisfile.cpp:137
uint32_t m_uid
Definition: sisreqrecord.h:46
uint16_t m_major
Definition: sisreqrecord.h:47
uint32_t m_variant
Definition: sisreqrecord.h:49
uint32_t * m_namePtrs
Definition: sisreqrecord.h:51
SisRC fillFrom(uint8_t *buf, int *base, off_t len, SISFile *sisFile)
Populate the fields.
uint16_t m_minor
Definition: sisreqrecord.h:48
uint32_t * m_nameLengths
Definition: sisreqrecord.h:50
#define _(String)
Definition: plpintl.h:35
uint32_t read32(uint8_t *p)
Definition: sistypes.cpp:62
int logLevel
Definition: sistypes.cpp:25
uint16_t read16(uint8_t *p)
Definition: sistypes.cpp:57
SisRC
Return Codes.
Definition: sistypes.h:29
@ SIS_OK
Definition: sistypes.h:30
@ SIS_TRUNCATED
Definition: sistypes.h:31
@ SIS_CORRUPTED
Definition: sistypes.h:33