Skip to content

Commit 47982e5

Browse files
committed
xml: Read context version into context structure
Store the context version that may appear in the XML string into the context structure. Signed-off-by: Paul Cercueil <[email protected]>
1 parent 9f67f70 commit 47982e5

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

context.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ void iio_context_destroy(struct iio_context *ctx)
272272
free(ctx->devices);
273273
free(ctx->xml);
274274
free(ctx->description);
275+
free(ctx->git_tag);
275276
free(ctx->pdata);
276277
free(ctx);
277278
}

iio-private.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ struct iio_context {
136136
const char *name;
137137
char *description;
138138

139+
unsigned int major;
140+
unsigned int minor;
141+
char *git_tag;
142+
139143
struct iio_device **devices;
140144
unsigned int nb_devices;
141145

xml.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,12 @@ static int iio_populate_xml_context_helper(struct iio_context *ctx, xmlNode *roo
407407

408408
static struct iio_context * iio_create_xml_context_helper(xmlDoc *doc)
409409
{
410-
const char *description = NULL;
410+
const char *description = NULL, *git_tag = NULL, *content;
411411
struct iio_context *ctx;
412+
long major = 0, minor = 0;
412413
xmlNode *root;
413414
xmlAttr *attr;
415+
char *end;
414416
int err;
415417

416418
root = xmlDocGetRootElement(doc);
@@ -421,17 +423,42 @@ static struct iio_context * iio_create_xml_context_helper(xmlDoc *doc)
421423
}
422424

423425
for (attr = root->properties; attr; attr = attr->next) {
424-
if (!strcmp((char *) attr->name, "description"))
425-
description = (const char *)attr->children->content;
426-
else if (strcmp((char *) attr->name, "name"))
426+
content = (const char *) attr->children->content;
427+
428+
if (!strcmp((char *) attr->name, "description")) {
429+
description = content;
430+
} else if (!strcmp((char *) attr->name, "version-major")) {
431+
major = strtol(content, &end, 10);
432+
if (*end != '\0')
433+
IIO_WARNING("invalid format for major version\n");
434+
} else if (!strcmp((char *) attr->name, "version-minor")) {
435+
minor = strtol(content, &end, 10);
436+
if (*end != '\0')
437+
IIO_WARNING("invalid format for minor version\n");
438+
} else if (!strcmp((char *) attr->name, "version-git")) {
439+
git_tag = content;
440+
} else if (strcmp((char *) attr->name, "name")) {
427441
IIO_WARNING("Unknown parameter \'%s\' in <context>\n",
428-
(char *) attr->children->content);
442+
content);
443+
}
429444
}
430445

431446
ctx = iio_context_create_from_backend(&xml_backend, description);
432447
if (!ctx)
433448
return NULL;
434449

450+
if (git_tag) {
451+
ctx->major = major;
452+
ctx->minor = minor;
453+
454+
ctx->git_tag = iio_strdup(git_tag);
455+
if (!ctx->git_tag) {
456+
iio_context_destroy(ctx);
457+
errno = ENOMEM;
458+
return NULL;
459+
}
460+
}
461+
435462
err = iio_populate_xml_context_helper(ctx, root);
436463
if (err) {
437464
iio_context_destroy(ctx);

0 commit comments

Comments
 (0)