int i;
cJSON *array = cJSON_GetObjectItem(o, "{n}");
int size = cJSON_GetArraySize(array);
- if (size != {lfield}) return 0;
+ if (size != {lfield}) goto error;
for (i = 0; i < size; i++) {{
cJSON *e = cJSON_GetArrayItem(array, i);
{call}
if o.lengthfield:
write(' s = u8string_fromjson(o, "{}");\n'
.format(o.fieldname))
- write(' if (!s) return 0;\n')
+ write(' if (!s) goto error;\n')
write(' {} = vec_len(s);\n'.format(lfield))
write(' {realloc} = realloc({realloc}, {msgsize} + '
write(' vec_free(s);\n')
else:
- write(' u8string_fromjson2(o, "{n}", a->{n});\n'
+ write(' if (u8string_fromjson2(o, "{n}", a->{n}) < 0) goto error;\n'
.format(n=o.fieldname))
return
call = ('vl_api_{t}_fromjson(e, &d[i]);'
.format(t=o.fieldtype))
else:
- call = ('{t}_fromjson({msgvar}, len, e, &d[i]); '
+ call = ('if ({t}_fromjson({msgvar}, len, e, &d[i]) < 0) goto error; '
.format(t=o.fieldtype, msgvar=msgvar))
write(forloop_vla.format(lfield=lfield,
t=o.fieldtype,
def print_define(self, o):
'''Convert JSON object to VPP API message'''
write = self.stream.write
+ error = 0
write('static inline vl_api_{name}_t *vl_api_{name}_t_fromjson '
'(cJSON *o, int *len) {{\n'.format(name=o.name))
write(' cJSON *item __attribute__ ((unused));\n')
write(' item = cJSON_GetObjectItem(o, "{}");\n'
.format(t.fieldname))
write(' if (!item) goto error;\n')
+ error += 1
self._dispatch[t.type](self, t, toplevel=True)
write('\n')
write(' *len = l;\n')
write(' return a;\n')
- write('\n error:\n')
- write(' free(a);\n')
- write(' return 0;\n')
+
+ if error:
+ write('\n error:\n')
+ write(' free(a);\n')
+ write(' return 0;\n')
write('}\n')
def print_using(self, o):
write(' {}_N_ERROR\n'.format(csetname.upper()))
write('}} vl_counter_{}_enum_t;\n'.format(csetname))
- write('extern vl_counter_t {}_error_counters[];\n'.format(csetname))
+ write('extern vlib_error_desc_t {}_error_counters[];\n'.format(csetname))
def generate_include_types(s, module, stream):
' .cleanup = vl_noop_handler,\n'
' .endian = vl_api_{n}_t_endian,\n'
' .print = vl_api_{n}_t_print,\n'
+ ' .traced = 1,\n'
+ ' .replay = 1,\n'
' .is_autoendian = {auto}}};\n'
.format(n=s.caller, ID=s.caller.upper(),
auto=d.autoendian))
for cnt in counters:
csetname = cnt.name
- write('vl_counter_t {}_error_counters[] = {{\n'.format(csetname))
+ write('vlib_error_desc_t {}_error_counters[] = {{\n'.format(csetname))
for c in cnt.block:
write(' {\n')
write(' .name = "{}",\n'.format(c['name']))
.format(n=e, ID=e.upper()))
write('}\n')
- if plugin:
- write('clib_error_t * vat_plugin_register (vat_main_t *vam)\n')
- else:
- write('clib_error_t * vat_{}_plugin_register (vat_main_t *vam)\n'
- .format(module))
+ write('clib_error_t * vat_plugin_register (vat_main_t *vam)\n')
write('{\n')
write(' {n}_test_main_t * mainp = &{n}_test_main;\n'.format(n=module))
write(' mainp->vat_main = vam;\n')
char *p;
int l;
vac_read(&p, &l, 5); // XXX: Fix timeout
+ if (p == 0 || l == 0) return 0;
// XXX Will fail in case of event received. Do loop
if (ntohs(*((u16 *)p)) != vac_get_msg_index(VL_API_{R}_CRC)) {{
fprintf(stderr, "Mismatched reply\\n");
char *p;
int l;
vac_read(&p, &l, 5); // XXX: Fix timeout
+ if (p == 0 || l == 0) {{
+ cJSON_free(reply);
+ return 0;
+ }}
/* Message can be one of [_details, control_ping_reply
* or unrelated event]
}}
if (reply_msg_id == details_msg_id) {{
+ if (l < sizeof(vl_api_{r}_t)) {{
+ cJSON_free(reply);
+ return 0;
+ }}
vl_api_{r}_t *rmp = (vl_api_{r}_t *)p;
vl_api_{r}_t_endian(rmp);
cJSON_AddItemToArray(reply, vl_api_{r}_t_tojson(rmp));
#include <vnet/ethernet/ethernet_format_fns.h>
#define vl_typedefs /* define message structures */
-#include <vpp/api/vpe_all_api_h.h>
+#include <vlibmemory/vl_memory_api_h.h>
+#include <vpp/api/vpe_types.api.h>
+#include <vpp/api/vpe.api.h>
#undef vl_typedefs
#include "{module}.api_enum.h"
continue
c_test_api_service(s, s.stream, stream)
- write('void vat2_register_function(char *, cJSON * (*)(cJSON *));\n')
+ write('void vat2_register_function(char *, cJSON * (*)(cJSON *), cJSON * (*)(void *));\n')
# write('__attribute__((constructor))')
write('clib_error_t *\n')
write('vat2_register_plugin (void) {\n')
for s in services:
- write(' vat2_register_function("{n}", api_{n});\n'
+ write(' vat2_register_function("{n}", api_{n}, (cJSON * (*)(void *))vl_api_{n}_t_tojson);\n'
.format(n=s.caller))
write(' return 0;\n')
write('}\n')