libubox
C utility functions for OpenWrt.
blobmsg.h File Reference
#include <stdarg.h>
#include "blob.h"

Go to the source code of this file.

Data Structures

struct  blobmsg_hdr
 
struct  blobmsg_policy
 

Macros

#define BLOBMSG_ALIGN   2
 
#define BLOBMSG_PADDING(len)   (((len) + (1 << BLOBMSG_ALIGN) - 1) & ~((1 << BLOBMSG_ALIGN) - 1))
 
#define blobmsg_for_each_attr(pos, attr, rem)
 
#define __blobmsg_for_each_attr(pos, attr, rem)
 

Enumerations

enum  blobmsg_type {
  BLOBMSG_TYPE_UNSPEC , BLOBMSG_TYPE_ARRAY , BLOBMSG_TYPE_TABLE , BLOBMSG_TYPE_STRING ,
  BLOBMSG_TYPE_INT64 , BLOBMSG_TYPE_INT32 , BLOBMSG_TYPE_INT16 , BLOBMSG_TYPE_INT8 ,
  BLOBMSG_TYPE_BOOL = BLOBMSG_TYPE_INT8 , BLOBMSG_TYPE_DOUBLE , __BLOBMSG_TYPE_LAST , BLOBMSG_TYPE_LAST = __BLOBMSG_TYPE_LAST - 1 ,
  BLOBMSG_CAST_INT64 = __BLOBMSG_TYPE_LAST
}
 

Functions

struct blobmsg_hdr __attribute__ ((packed))
 
static int blobmsg_hdrlen (unsigned int namelen)
 
static void blobmsg_clear_name (struct blob_attr *attr)
 
static const char * blobmsg_name (const struct blob_attr *attr)
 
static int blobmsg_type (const struct blob_attr *attr)
 
static uint16_t blobmsg_namelen (const struct blobmsg_hdr *hdr)
 
static void * blobmsg_data (const struct blob_attr *attr)
 
static size_t blobmsg_data_len (const struct blob_attr *attr)
 
static size_t blobmsg_len (const struct blob_attr *attr)
 
bool blobmsg_check_attr (const struct blob_attr *attr, bool name)
 
bool blobmsg_check_attr_len (const struct blob_attr *attr, bool name, size_t len)
 
bool blobmsg_check_attr_list (const struct blob_attr *attr, int type)
 
bool blobmsg_check_attr_list_len (const struct blob_attr *attr, int type, size_t len)
 
int blobmsg_check_array (const struct blob_attr *attr, int type)
 
int blobmsg_check_array_len (const struct blob_attr *attr, int type, size_t len)
 
int blobmsg_parse (const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len)
 
int blobmsg_parse_array (const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len)
 
int blobmsg_add_field (struct blob_buf *buf, int type, const char *name, const void *data, unsigned int len)
 
static int blobmsg_parse_attr (const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, struct blob_attr *data)
 
static int blobmsg_parse_array_attr (const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, struct blob_attr *data)
 
static int blobmsg_add_double (struct blob_buf *buf, const char *name, double val)
 
static int blobmsg_add_u8 (struct blob_buf *buf, const char *name, uint8_t val)
 
static int blobmsg_add_u16 (struct blob_buf *buf, const char *name, uint16_t val)
 
static int blobmsg_add_u32 (struct blob_buf *buf, const char *name, uint32_t val)
 
static int blobmsg_add_u64 (struct blob_buf *buf, const char *name, uint64_t val)
 
static int blobmsg_add_string (struct blob_buf *buf, const char *name, const char *string)
 
static int blobmsg_add_blob (struct blob_buf *buf, struct blob_attr *attr)
 
void * blobmsg_open_nested (struct blob_buf *buf, const char *name, bool array)
 
static void * blobmsg_open_array (struct blob_buf *buf, const char *name)
 
static void * blobmsg_open_table (struct blob_buf *buf, const char *name)
 
static void blobmsg_close_array (struct blob_buf *buf, void *cookie)
 
static void blobmsg_close_table (struct blob_buf *buf, void *cookie)
 
static int blobmsg_buf_init (struct blob_buf *buf)
 
static uint8_t blobmsg_get_u8 (struct blob_attr *attr)
 
static bool blobmsg_get_bool (struct blob_attr *attr)
 
static uint16_t blobmsg_get_u16 (struct blob_attr *attr)
 
static uint32_t blobmsg_get_u32 (struct blob_attr *attr)
 
static uint64_t blobmsg_get_u64 (struct blob_attr *attr)
 
static uint64_t blobmsg_cast_u64 (struct blob_attr *attr)
 
static int64_t blobmsg_cast_s64 (struct blob_attr *attr)
 
static double blobmsg_get_double (struct blob_attr *attr)
 
static char * blobmsg_get_string (struct blob_attr *attr)
 
void * blobmsg_alloc_string_buffer (struct blob_buf *buf, const char *name, unsigned int maxlen)
 
void * blobmsg_realloc_string_buffer (struct blob_buf *buf, unsigned int maxlen)
 
void blobmsg_add_string_buffer (struct blob_buf *buf)
 
int blobmsg_vprintf (struct blob_buf *buf, const char *name, const char *format, va_list arg)
 
int blobmsg_printf (struct blob_buf *buf, const char *name, const char *format,...) __attribute__((format(printf
 

Variables

uint16_t namelen
 
uint8_t name []
 
struct blobmsg_policy __attribute__
 

Macro Definition Documentation

◆ __blobmsg_for_each_attr

#define __blobmsg_for_each_attr (   pos,
  attr,
  rem 
)
Value:
for (pos = (struct blob_attr *) (attr ? blobmsg_data(attr) : NULL); \
rem >= sizeof(struct blob_attr) && (blob_pad_len(pos) <= rem) && \
(blob_pad_len(pos) >= sizeof(struct blob_attr)); \
rem -= blob_pad_len(pos), pos = blob_next(pos))
static size_t blob_pad_len(const struct blob_attr *attr)
Definition: blob.h:118
static struct blob_attr * blob_next(const struct blob_attr *attr)
Definition: blob.h:185
static void * blobmsg_data(const struct blob_attr *attr)
Definition: blobmsg.h:78
Definition: blob.h:52

Definition at line 371 of file blobmsg.h.

◆ BLOBMSG_ALIGN

#define BLOBMSG_ALIGN   2

Definition at line 22 of file blobmsg.h.

◆ blobmsg_for_each_attr

#define blobmsg_for_each_attr (   pos,
  attr,
  rem 
)
Value:
for (rem = attr ? blobmsg_data_len(attr) : 0, \
pos = (struct blob_attr *) (attr ? blobmsg_data(attr) : NULL); \
rem >= sizeof(struct blob_attr) && (blob_pad_len(pos) <= rem) && \
(blob_pad_len(pos) >= sizeof(struct blob_attr)); \
rem -= blob_pad_len(pos), pos = blob_next(pos))
static size_t blobmsg_data_len(const struct blob_attr *attr)
Definition: blobmsg.h:95

Definition at line 364 of file blobmsg.h.

◆ BLOBMSG_PADDING

#define BLOBMSG_PADDING (   len)    (((len) + (1 << BLOBMSG_ALIGN) - 1) & ~((1 << BLOBMSG_ALIGN) - 1))

Definition at line 23 of file blobmsg.h.

Enumeration Type Documentation

◆ blobmsg_type

Enumerator
BLOBMSG_TYPE_UNSPEC 
BLOBMSG_TYPE_ARRAY 
BLOBMSG_TYPE_TABLE 
BLOBMSG_TYPE_STRING 
BLOBMSG_TYPE_INT64 
BLOBMSG_TYPE_INT32 
BLOBMSG_TYPE_INT16 
BLOBMSG_TYPE_INT8 
BLOBMSG_TYPE_BOOL 
BLOBMSG_TYPE_DOUBLE 
__BLOBMSG_TYPE_LAST 
BLOBMSG_TYPE_LAST 
BLOBMSG_CAST_INT64 

Definition at line 25 of file blobmsg.h.

25  {
39 };
@ BLOBMSG_TYPE_LAST
Definition: blobmsg.h:37
@ BLOBMSG_TYPE_TABLE
Definition: blobmsg.h:28
@ __BLOBMSG_TYPE_LAST
Definition: blobmsg.h:36
@ BLOBMSG_TYPE_STRING
Definition: blobmsg.h:29
@ BLOBMSG_TYPE_BOOL
Definition: blobmsg.h:34
@ BLOBMSG_TYPE_INT16
Definition: blobmsg.h:32
@ BLOBMSG_TYPE_ARRAY
Definition: blobmsg.h:27
@ BLOBMSG_TYPE_UNSPEC
Definition: blobmsg.h:26
@ BLOBMSG_TYPE_INT8
Definition: blobmsg.h:33
@ BLOBMSG_TYPE_INT32
Definition: blobmsg.h:31
@ BLOBMSG_TYPE_INT64
Definition: blobmsg.h:30
@ BLOBMSG_TYPE_DOUBLE
Definition: blobmsg.h:35
@ BLOBMSG_CAST_INT64
Definition: blobmsg.h:38

Function Documentation

◆ __attribute__()

struct blobmsg_hdr __attribute__ ( (packed)  )

◆ blobmsg_add_blob()

static int blobmsg_add_blob ( struct blob_buf buf,
struct blob_attr attr 
)
inlinestatic

Definition at line 241 of file blobmsg.h.

242 {
243  return blobmsg_add_field(buf, blobmsg_type(attr), blobmsg_name(attr),
244  blobmsg_data(attr), blobmsg_data_len(attr));
245 }
static const char * blobmsg_name(const struct blob_attr *attr)
Definition: blobmsg.h:62
int blobmsg_add_field(struct blob_buf *buf, int type, const char *name, const void *data, unsigned int len)
Definition: blobmsg.c:377
blobmsg_type
Definition: blobmsg.h:25
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_add_double()

static int blobmsg_add_double ( struct blob_buf buf,
const char *  name,
double  val 
)
inlinestatic

Definition at line 196 of file blobmsg.h.

197 {
198  union {
199  double d;
200  uint64_t u64;
201  } v;
202  v.d = val;
203  v.u64 = cpu_to_be64(v.u64);
204  return blobmsg_add_field(buf, BLOBMSG_TYPE_DOUBLE, name, &v.u64, 8);
205 }
uint8_t name[]
Definition: blobmsg.h:1
#define cpu_to_be64(x)
Definition: utils.h:162
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_add_field()

int blobmsg_add_field ( struct blob_buf buf,
int  type,
const char *  name,
const void *  data,
unsigned int  len 
)

Definition at line 377 of file blobmsg.c.

379 {
380  struct blob_attr *attr;
381  void *data_dest;
382 
383  attr = blobmsg_new(buf, type, name, len, &data_dest);
384  if (!attr)
385  return -1;
386 
387  if (len > 0)
388  memcpy(data_dest, data, len);
389 
390  return 0;
391 }
char data[]
Definition: blob.h:1
static struct blob_attr * blobmsg_new(struct blob_buf *buf, int type, const char *name, int payload_len, void **data)
Definition: blobmsg.c:227
uint8_t type
Definition: udebug-proto.h:0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_add_string()

static int blobmsg_add_string ( struct blob_buf buf,
const char *  name,
const char *  string 
)
inlinestatic

Definition at line 235 of file blobmsg.h.

236 {
237  return blobmsg_add_field(buf, BLOBMSG_TYPE_STRING, name, string, strlen(string) + 1);
238 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_add_string_buffer()

void blobmsg_add_string_buffer ( struct blob_buf buf)

Definition at line 361 of file blobmsg.c.

362 {
363  struct blob_attr *attr;
364  int len, attrlen;
365 
366  attr = blob_next(buf->head);
367  len = strlen(blobmsg_data(attr)) + 1;
368 
369  attrlen = blob_raw_len(attr) + len;
370  blob_set_raw_len(attr, attrlen);
371  blob_fill_pad(attr);
372 
373  blob_set_raw_len(buf->head, blob_raw_len(buf->head) + blob_pad_len(attr));
374 }
void blob_set_raw_len(struct blob_attr *attr, unsigned int len)
Definition: blob.c:124
void blob_fill_pad(struct blob_attr *attr)
Definition: blob.c:113
static size_t blob_raw_len(const struct blob_attr *attr)
Definition: blob.h:109
struct blob_attr * head
Definition: blob.h:65
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_add_u16()

static int blobmsg_add_u16 ( struct blob_buf buf,
const char *  name,
uint16_t  val 
)
inlinestatic

Definition at line 214 of file blobmsg.h.

215 {
216  val = cpu_to_be16(val);
217  return blobmsg_add_field(buf, BLOBMSG_TYPE_INT16, name, &val, 2);
218 }
#define cpu_to_be16(x)
Definition: utils.h:164
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_add_u32()

static int blobmsg_add_u32 ( struct blob_buf buf,
const char *  name,
uint32_t  val 
)
inlinestatic

Definition at line 221 of file blobmsg.h.

222 {
223  val = cpu_to_be32(val);
224  return blobmsg_add_field(buf, BLOBMSG_TYPE_INT32, name, &val, 4);
225 }
#define cpu_to_be32(x)
Definition: utils.h:163
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_add_u64()

static int blobmsg_add_u64 ( struct blob_buf buf,
const char *  name,
uint64_t  val 
)
inlinestatic

Definition at line 228 of file blobmsg.h.

229 {
230  val = cpu_to_be64(val);
231  return blobmsg_add_field(buf, BLOBMSG_TYPE_INT64, name, &val, 8);
232 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_add_u8()

static int blobmsg_add_u8 ( struct blob_buf buf,
const char *  name,
uint8_t  val 
)
inlinestatic

Definition at line 208 of file blobmsg.h.

209 {
210  return blobmsg_add_field(buf, BLOBMSG_TYPE_INT8, name, &val, 1);
211 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_alloc_string_buffer()

void* blobmsg_alloc_string_buffer ( struct blob_buf buf,
const char *  name,
unsigned int  maxlen 
)

Definition at line 326 of file blobmsg.c.

327 {
328  struct blob_attr *attr;
329  void *data_dest;
330 
331  maxlen++;
332  attr = blobmsg_new(buf, BLOBMSG_TYPE_STRING, name, maxlen, &data_dest);
333  if (!attr)
334  return NULL;
335 
336  blob_set_raw_len(buf->head, blob_pad_len(buf->head) - blob_pad_len(attr));
337  blob_set_raw_len(attr, blob_raw_len(attr) - maxlen);
338 
339  return data_dest;
340 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_buf_init()

static int blobmsg_buf_init ( struct blob_buf buf)
inlinestatic

Definition at line 273 of file blobmsg.h.

274 {
275  return blob_buf_init(buf, BLOBMSG_TYPE_TABLE);
276 }
int blob_buf_init(struct blob_buf *buf, int id)
Definition: blob.c:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_cast_s64()

static int64_t blobmsg_cast_s64 ( struct blob_attr attr)
inlinestatic

Definition at line 322 of file blobmsg.h.

323 {
324  int64_t tmp = 0;
325 
326  if (blobmsg_type(attr) == BLOBMSG_TYPE_INT64)
327  tmp = blobmsg_get_u64(attr);
328  else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT32)
329  tmp = (int32_t)blobmsg_get_u32(attr);
330  else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT16)
331  tmp = (int16_t)blobmsg_get_u16(attr);
332  else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT8)
333  tmp = (int8_t)blobmsg_get_u8(attr);
334 
335  return tmp;
336 }
static uint16_t blobmsg_get_u16(struct blob_attr *attr)
Definition: blobmsg.h:288
static uint32_t blobmsg_get_u32(struct blob_attr *attr)
Definition: blobmsg.h:293
static uint64_t blobmsg_get_u64(struct blob_attr *attr)
Definition: blobmsg.h:298
static uint8_t blobmsg_get_u8(struct blob_attr *attr)
Definition: blobmsg.h:278
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_cast_u64()

static uint64_t blobmsg_cast_u64 ( struct blob_attr attr)
inlinestatic

Definition at line 306 of file blobmsg.h.

307 {
308  uint64_t tmp = 0;
309 
310  if (blobmsg_type(attr) == BLOBMSG_TYPE_INT64)
311  tmp = blobmsg_get_u64(attr);
312  else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT32)
313  tmp = blobmsg_get_u32(attr);
314  else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT16)
315  tmp = blobmsg_get_u16(attr);
316  else if (blobmsg_type(attr) == BLOBMSG_TYPE_INT8)
317  tmp = blobmsg_get_u8(attr);
318 
319  return tmp;
320 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_check_array()

int blobmsg_check_array ( const struct blob_attr attr,
int  type 
)

Definition at line 87 of file blobmsg.c.

88 {
89  return blobmsg_check_array_len(attr, type, blob_raw_len(attr));
90 }
int blobmsg_check_array_len(const struct blob_attr *attr, int type, size_t blob_len)
Definition: blobmsg.c:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_check_array_len()

int blobmsg_check_array_len ( const struct blob_attr attr,
int  type,
size_t  len 
)

Definition at line 92 of file blobmsg.c.

94 {
95  struct blob_attr *cur;
96  size_t rem;
97  bool name;
98  int size = 0;
99 
100  if (type > BLOBMSG_TYPE_LAST)
101  return -1;
102 
103  if (!blobmsg_check_attr_len(attr, false, blob_len))
104  return -1;
105 
106  switch (blobmsg_type(attr)) {
107  case BLOBMSG_TYPE_TABLE:
108  name = true;
109  break;
110  case BLOBMSG_TYPE_ARRAY:
111  name = false;
112  break;
113  default:
114  return -1;
115  }
116 
117  blobmsg_for_each_attr(cur, attr, rem) {
118  if (type != BLOBMSG_TYPE_UNSPEC && blobmsg_type(cur) != type)
119  return -1;
120 
121  if (!blobmsg_check_attr_len(cur, name, rem))
122  return -1;
123 
124  size++;
125  }
126 
127  return size;
128 }
static size_t blob_len(const struct blob_attr *attr)
Definition: blob.h:100
bool blobmsg_check_attr_len(const struct blob_attr *attr, bool name, size_t len)
Definition: blobmsg.c:58
#define blobmsg_for_each_attr(pos, attr, rem)
Definition: blobmsg.h:364
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_check_attr()

bool blobmsg_check_attr ( const struct blob_attr attr,
bool  name 
)

Definition at line 28 of file blobmsg.c.

29 {
30  return blobmsg_check_attr_len(attr, name, blob_raw_len(attr));
31 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_check_attr_len()

bool blobmsg_check_attr_len ( const struct blob_attr attr,
bool  name,
size_t  len 
)

Definition at line 58 of file blobmsg.c.

59 {
60  const char *data;
61  size_t data_len;
62  int id;
63 
64  if (len < sizeof(struct blob_attr))
65  return false;
66 
67  data_len = blob_raw_len(attr);
68  if (data_len < sizeof(struct blob_attr) || data_len > len)
69  return false;
70 
71  if (!blobmsg_check_name(attr, name))
72  return false;
73 
74  id = blob_id(attr);
75  if (id > BLOBMSG_TYPE_LAST)
76  return false;
77 
78  if (!blob_type[id])
79  return true;
80 
81  data = blobmsg_data(attr);
82  data_len = blobmsg_data_len(attr);
83 
84  return blob_check_type(data, data_len, blob_type[id]);
85 }
bool blob_check_type(const void *ptr, unsigned int len, int type)
Definition: blob.c:202
static unsigned int blob_id(const struct blob_attr *attr)
Definition: blob.h:84
static bool blobmsg_check_name(const struct blob_attr *attr, bool name)
Definition: blobmsg.c:33
static const int blob_type[__BLOBMSG_TYPE_LAST]
Definition: blobmsg.c:18
uint32_t id
Definition: udebug-proto.h:2
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_check_attr_list()

bool blobmsg_check_attr_list ( const struct blob_attr attr,
int  type 
)

Definition at line 130 of file blobmsg.c.

131 {
132  return blobmsg_check_array(attr, type) >= 0;
133 }
int blobmsg_check_array(const struct blob_attr *attr, int type)
Definition: blobmsg.c:87
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_check_attr_list_len()

bool blobmsg_check_attr_list_len ( const struct blob_attr attr,
int  type,
size_t  len 
)

Definition at line 135 of file blobmsg.c.

136 {
137  return blobmsg_check_array_len(attr, type, len) >= 0;
138 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_clear_name()

static void blobmsg_clear_name ( struct blob_attr attr)
inlinestatic

Definition at line 56 of file blobmsg.h.

57 {
58  struct blobmsg_hdr *hdr = (struct blobmsg_hdr *) blob_data(attr);
59  hdr->name[0] = 0;
60 }
static void * blob_data(const struct blob_attr *attr)
Definition: blob.h:75
uint8_t name[]
Definition: blobmsg.h:43
Here is the call graph for this function:

◆ blobmsg_close_array()

static void blobmsg_close_array ( struct blob_buf buf,
void *  cookie 
)
inlinestatic

Definition at line 262 of file blobmsg.h.

263 {
264  blob_nest_end(buf, cookie);
265 }
void blob_nest_end(struct blob_buf *buf, void *cookie)
Definition: blob.c:185
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_close_table()

static void blobmsg_close_table ( struct blob_buf buf,
void *  cookie 
)
inlinestatic

Definition at line 268 of file blobmsg.h.

269 {
270  blob_nest_end(buf, cookie);
271 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_data()

static void* blobmsg_data ( const struct blob_attr attr)
inlinestatic

Definition at line 78 of file blobmsg.h.

79 {
80  struct blobmsg_hdr *hdr;
81  char *data;
82 
83  if (!attr)
84  return NULL;
85 
86  hdr = (struct blobmsg_hdr *) blob_data(attr);
87  data = (char *) blob_data(attr);
88 
89  if (blob_is_extended(attr))
91 
92  return data;
93 }
static bool blob_is_extended(const struct blob_attr *attr)
Definition: blob.h:91
static uint16_t blobmsg_namelen(const struct blobmsg_hdr *hdr)
Definition: blobmsg.h:73
static int blobmsg_hdrlen(unsigned int namelen)
Definition: blobmsg.h:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_data_len()

static size_t blobmsg_data_len ( const struct blob_attr attr)
inlinestatic

Definition at line 95 of file blobmsg.h.

96 {
97  uint8_t *start, *end;
98 
99  if (!attr)
100  return 0;
101 
102  start = (uint8_t *) blob_data(attr);
103  end = (uint8_t *) blobmsg_data(attr);
104 
105  return blob_len(attr) - (end - start);
106 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_get_bool()

static bool blobmsg_get_bool ( struct blob_attr attr)
inlinestatic

Definition at line 283 of file blobmsg.h.

284 {
285  return *(uint8_t *) blobmsg_data(attr);
286 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_get_double()

static double blobmsg_get_double ( struct blob_attr attr)
inlinestatic

Definition at line 338 of file blobmsg.h.

339 {
340  union {
341  double d;
342  uint64_t u64;
343  } v;
344  v.u64 = blobmsg_get_u64(attr);
345  return v.d;
346 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_get_string()

static char* blobmsg_get_string ( struct blob_attr attr)
inlinestatic

Definition at line 348 of file blobmsg.h.

349 {
350  if (!attr)
351  return NULL;
352 
353  return (char *) blobmsg_data(attr);
354 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_get_u16()

static uint16_t blobmsg_get_u16 ( struct blob_attr attr)
inlinestatic

Definition at line 288 of file blobmsg.h.

289 {
290  return be16_to_cpu(*(uint16_t *) blobmsg_data(attr));
291 }
#define be16_to_cpu(x)
Definition: utils.h:168
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_get_u32()

static uint32_t blobmsg_get_u32 ( struct blob_attr attr)
inlinestatic

Definition at line 293 of file blobmsg.h.

294 {
295  return be32_to_cpu(*(uint32_t *) blobmsg_data(attr));
296 }
#define be32_to_cpu(x)
Definition: utils.h:167
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_get_u64()

static uint64_t blobmsg_get_u64 ( struct blob_attr attr)
inlinestatic

Definition at line 298 of file blobmsg.h.

299 {
300  uint32_t *ptr = (uint32_t *) blobmsg_data(attr);
301  uint64_t tmp = ((uint64_t) be32_to_cpu(ptr[0])) << 32;
302  tmp |= be32_to_cpu(ptr[1]);
303  return tmp;
304 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_get_u8()

static uint8_t blobmsg_get_u8 ( struct blob_attr attr)
inlinestatic

Definition at line 278 of file blobmsg.h.

279 {
280  return *(uint8_t *) blobmsg_data(attr);
281 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_hdrlen()

static int blobmsg_hdrlen ( unsigned int  namelen)
inlinestatic

Definition at line 51 of file blobmsg.h.

52 {
53  return BLOBMSG_PADDING(sizeof(struct blobmsg_hdr) + namelen + 1);
54 }
#define BLOBMSG_PADDING(len)
Definition: blobmsg.h:23
uint16_t namelen
Definition: blobmsg.h:0
Here is the caller graph for this function:

◆ blobmsg_len()

static size_t blobmsg_len ( const struct blob_attr attr)
inlinestatic

Definition at line 108 of file blobmsg.h.

109 {
110  return blobmsg_data_len(attr);
111 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_name()

static const char* blobmsg_name ( const struct blob_attr attr)
inlinestatic

Definition at line 62 of file blobmsg.h.

63 {
64  struct blobmsg_hdr *hdr = (struct blobmsg_hdr *) blob_data(attr);
65  return (const char *)(hdr + 1);
66 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_namelen()

static uint16_t blobmsg_namelen ( const struct blobmsg_hdr hdr)
static

Definition at line 73 of file blobmsg.h.

74 {
75  return be16_to_cpu(hdr->namelen);
76 }
uint16_t namelen
Definition: blobmsg.h:42
Here is the caller graph for this function:

◆ blobmsg_open_array()

static void* blobmsg_open_array ( struct blob_buf buf,
const char *  name 
)
inlinestatic

Definition at line 250 of file blobmsg.h.

251 {
252  return blobmsg_open_nested(buf, name, true);
253 }
void * blobmsg_open_nested(struct blob_buf *buf, const char *name, bool array)
Definition: blobmsg.c:266
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_open_nested()

void* blobmsg_open_nested ( struct blob_buf buf,
const char *  name,
bool  array 
)

Definition at line 266 of file blobmsg.c.

267 {
268  struct blob_attr *head;
270  unsigned long offset = attr_to_offset(buf, buf->head);
271  void *data;
272 
273  if (!name)
274  name = "";
275 
276  head = blobmsg_new(buf, type, name, 0, &data);
277  if (!head)
278  return NULL;
279  blob_set_raw_len(buf->head, blob_pad_len(buf->head) - blobmsg_hdrlen(strlen(name)));
280  buf->head = head;
281  return (void *)offset;
282 }
static int attr_to_offset(struct blob_buf *buf, struct blob_attr *attr)
Definition: blobmsg.c:259
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_open_table()

static void* blobmsg_open_table ( struct blob_buf buf,
const char *  name 
)
inlinestatic

Definition at line 256 of file blobmsg.h.

257 {
258  return blobmsg_open_nested(buf, name, false);
259 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_parse()

int blobmsg_parse ( const struct blobmsg_policy policy,
int  policy_len,
struct blob_attr **  tb,
void *  data,
unsigned int  len 
)

Definition at line 166 of file blobmsg.c.

168 {
169  const struct blobmsg_hdr *hdr;
170  struct blob_attr *attr;
171  uint8_t *pslen;
172  int i;
173 
174  memset(tb, 0, policy_len * sizeof(*tb));
175  if (!data || !len)
176  return -EINVAL;
177  pslen = alloca(policy_len);
178  for (i = 0; i < policy_len; i++) {
179  if (!policy[i].name)
180  continue;
181 
182  pslen[i] = strlen(policy[i].name);
183  }
184 
185  __blob_for_each_attr(attr, data, len) {
186  if (!blobmsg_check_attr_len(attr, false, len))
187  return -1;
188 
189  if (!blob_is_extended(attr))
190  continue;
191 
192  hdr = blob_data(attr);
193  for (i = 0; i < policy_len; i++) {
194  if (!policy[i].name)
195  continue;
196 
197  if (policy[i].type != BLOBMSG_TYPE_UNSPEC &&
198  policy[i].type != BLOBMSG_CAST_INT64 &&
199  blob_id(attr) != policy[i].type)
200  continue;
201 
202  if (policy[i].type == BLOBMSG_CAST_INT64 &&
203  (blob_id(attr) != BLOBMSG_TYPE_INT64 &&
204  blob_id(attr) != BLOBMSG_TYPE_INT32 &&
205  blob_id(attr) != BLOBMSG_TYPE_INT16 &&
206  blob_id(attr) != BLOBMSG_TYPE_INT8))
207  continue;
208 
209  if (blobmsg_namelen(hdr) != pslen[i])
210  continue;
211 
212  if (tb[i])
213  continue;
214 
215  if (strcmp(policy[i].name, (char *) hdr->name) != 0)
216  continue;
217 
218  tb[i] = attr;
219  }
220  }
221 
222  return 0;
223 }
#define __blob_for_each_attr(pos, attr, rem)
Definition: blob.h:244
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_parse_array()

int blobmsg_parse_array ( const struct blobmsg_policy policy,
int  policy_len,
struct blob_attr **  tb,
void *  data,
unsigned int  len 
)

Definition at line 140 of file blobmsg.c.

142 {
143  struct blob_attr *attr;
144  int i = 0;
145 
146  memset(tb, 0, policy_len * sizeof(*tb));
147  __blob_for_each_attr(attr, data, len) {
148  if (policy[i].type != BLOBMSG_TYPE_UNSPEC &&
149  blob_id(attr) != policy[i].type)
150  continue;
151 
152  if (!blobmsg_check_attr_len(attr, false, len))
153  return -1;
154 
155  if (tb[i])
156  continue;
157 
158  tb[i++] = attr;
159  if (i == policy_len)
160  break;
161  }
162 
163  return 0;
164 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_parse_array_attr()

static int blobmsg_parse_array_attr ( const struct blobmsg_policy policy,
int  policy_len,
struct blob_attr **  tb,
struct blob_attr data 
)
inlinestatic

Definition at line 189 of file blobmsg.h.

191 {
192  return blobmsg_parse_array(policy, policy_len, tb, blobmsg_data(data), blobmsg_len(data));
193 }
static size_t blobmsg_len(const struct blob_attr *attr)
Definition: blobmsg.h:108
int blobmsg_parse_array(const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len)
Definition: blobmsg.c:140
Here is the call graph for this function:

◆ blobmsg_parse_attr()

static int blobmsg_parse_attr ( const struct blobmsg_policy policy,
int  policy_len,
struct blob_attr **  tb,
struct blob_attr data 
)
inlinestatic

Definition at line 182 of file blobmsg.h.

184 {
185  return blobmsg_parse(policy, policy_len, tb, blobmsg_data(data), blobmsg_len(data));
186 }
int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len)
Definition: blobmsg.c:166
Here is the call graph for this function:

◆ blobmsg_printf()

int blobmsg_printf ( struct blob_buf buf,
const char *  name,
const char *  format,
  ... 
)

◆ blobmsg_realloc_string_buffer()

void* blobmsg_realloc_string_buffer ( struct blob_buf buf,
unsigned int  maxlen 
)

Definition at line 343 of file blobmsg.c.

344 {
345  struct blob_attr *attr = blob_next(buf->head);
346  int offset = attr_to_offset(buf, blob_next(buf->head)) + blob_pad_len(attr) - BLOB_COOKIE;
347  int required = maxlen + 1 - (buf->buflen - offset);
348 
349  if (required <= 0)
350  goto out;
351 
352  if (!blob_buf_grow(buf, required))
353  return NULL;
354  attr = blob_next(buf->head);
355 
356 out:
357  return blobmsg_data(attr);
358 }
bool blob_buf_grow(struct blob_buf *buf, int required)
Definition: blob.c:57
#define BLOB_COOKIE
Definition: blob.h:31
int buflen
Definition: blob.h:67
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blobmsg_type()

static int blobmsg_type ( const struct blob_attr attr)
inlinestatic

Definition at line 68 of file blobmsg.h.

69 {
70  return blob_id(attr);
71 }
Here is the call graph for this function:

◆ blobmsg_vprintf()

int blobmsg_vprintf ( struct blob_buf buf,
const char *  name,
const char *  format,
va_list  arg 
)
Here is the caller graph for this function:

Variable Documentation

◆ __attribute__

struct blobmsg_policy __attribute__

◆ name

uint8_t name[]

Definition at line 1 of file blobmsg.h.

◆ namelen

uint16_t namelen

Definition at line 0 of file blobmsg.h.