]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/ptm_lib.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / ptm_lib.c
index f50d1e2989a381cc4bb253c1bf7f1beda0fb1310..7f868beda419048aef5a788c7e05af2c59b9919d 100644 (file)
  * with this program; see the file COPYING; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdbool.h>
@@ -60,10 +65,10 @@ static csv_record_t *_ptm_lib_encode_header(csv_t *csv, csv_record_t *rec,
        char client_buf[32];
        csv_record_t *rec1;
 
-       sprintf(msglen_buf, "%4u", msglen);
-       sprintf(vers_buf, "%4u", version);
-       sprintf(type_buf, "%4u", type);
-       sprintf(cmdid_buf, "%4u", cmd_id);
+       sprintf(msglen_buf, "%4d", msglen);
+       sprintf(vers_buf, "%4d", version);
+       sprintf(type_buf, "%4d", type);
+       sprintf(cmdid_buf, "%4d", cmd_id);
        snprintf(client_buf, 17, "%16.16s", client_name);
        if (rec) {
                rec1 = csv_encode_record(csv, rec, 5, msglen_buf, vers_buf,
@@ -120,7 +125,7 @@ static int _ptm_lib_decode_header(csv_t *csv, int *msglen, int *version,
        }
        /* remove leading spaces */
        for (i = j = 0; i < csv_field_len(fld); i++) {
-               if (!isspace(hdr[i])) {
+               if (!isspace((int)hdr[i])) {
                        client_name[j] = hdr[i];
                        j++;
                }
@@ -223,6 +228,25 @@ int ptm_lib_init_msg(ptm_lib_handle_t *hdl, int cmd_id, int type, void *in_ctxt,
        return 0;
 }
 
+int ptm_lib_cleanup_msg(ptm_lib_handle_t *hdl, void *ctxt)
+{
+       ptm_lib_msg_ctxt_t *p_ctxt = ctxt;
+       csv_t *csv;
+
+       if (!p_ctxt) {
+               ERRLOG("%s: no context \n", __FUNCTION__);
+               return -1;
+       }
+
+       csv = p_ctxt->csv;
+
+       csv_clean(csv);
+       csv_free(csv);
+       free(p_ctxt);
+
+       return 0;
+}
+
 int ptm_lib_complete_msg(ptm_lib_handle_t *hdl, void *ctxt, char *buf, int *len)
 {
        ptm_lib_msg_ctxt_t *p_ctxt = ctxt;
@@ -328,9 +352,9 @@ int ptm_lib_process_msg(ptm_lib_handle_t *hdl, int fd, char *inbuf, int inlen,
 {
        int rc, len;
        char client_name[32];
-       int cmd_id, type, ver, msglen;
+       int cmd_id = 0, type = 0, ver = 0, msglen = 0;
        csv_t *csv;
-       ptm_lib_msg_ctxt_t *p_ctxt;
+       ptm_lib_msg_ctxt_t *p_ctxt = NULL;
 
        len = _ptm_lib_read_ptm_socket(fd, inbuf, PTMLIB_MSG_HDR_LEN);
        if (len <= 0)