api: clean up error message
[vpp.git] / src / vlibapi / api_shared.c
index 73ef3ce..d2f1759 100644 (file)
@@ -531,10 +531,7 @@ msg_handler_internal (api_main_t *am, void *the_msg, uword msg_len,
       if (am->msg_print_flag)
        {
          fformat (stdout, "[%d]: %s\n", id, m->name);
-         if (m->print_handler)
-           m->print_handler (the_msg, stdout);
-         else
-           fformat (stdout, "  [no registered print fn]\n");
+         fformat (stdout, "%U", format_vl_api_msg_text, am, id, the_msg);
        }
 
       uword calc_size = 0;
@@ -769,8 +766,7 @@ vl_msg_api_config (vl_msg_api_msg_config_t * c)
   m->handler = c->handler;
   m->cleanup_handler = c->cleanup;
   m->endian_handler = c->endian;
-  m->print_handler = c->print;
-  m->print_json_handler = c->print_json;
+  m->format_fn = c->format_fn;
   m->tojson_handler = c->tojson;
   m->fromjson_handler = c->fromjson;
   m->calc_size_func = c->calc_size;
@@ -788,39 +784,6 @@ vl_msg_api_config (vl_msg_api_msg_config_t * c)
   hash_set_mem (am->msg_id_by_name, c->name, c->id);
 }
 
-/*
- * vl_msg_api_set_handlers
- * preserve the old API for a while
- */
-void
-vl_msg_api_set_handlers (int id, char *name, void *handler, void *cleanup,
-                        void *endian, void *print, int size, int traced,
-                        void *print_json, void *tojson, void *fromjson,
-                        void *calc_size)
-{
-  vl_msg_api_msg_config_t cfg;
-  vl_msg_api_msg_config_t *c = &cfg;
-
-  clib_memset (c, 0, sizeof (*c));
-
-  c->id = id;
-  c->name = name;
-  c->handler = handler;
-  c->cleanup = cleanup;
-  c->endian = endian;
-  c->print = print;
-  c->traced = traced;
-  c->replay = 1;
-  c->message_bounce = 0;
-  c->is_mp_safe = 0;
-  c->is_autoendian = 0;
-  c->tojson = tojson;
-  c->fromjson = fromjson;
-  c->print_json = print_json;
-  c->calc_size = calc_size;
-  vl_msg_api_config (c);
-}
-
 void
 vl_msg_api_clean_handlers (int msg_id)
 {
@@ -850,6 +813,7 @@ vl_msg_api_queue_handler (svm_queue_t * q)
 
   while (!svm_queue_sub (q, (u8 *) &msg, SVM_Q_WAIT, 0))
     {
+      VL_MSG_API_UNPOISON ((u8 *) msg);
       msgbuf_t *msgbuf = (msgbuf_t *) ((u8 *) msg - offsetof (msgbuf_t, data));
       vl_msg_api_handler ((void *) msg, ntohl (msgbuf->data_len));
     }
@@ -884,12 +848,6 @@ vl_msg_api_trace_get (api_main_t * am, vl_api_trace_which_t which)
     }
 }
 
-void
-vl_noop_handler (void *mp)
-{
-}
-
-
 static u8 post_mortem_dump_enabled;
 
 void
@@ -1102,8 +1060,9 @@ vl_api_from_api_to_new_vec (void *mp, vl_api_string_t * astr)
   u8 *v = 0;
 
   if (vl_msg_api_max_length (mp) < clib_net_to_host_u32 (astr->length))
-    return format (0, "insane astr->length %u%c",
-                  clib_net_to_host_u32 (astr->length), 0);
+    return format (0, "Invalid astr->length %u > max (%u)%c",
+                  clib_net_to_host_u32 (astr->length),
+                  vl_msg_api_max_length (mp), 0);
   vec_add (v, astr->buf, clib_net_to_host_u32 (astr->length));
   return v;
 }