]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/ptm_lib.c
Merge pull request #7220 from idryzhov/fix-clear-isis
[mirror_frr.git] / lib / ptm_lib.c
index 7f868beda419048aef5a788c7e05af2c59b9919d..e00dd54290571b05f77b0192de2ff44fe1cb6189 100644 (file)
@@ -65,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, "%4d", msglen);
-       sprintf(vers_buf, "%4d", version);
-       sprintf(type_buf, "%4d", type);
-       sprintf(cmdid_buf, "%4d", cmd_id);
+       snprintf(msglen_buf, sizeof(msglen_buf), "%4d", msglen);
+       snprintf(vers_buf, sizeof(vers_buf), "%4d", version);
+       snprintf(type_buf, sizeof(type_buf), "%4d", type);
+       snprintf(cmdid_buf, sizeof(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,
@@ -92,47 +92,47 @@ static int _ptm_lib_decode_header(csv_t *csv, int *msglen, int *version,
        rec = csv_record_iter(csv);
        if (rec == NULL) {
                DLOG("malformed CSV\n");
-               return (-1);
+               return -1;
        }
        hdr = csv_field_iter(rec, &fld);
        if (hdr == NULL) {
                DLOG("malformed CSV\n");
-               return (-1);
+               return -1;
        }
        *msglen = atoi(hdr);
        hdr = csv_field_iter_next(&fld);
        if (hdr == NULL) {
                DLOG("malformed CSV\n");
-               return (-1);
+               return -1;
        }
        *version = atoi(hdr);
        hdr = csv_field_iter_next(&fld);
        if (hdr == NULL) {
                DLOG("malformed CSV\n");
-               return (-1);
+               return -1;
        }
        *type = atoi(hdr);
        hdr = csv_field_iter_next(&fld);
        if (hdr == NULL) {
                DLOG("malformed CSV\n");
-               return (-1);
+               return -1;
        }
        *cmd_id = atoi(hdr);
        hdr = csv_field_iter_next(&fld);
        if (hdr == NULL) {
                DLOG("malformed CSV\n");
-               return (-1);
+               return -1;
        }
        /* remove leading spaces */
        for (i = j = 0; i < csv_field_len(fld); i++) {
-               if (!isspace((int)hdr[i])) {
+               if (!isspace((unsigned char)hdr[i])) {
                        client_name[j] = hdr[i];
                        j++;
                }
        }
        client_name[j] = '\0';
 
-       return (0);
+       return 0;
 }
 
 int ptm_lib_append_msg(ptm_lib_handle_t *hdl, void *ctxt, const char *key,
@@ -143,7 +143,7 @@ int ptm_lib_append_msg(ptm_lib_handle_t *hdl, void *ctxt, const char *key,
        csv_record_t *mh_rec, *rec;
 
        if (!p_ctxt) {
-               ERRLOG("%s: no context \n", __FUNCTION__);
+               ERRLOG("%s: no context \n", __func__);
                return -1;
        }
 
@@ -154,7 +154,7 @@ int ptm_lib_append_msg(ptm_lib_handle_t *hdl, void *ctxt, const char *key,
        /* append to the hdr record */
        rec = csv_append_record(csv, rec, 1, key);
        if (!rec) {
-               ERRLOG("%s: Could not append key \n", __FUNCTION__);
+               ERRLOG("%s: Could not append key \n", __func__);
                return -1;
        }
 
@@ -162,7 +162,7 @@ int ptm_lib_append_msg(ptm_lib_handle_t *hdl, void *ctxt, const char *key,
        /* append to the data record */
        rec = csv_append_record(csv, rec, 1, val);
        if (!rec) {
-               ERRLOG("%s: Could not append val \n", __FUNCTION__);
+               ERRLOG("%s: Could not append val \n", __func__);
                return -1;
        }
 
@@ -186,7 +186,7 @@ int ptm_lib_init_msg(ptm_lib_handle_t *hdl, int cmd_id, int type, void *in_ctxt,
        csv = csv_init(NULL, NULL, PTMLIB_MSG_SZ);
 
        if (!csv) {
-               ERRLOG("%s: Could not allocate csv \n", __FUNCTION__);
+               ERRLOG("%s: Could not allocate csv \n", __func__);
                return -1;
        }
 
@@ -194,7 +194,7 @@ int ptm_lib_init_msg(ptm_lib_handle_t *hdl, int cmd_id, int type, void *in_ctxt,
                                     cmd_id, hdl->client_name);
 
        if (!rec) {
-               ERRLOG("%s: Could not allocate record \n", __FUNCTION__);
+               ERRLOG("%s: Could not allocate record \n", __func__);
                csv_clean(csv);
                csv_free(csv);
                return -1;
@@ -202,7 +202,7 @@ int ptm_lib_init_msg(ptm_lib_handle_t *hdl, int cmd_id, int type, void *in_ctxt,
 
        p_ctxt = calloc(1, sizeof(*p_ctxt));
        if (!p_ctxt) {
-               ERRLOG("%s: Could not allocate context \n", __FUNCTION__);
+               ERRLOG("%s: Could not allocate context \n", __func__);
                csv_clean(csv);
                csv_free(csv);
                return -1;
@@ -234,7 +234,7 @@ int ptm_lib_cleanup_msg(ptm_lib_handle_t *hdl, void *ctxt)
        csv_t *csv;
 
        if (!p_ctxt) {
-               ERRLOG("%s: no context \n", __FUNCTION__);
+               ERRLOG("%s: no context \n", __func__);
                return -1;
        }
 
@@ -254,7 +254,7 @@ int ptm_lib_complete_msg(ptm_lib_handle_t *hdl, void *ctxt, char *buf, int *len)
        csv_record_t *rec;
 
        if (!p_ctxt) {
-               ERRLOG("%s: no context \n", __FUNCTION__);
+               ERRLOG("%s: no context \n", __func__);
                return -1;
        }
 
@@ -268,7 +268,7 @@ int ptm_lib_complete_msg(ptm_lib_handle_t *hdl, void *ctxt, char *buf, int *len)
        /* parse csv contents into string */
        if (buf && len) {
                if (csv_serialize(csv, buf, *len)) {
-                       ERRLOG("%s: cannot serialize\n", __FUNCTION__);
+                       ERRLOG("%s: cannot serialize\n", __func__);
                        return -1;
                }
                *len = csvlen(csv);
@@ -364,7 +364,7 @@ int ptm_lib_process_msg(ptm_lib_handle_t *hdl, int fd, char *inbuf, int inlen,
 
        if (!csv) {
                DLOG("Cannot allocate csv for hdr\n");
-               return (-1);
+               return -1;
        }
 
        rc = _ptm_lib_decode_header(csv, &msglen, &ver, &type, &cmd_id,
@@ -390,14 +390,14 @@ int ptm_lib_process_msg(ptm_lib_handle_t *hdl, int fd, char *inbuf, int inlen,
                /* we only support the get-status cmd */
                if (strcmp(inbuf, PTMLIB_CMD_GET_STATUS)) {
                        DLOG("unsupported legacy cmd %s\n", inbuf);
-                       return (-1);
+                       return -1;
                }
                /* internally create a csv-style cmd */
                ptm_lib_init_msg(hdl, 0, PTMLIB_MSG_TYPE_CMD, NULL,
                                 (void *)&p_ctxt);
                if (!p_ctxt) {
                        DLOG("couldnt allocate context\n");
-                       return (-1);
+                       return -1;
                }
                ptm_lib_append_msg(hdl, p_ctxt, "cmd", PTMLIB_CMD_GET_STATUS);
 
@@ -425,8 +425,7 @@ int ptm_lib_process_msg(ptm_lib_handle_t *hdl, int fd, char *inbuf, int inlen,
                csv_decode(csv, inbuf);
                p_ctxt = calloc(1, sizeof(*p_ctxt));
                if (!p_ctxt) {
-                       ERRLOG("%s: Could not allocate context \n",
-                              __FUNCTION__);
+                       ERRLOG("%s: Could not allocate context \n", __func__);
                        csv_clean(csv);
                        csv_free(csv);
                        return -1;