summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2009-06-04 15:21:21 +0200
committerDavid Sommerseth <davids@redhat.com>2009-06-04 15:21:21 +0200
commitadc4191973b177f557d9a851d558d09cde841efe (patch)
tree5e31e51dd1a87b65fb4eb6dac97b3682cf6cb5ac
parent5cd0472e1bc6a74f5011976e4b9fe31a0b84d938 (diff)
downloadpython-dmidecode-adc4191973b177f557d9a851d558d09cde841efe.tar.gz
python-dmidecode-adc4191973b177f557d9a851d558d09cde841efe.tar.xz
python-dmidecode-adc4191973b177f557d9a851d558d09cde841efe.zip
Avoid passing the option struct to dmidecode.c functions
-rw-r--r--src/dmidecode.c42
-rw-r--r--src/dmidecode.h8
-rw-r--r--src/dmidecodemodule.c10
-rw-r--r--src/dmidecodemodule.h10
4 files changed, 38 insertions, 32 deletions
diff --git a/src/dmidecode.c b/src/dmidecode.c
index 8f2c545..974d6e3 100644
--- a/src/dmidecode.c
+++ b/src/dmidecode.c
@@ -201,7 +201,7 @@ static int dmi_bcd_range(u8 value, u8 low, u8 high)
return 1;
}
-void dmi_dump(options *opt, xmlNode *node, struct dmi_header * h)
+void dmi_dump(xmlNode *node, struct dmi_header * h)
{
int row, i;
const char *s;
@@ -234,6 +234,9 @@ void dmi_dump(options *opt, xmlNode *node, struct dmi_header * h)
while((s = dmi_string(h, i++)) != NULL) {
//. FIXME: DUMP
/*
+ * opt->flags will need to be transported to the function somehow
+ * when this feature is implemented completely.
+ *
* if(opt->flags & FLAG_DUMP) {
* int j, l = strlen(s)+1;
* for(row=0; row<((l-1)>>4)+1; row++) {
@@ -3684,7 +3687,7 @@ void dmi_additional_info(xmlNode *node, const struct dmi_header *h)
** Main
*/
-xmlNode *dmi_decode(options *opt, xmlNode *prnt_n, struct dmi_header * h, u16 ver)
+xmlNode *dmi_decode(xmlNode *prnt_n, struct dmi_header * h, u16 ver)
{
const u8 *data = h->data;
xmlNode *sect_n = NULL, *sub_n = NULL, *sub2_n = NULL;
@@ -4815,7 +4818,7 @@ xmlNode *dmi_decode(options *opt, xmlNode *prnt_n, struct dmi_header * h, u16 ve
dmixml_AddAttribute(sect_n, "Type", "%i", h->type);
dmixml_AddAttribute(sect_n, "InfoType", "%s", h->type >= 128 ? "OEM-specific" : "Unknown");
- dmi_dump(opt, sect_n, h);
+ dmi_dump(sect_n, h);
break;
}
return sect_n;
@@ -4829,10 +4832,11 @@ void to_dmi_header(struct dmi_header *h, u8 * data)
h->data = data;
}
-xmlNode *dmi_table_string(options *opt, xmlNode *prnt_n, const struct dmi_header *h, const u8 *data, u16 ver)
+xmlNode *dmi_table_string(const struct string_keyword *opt_string, xmlNode *prnt_n,
+ const struct dmi_header *h, const u8 *data, u16 ver)
{
int key;
- u8 offset = opt->string->offset;
+ u8 offset = opt_string->offset;
xmlNode *handle_n = NULL, *dmi_n = NULL;
if(offset >= h->length)
@@ -4842,7 +4846,7 @@ xmlNode *dmi_table_string(options *opt, xmlNode *prnt_n, const struct dmi_header
assert( handle_n != NULL );
//. TODO: These should have more meaningful dictionary names
- key = (opt->string->type << 8) | offset;
+ key = (opt_string->type << 8) | offset;
switch (key) {
case 0x108:
@@ -5010,13 +5014,14 @@ int dump(const char *dumpfile)
return ret == 0 ? found : ret;
}
-static void dmi_table(options *opt, u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode)
+static void dmi_table(u8 *type, const struct string_keyword *opt_string,
+ u32 base, u16 len, u16 num, u16 ver, const char *devmem, xmlNode *xmlnode)
{
u8 *buf;
u8 *data;
int i = 0;
- if(opt->type == NULL) {
+ if(type == NULL) {
xmlNode *info_n = NULL;
info_n = dmixml_AddTextChild(xmlnode, "DMIinfo", "%i structures occupying %i bytes", num, len);
@@ -5049,9 +5054,8 @@ static void dmi_table(options *opt, u32 base, u16 len, u16 num, u16 ver, const c
int display;
to_dmi_header(&h, data);
- display = ((opt->type == NULL || opt->type[h.type])
- // && !(h.type>39 && h.type<=127)
- && !opt->string);
+ display = ((type == NULL || type[h.type]) // FIXME: Is this check correct?
+ && !opt_string);
/*
** If a short entry is found (less than 4 bytes), not only it
@@ -5094,11 +5098,11 @@ static void dmi_table(options *opt, u32 base, u16 len, u16 num, u16 ver, const c
* PyDict_SetItem(hDict, PyString_FromString("data"), dmi_decode(&h, ver));
* PyDict_SetItem(pydata, PyString_FromString(hid), hDict);
* } */
- handle_n = dmi_decode(opt, xmlnode, &h, ver);
+ handle_n = dmi_decode(xmlnode, &h, ver);
} else
fprintf(stderr, "<TRUNCATED>");
- } else if(opt->string != NULL && opt->string->type == h.type) {
- handle_n = dmi_table_string(opt, xmlnode, &h, data, ver);
+ } else if(opt_string != NULL && opt_string->type == h.type) {
+ handle_n = dmi_table_string(opt_string, xmlnode, &h, data, ver);
}
if( handle_n != NULL ) {
dmixml_AddAttribute(handle_n, "handle", "0x%04x", h.handle);
@@ -5172,7 +5176,8 @@ xmlNode *smbios_decode_get_version(u8 * buf, const char *devmem)
return data_n;
}
-int smbios_decode(options *opt, u8 * buf, const char *devmem, xmlNode *xmlnode)
+int smbios_decode(u8 *type, const struct string_keyword *opt_string,
+ u8 *buf, const char *devmem, xmlNode *xmlnode)
{
int check = _smbios_decode_check(buf);
@@ -5188,7 +5193,7 @@ int smbios_decode(options *opt, u8 * buf, const char *devmem, xmlNode *xmlnode)
break;
}
//printf(">>%d @ %d, %d<<\n", DWORD(buf+0x18), WORD(buf+0x16), WORD(buf+0x1C));
- dmi_table(opt, DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C), ver, devmem,
+ dmi_table(type, opt_string, DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C), ver, devmem,
xmlnode);
}
return check;
@@ -5227,12 +5232,13 @@ xmlNode *legacy_decode_get_version(u8 * buf, const char *devmem)
return data_n;
}
-int legacy_decode(options *opt, u8 * buf, const char *devmem, xmlNode *xmlnode)
+int legacy_decode(u8 *type, const struct string_keyword *opt_string,
+ u8 *buf, const char *devmem, xmlNode *xmlnode)
{
int check = _legacy_decode_check(buf);
if(check == 1)
- dmi_table(opt, DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C),
+ dmi_table(type, opt_string, DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C),
((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F), devmem, xmlnode);
return check;
}
diff --git a/src/dmidecode.h b/src/dmidecode.h
index c199b7a..571c381 100644
--- a/src/dmidecode.h
+++ b/src/dmidecode.h
@@ -29,14 +29,14 @@ struct dmi_header {
u8 *data;
};
-void dmi_dump(options *, xmlNode *node, struct dmi_header * h);
-xmlNode *dmi_decode(options *, xmlNode *parent_n, struct dmi_header * h, u16 ver);
+void dmi_dump(xmlNode *node, struct dmi_header * h);
+xmlNode *dmi_decode(xmlNode *parent_n, struct dmi_header * h, u16 ver);
int address_from_efi(size_t * address);
void to_dmi_header(struct dmi_header *h, u8 * data);
xmlNode *smbios_decode_get_version(u8 * buf, const char *devmem);
-int smbios_decode(options *, u8 * buf, const char *devmem, xmlNode *xmlnode);
+int smbios_decode(u8 *type, const struct string_keyword *opt_string, u8 *buf, const char *devmem, xmlNode *xmlnode);
xmlNode *legacy_decode_get_version(u8 * buf, const char *devmem);
-int legacy_decode(options *, u8 * buf, const char *devmem, xmlNode *xmlnode);
+int legacy_decode(u8 *type, const struct string_keyword *opt_string, u8 *buf, const char *devmem, xmlNode *xmlnode);
const char *dmi_string(const struct dmi_header *dm, u8 s);
void dmi_system_uuid(xmlNode *node, const u8 * p, u16 ver);
diff --git a/src/dmidecodemodule.c b/src/dmidecodemodule.c
index f9b0eb1..ab4561b 100644
--- a/src/dmidecodemodule.c
+++ b/src/dmidecodemodule.c
@@ -211,10 +211,10 @@ int dmidecode_get_xml(options *opt, xmlNode* dmixml_n)
// printf("Reading SMBIOS/DMI data from file %s.\n", dumpfile);
if((buf = mem_chunk(0, 0x20, opt->dumpfile)) != NULL) {
if(memcmp(buf, "_SM_", 4) == 0) {
- if(smbios_decode(opt, buf, opt->dumpfile, dmixml_n))
+ if(smbios_decode(opt->type, opt->string, buf, opt->dumpfile, dmixml_n))
found++;
} else if(memcmp(buf, "_DMI_", 5) == 0) {
- if(legacy_decode(opt, buf, opt->dumpfile, dmixml_n))
+ if(legacy_decode(opt->type, opt->string, buf, opt->dumpfile, dmixml_n))
found++;
}
} else {
@@ -228,12 +228,12 @@ int dmidecode_get_xml(options *opt, xmlNode* dmixml_n)
if((buf = mem_chunk(0xF0000, 0x10000, opt->devmem)) != NULL) {
for(fp = 0; fp <= 0xFFF0; fp += 16) {
if(memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0) {
- if(smbios_decode(opt, buf + fp, opt->devmem, dmixml_n)) {
+ if(smbios_decode(opt->type, opt->string, buf + fp, opt->devmem, dmixml_n)) {
found++;
fp += 16;
}
} else if(memcmp(buf + fp, "_DMI_", 5) == 0) {
- if(legacy_decode(opt, buf + fp, opt->devmem, dmixml_n))
+ if(legacy_decode(opt->type, opt->string, buf + fp, opt->devmem, dmixml_n))
found++;
}
}
@@ -244,7 +244,7 @@ int dmidecode_get_xml(options *opt, xmlNode* dmixml_n)
} else {
if((buf = mem_chunk(fp, 0x20, opt->devmem)) == NULL)
ret = 1;
- else if(smbios_decode(opt, buf, opt->devmem, dmixml_n))
+ else if(smbios_decode(opt->type, opt->string, buf, opt->devmem, dmixml_n))
found++;
// TODO: dmixml_AddAttribute(dmixml_n, "efi_address", "0x%08x", efiAddress);
}
diff --git a/src/dmidecodemodule.h b/src/dmidecodemodule.h
index 04d1203..7d085b2 100644
--- a/src/dmidecodemodule.h
+++ b/src/dmidecodemodule.h
@@ -24,13 +24,13 @@
xmlNode *dmidecode_get_version(options *);
//extern void dmi_decode(struct dmi_header *h, u16 ver, PyObject* pydata);
-extern void dmi_dump(options *, xmlNode *node, struct dmi_header *h);
-extern xmlNode *dmi_decode(options *, xmlNode *parent_n, struct dmi_header * h, u16 ver);
+extern void dmi_dump(xmlNode *node, struct dmi_header *h);
+extern xmlNode *dmi_decode(xmlNode *parent_n, struct dmi_header * h, u16 ver);
extern int address_from_efi(size_t * address);
extern void to_dmi_header(struct dmi_header *h, u8 * data);
-extern void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem);
-extern int smbios_decode(options *, u8 * buf, const char *devmem, xmlNode *node);
-extern int legacy_decode(options *, u8 * buf, const char *devmem, xmlNode *node);
+// extern void dmi_table(u8 *type, const struct string_keyword *opt_string, u32 base, u16 len, u16 num, u16 ver, const char *devmem);
+extern int smbios_decode(u8 *type, const struct string_keyword *opt_string, u8 *buf, const char *devmem, xmlNode *node);
+extern int legacy_decode(u8 *type, const struct string_keyword *opt_string, u8 *buf, const char *devmem, xmlNode *node);
extern xmlNode *smbios_decode_get_version(u8 * buf, const char *devmem);
extern xmlNode *legacy_decode_get_version(u8 * buf, const char *devmem);
extern void *mem_chunk(size_t base, size_t len, const char *devmem);