]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/ptm_lib.c
Merge pull request #13659 from donaldsharp/increase_mgmt_time
[mirror_frr.git] / lib / ptm_lib.c
index 69fd61e2a06998ea914551f4b02b3aeb71e43c24..ac800be0a5ef90fbffc2718fd09634ebcf0e6190 100644 (file)
@@ -1,22 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* PTM Library
  * Copyright (C) 2015 Cumulus Networks, Inc.
- *
- * This file is part of Quagga.
- *
- * Quagga is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * Quagga is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * 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 +50,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,
@@ -87,47 +77,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,
@@ -138,7 +128,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;
        }
 
@@ -149,7 +139,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;
        }
 
@@ -157,7 +147,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;
        }
 
@@ -181,7 +171,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;
        }
 
@@ -189,7 +179,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;
@@ -197,7 +187,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;
@@ -229,7 +219,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;
        }
 
@@ -249,7 +239,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;
        }
 
@@ -263,7 +253,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);
@@ -359,7 +349,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,
@@ -385,14 +375,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);
 
@@ -420,8 +410,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;