Skip to content

Commit c2b967f

Browse files
committed
Updated htsmsg support with a few extra support routines and corrected a mistake in the XML attrib support routine.
1 parent e81e4f4 commit c2b967f

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed

Diff for: src/htsmsg.c

+19-4
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@ htsmsg_get_s64(htsmsg_t *msg, const char *name, int64_t *s64p)
316316
return 0;
317317
}
318318

319+
/**
320+
*
321+
*/
322+
int64_t
323+
htsmsg_get_s64_or_default(htsmsg_t *msg, const char *name, int64_t def)
324+
{
325+
int64_t s64;
326+
return htsmsg_get_s64(msg, name, &s64) ? def : s64;
327+
}
328+
319329
/**
320330
*
321331
*/
@@ -363,15 +373,13 @@ htsmsg_get_u32(htsmsg_t *msg, const char *name, uint32_t *u32p)
363373
/**
364374
*
365375
*/
366-
int
376+
uint32_t
367377
htsmsg_get_u32_or_default(htsmsg_t *msg, const char *name, uint32_t def)
368378
{
369379
uint32_t u32;
370-
return htsmsg_get_u32(msg, name, &u32) ? def : u32;
380+
return htsmsg_get_u32(msg, name, &u32) ? def : u32;
371381
}
372382

373-
374-
375383
/*
376384
*
377385
*/
@@ -449,6 +457,13 @@ htsmsg_get_str(htsmsg_t *msg, const char *name)
449457

450458
}
451459

460+
const char *
461+
htsmsg_get_str_or_default(htsmsg_t *msg, const char *name, const char *def)
462+
{
463+
const char *str = htsmsg_get_str(msg, name);
464+
return str ?: def;
465+
}
466+
452467
/*
453468
*
454469
*/

Diff for: src/htsmsg.h

+28-8
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@ void htsmsg_add_binptr(htsmsg_t *msg, const char *name, const void *bin,
160160
*/
161161
int htsmsg_get_u32(htsmsg_t *msg, const char *name, uint32_t *u32p);
162162

163+
/**
164+
* Return the field \p name as an u32.
165+
*
166+
* @return An unsigned 32 bit integer or def if the field can not be found
167+
* or if conversion is not possible.
168+
*/
169+
uint32_t htsmsg_get_u32_or_default
170+
(htsmsg_t *msg, const char *name, uint32_t def);
171+
163172
/**
164173
* Get an integer as an signed 32 bit integer.
165174
*
@@ -178,6 +187,16 @@ int htsmsg_get_s32(htsmsg_t *msg, const char *name, int32_t *s32p);
178187
*/
179188
int htsmsg_get_s64(htsmsg_t *msg, const char *name, int64_t *s64p);
180189

190+
191+
/**
192+
* Return the field \p name as an s64.
193+
*
194+
* @return A signed 64 bit integer or def if the field can not be found
195+
* or if conversion is not possible.
196+
*/
197+
int64_t htsmsg_get_s64_or_default
198+
(htsmsg_t *msg, const char *name, int64_t def);
199+
181200
/**
182201
* Get an integer as an unsigned 64 bit integer.
183202
*
@@ -217,6 +236,15 @@ htsmsg_t *htsmsg_get_list(htsmsg_t *msg, const char *name);
217236
*/
218237
const char *htsmsg_get_str(htsmsg_t *msg, const char *name);
219238

239+
/**
240+
* Get a field of type 'string'. No copying is done.
241+
*
242+
* @return def if the field can not be found or not of string type.
243+
* Otherwise a pointer to the data is returned.
244+
*/
245+
const char *htsmsg_get_str_or_default
246+
(htsmsg_t *msg, const char *name, const char *def);
247+
220248
/**
221249
* Get a field of type 'map'. No copying is done.
222250
*
@@ -236,14 +264,6 @@ htsmsg_t *htsmsg_get_map_multi(htsmsg_t *msg, ...);
236264
*/
237265
const char *htsmsg_field_get_string(htsmsg_field_t *f);
238266

239-
/**
240-
* Return the field \p name as an u32.
241-
*
242-
* @return An unsigned 32 bit integer or NULL if the field can not be found
243-
* or if conversion is not possible.
244-
*/
245-
int htsmsg_get_u32_or_default(htsmsg_t *msg, const char *name, uint32_t def);
246-
247267
/**
248268
* Remove the given field called \p name from the message \p msg.
249269
*/

Diff for: src/htsmsg_xml.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ const char *
897897
htsmsg_xml_get_attr_str ( htsmsg_t *tag, const char *name )
898898
{
899899
htsmsg_t *attr = htsmsg_get_map(tag, "attrib");
900-
if (attr) return htsmsg_get_str(tag, name);
900+
if (attr) return htsmsg_get_str(attr, name);
901901
return NULL;
902902
}
903903

0 commit comments

Comments
 (0)