examples: use SPDX tag for Intel copyright files
[dpdk.git] / examples / ipsec-secgw / parser.c
index 99bdfc5..2403b56 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2016 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2016 Intel Corporation
  */
 #include <rte_common.h>
 #include <rte_crypto.h>
@@ -248,7 +219,7 @@ parse_ipv4_addr(const char *token, struct in_addr *ipv4, uint32_t *mask)
                if (mask)
                        *mask = atoi(pch);
        } else {
-               strncpy(ip_str, token, sizeof(ip_str));
+               strncpy(ip_str, token, sizeof(ip_str) - 1);
                if (mask)
                        *mask = 0;
        }
@@ -277,7 +248,7 @@ parse_ipv6_addr(const char *token, struct in6_addr *ipv6, uint32_t *mask)
                if (mask)
                        *mask = atoi(pch);
        } else {
-               strncpy(ip_str, token, sizeof(ip_str));
+               strncpy(ip_str, token, sizeof(ip_str) - 1);
                if (mask)
                        *mask = 0;
        }
@@ -487,8 +458,7 @@ parse_cfg_file(const char *cfg_filename)
        struct parse_status status = {0};
 
        if (f == NULL) {
-               rte_panic("Error: invalid file descriptor %s\n",
-                       cfg_filename);
+               rte_panic("Error: invalid file descriptor %s\n", cfg_filename);
                goto error_exit;
        }
 
@@ -503,86 +473,79 @@ parse_cfg_file(const char *cfg_filename)
 
        do {
                char oneline[1024];
-
+               char *pos;
                get_s = fgets(oneline, 1024, f);
-               if (get_s) {
-                       char *pos;
 
-                       line_num++;
+               if (!get_s)
+                       break;
 
-                       if (strlen(oneline) > 1022) {
-                               rte_panic("%s:%u: error: the line "
-                                       "contains more characters the "
-                                       "parser can handle\n",
-                                       cfg_filename, line_num);
-                               goto error_exit;
-                       }
+               line_num++;
 
-                       /* process comment char '#' */
-                       if (oneline[0] == '#')
-                               continue;
+               if (strlen(oneline) > 1022) {
+                       rte_panic("%s:%u: error: "
+                               "the line contains more characters the parser can handle\n",
+                               cfg_filename, line_num);
+                       goto error_exit;
+               }
 
-                       pos = strchr(oneline, '#');
-                       if (pos != NULL)
-                               *pos = '\0';
-
-                       /* process line concatenator '\' */
-                       pos = strchr(oneline, 92);
-                       if (pos != NULL) {
-                               if (pos != oneline+strlen(oneline) - 2) {
-                                       rte_panic("%s:%u: error: no "
-                                               "character should exist "
-                                               "after '\\' symbol\n",
-                                               cfg_filename, line_num);
-                                       goto error_exit;
-                               }
-
-                               *pos = '\0';
-
-                               if (strlen(oneline) + strlen(str) > 1022) {
-                                       rte_panic("%s:%u: error: the "
-                                               "concatenated line "
-                                               "contains more characters "
-                                               "the parser can handle\n",
-                                               cfg_filename, line_num);
-                                       goto error_exit;
-                               }
-
-                               strncpy(str + strlen(str), oneline,
-                                       strlen(oneline));
+               /* process comment char '#' */
+               if (oneline[0] == '#')
+                       continue;
 
-                               continue;
+               pos = strchr(oneline, '#');
+               if (pos != NULL)
+                       *pos = '\0';
+
+               /* process line concatenator '\' */
+               pos = strchr(oneline, 92);
+               if (pos != NULL) {
+                       if (pos != oneline+strlen(oneline) - 2) {
+                               rte_panic("%s:%u: error: "
+                                       "no character should exist after '\\'\n",
+                                       cfg_filename, line_num);
+                               goto error_exit;
                        }
 
-                       /* copy the line to str and process */
+                       *pos = '\0';
+
                        if (strlen(oneline) + strlen(str) > 1022) {
-                               rte_panic("%s:%u: error: the line "
-                                       "contains more characters the "
-                                       "parser can handle\n",
+                               rte_panic("%s:%u: error: "
+                                       "the concatenated line contains more characters the parser can handle\n",
                                        cfg_filename, line_num);
                                goto error_exit;
                        }
+
                        strncpy(str + strlen(str), oneline,
                                strlen(oneline));
 
-                       str[strlen(str)] = '\n';
-                       if (cmdline_parse(cl, str) < 0) {
-                               rte_panic("%s:%u: error: parsing \"%s\" "
-                                       "failed\n", cfg_filename,
-                                       line_num, str);
-                               goto error_exit;
-                       }
+                       continue;
+               }
 
-                       if (status.status < 0) {
-                               rte_panic("%s:%u: error: %s",
-                                       cfg_filename, line_num,
-                                       status.parse_msg);
-                               goto error_exit;
-                       }
+               /* copy the line to str and process */
+               if (strlen(oneline) + strlen(str) > 1022) {
+                       rte_panic("%s:%u: error: "
+                               "the line contains more characters the parser can handle\n",
+                               cfg_filename, line_num);
+                       goto error_exit;
+               }
+               strncpy(str + strlen(str), oneline,
+                       strlen(oneline));
+
+               str[strlen(str)] = '\n';
+               if (cmdline_parse(cl, str) < 0) {
+                       rte_panic("%s:%u: error: parsing \"%s\" failed\n",
+                               cfg_filename, line_num, str);
+                       goto error_exit;
+               }
 
-                       memset(str, 0, 1024);
+               if (status.status < 0) {
+                       rte_panic("%s:%u: error: %s", cfg_filename,
+                               line_num, status.parse_msg);
+                       goto error_exit;
                }
-       } while (get_s != NULL);
+
+               memset(str, 0, 1024);
+       } while (1);
 
        cmdline_stdin_exit(cl);
        fclose(f);