]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/BsdSocketLib/ns_parse.c
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / StdLib / BsdSocketLib / ns_parse.c
diff --git a/StdLib/BsdSocketLib/ns_parse.c b/StdLib/BsdSocketLib/ns_parse.c
deleted file mode 100644 (file)
index 40ae79e..0000000
+++ /dev/null
@@ -1,232 +0,0 @@
-/** @file\r
-  Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials are licensed and made available under\r
-  the terms and conditions of the BSD License that accompanies this distribution.\r
-  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php.\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
- * Portions copyright (c) 1999, 2000\r
- * Intel Corporation.\r
- * All rights reserved.\r
- * \r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * \r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer.\r
- * \r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the\r
- *    documentation and/or other materials provided with the distribution.\r
- * \r
- * 3. All advertising materials mentioning features or use of this software\r
- *    must display the following acknowledgement:\r
- * \r
- *    This product includes software developed by Intel Corporation and\r
- *    its contributors.\r
- * \r
- * 4. Neither the name of Intel Corporation or its contributors may be\r
- *    used to endorse or promote products derived from this software\r
- *    without specific prior written permission.\r
- * \r
- * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''\r
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- * ARE DISCLAIMED.  IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE\r
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\r
- * THE POSSIBILITY OF SUCH DAMAGE.\r
- * \r
- * Copyright (c) 1996 by Internet Software Consortium.\r
- *\r
- * Permission to use, copy, modify, and distribute this software for any\r
- * purpose with or without fee is hereby granted, provided that the above\r
- * copyright notice and this permission notice appear in all copies.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS\r
- * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE\r
- * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
- * SOFTWARE.\r
-**/\r
-\r
-#include <sys/types.h>\r
-\r
-#include <netinet/in.h>\r
-#include <arpa/nameser.h>\r
-\r
-#include <errno.h>\r
-#include <resolv.h>\r
-#include <string.h>\r
-\r
-/* These need to be in the same order as the nres.h:ns_flag enum. */\r
-struct _ns_flagdata _ns_flagdata[16] = {\r
-       { 0x8000, 15 },         /* qr. */\r
-       { 0x7800, 11 },         /* opcode. */\r
-       { 0x0400, 10 },         /* aa. */\r
-       { 0x0200, 9 },          /* tc. */\r
-       { 0x0100, 8 },          /* rd. */\r
-       { 0x0080, 7 },          /* ra. */\r
-       { 0x0040, 6 },          /* z. */\r
-       { 0x0020, 5 },          /* ad. */\r
-       { 0x0010, 4 },          /* cd. */\r
-       { 0x000f, 0 },          /* rcode. */\r
-       { 0x0000, 0 },          /* expansion (1/6). */\r
-       { 0x0000, 0 },          /* expansion (2/6). */\r
-       { 0x0000, 0 },          /* expansion (3/6). */\r
-       { 0x0000, 0 },          /* expansion (4/6). */\r
-       { 0x0000, 0 },          /* expansion (5/6). */\r
-       { 0x0000, 0 },          /* expansion (6/6). */\r
-};\r
-\r
-static int\r
-skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {\r
-       const u_char *optr = ptr;\r
-\r
-       for ((void)NULL; count > 0; count--) {\r
-               int b, rdlength;\r
-\r
-               b = dn_skipname(ptr, eom);\r
-               if (b < 0)\r
-                       goto emsgsize;\r
-               ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/;\r
-               if (section != ns_s_qd) {\r
-                       if (ptr + NS_INT32SZ > eom)\r
-                               goto emsgsize;\r
-                       ptr += NS_INT32SZ/*TTL*/;\r
-                       if (ptr + NS_INT16SZ > eom)\r
-                               goto emsgsize;\r
-                       NS_GET16(rdlength, ptr);\r
-                       ptr += rdlength/*RData*/;\r
-               }\r
-       }\r
-       if (ptr > eom)\r
-               goto emsgsize;\r
-       return ((int)(ptr - optr));\r
- emsgsize:\r
-       errno = EMSGSIZE;\r
-       return (-1);\r
-}\r
-\r
-int\r
-ns_initparse(const u_char *msg, int msglen, ns_msg *handle) {\r
-       const u_char *eom = msg + msglen;\r
-       int i;\r
-\r
-       memset(handle, 0x5e, sizeof *handle);\r
-       handle->_msg = msg;\r
-       handle->_eom = eom;\r
-       if (msg + NS_INT16SZ > eom)\r
-               goto emsgsize;\r
-       NS_GET16(handle->_id, msg);\r
-       if (msg + NS_INT16SZ > eom)\r
-               goto emsgsize;\r
-       NS_GET16(handle->_flags, msg);\r
-       for (i = 0; i < ns_s_max; i++) {\r
-               if (msg + NS_INT16SZ > eom)\r
-                       goto emsgsize;\r
-               NS_GET16(handle->_counts[i], msg);\r
-       }\r
-       for (i = 0; i < ns_s_max; i++)\r
-               if (handle->_counts[i] == 0)\r
-                       handle->_sections[i] = NULL;\r
-               else {\r
-                       int b = skiprr(msg, eom, (ns_sect)i,\r
-                                      handle->_counts[i]);\r
-\r
-                       if (b < 0)\r
-                               return (-1);\r
-                       handle->_sections[i] = msg;\r
-                       msg += b;\r
-               }\r
-       if (msg != eom)\r
-               goto emsgsize;\r
-       handle->_sect = ns_s_max;\r
-       handle->_rrnum = -1;\r
-       handle->_msg_ptr = NULL;\r
-       return (0);\r
- emsgsize:\r
-       errno = EMSGSIZE;\r
-       return (-1);\r
-}\r
-\r
-int\r
-ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {\r
-       int b;\r
-\r
-       /* Make section right. */\r
-       if ((unsigned int)section >= ns_s_max)\r
-               goto enodev;\r
-       if ((int)section != (int)handle->_sect) {\r
-               handle->_sect = section;\r
-               handle->_rrnum = 0;\r
-               handle->_msg_ptr = handle->_sections[(int)section];\r
-       }\r
-\r
-       /* Make rrnum right. */\r
-       if (rrnum == -1)\r
-               rrnum = handle->_rrnum;\r
-       if (rrnum < 0 || rrnum >= handle->_counts[(int)section])\r
-               goto enodev;\r
-       if (rrnum < handle->_rrnum) {\r
-               handle->_rrnum = 0;\r
-               handle->_msg_ptr = handle->_sections[(int)section];\r
-       }\r
-       \r
-       b = skiprr(handle->_msg, handle->_eom, section,\r
-                  rrnum - handle->_rrnum);\r
-       if (b < 0)\r
-               return (-1);\r
-       handle->_msg_ptr += b;\r
-       handle->_rrnum = rrnum;\r
-\r
-       /* Do the parse. */\r
-       b = dn_expand(handle->_msg, handle->_eom,\r
-                     handle->_msg_ptr, rr->name, NS_MAXDNAME);\r
-       if (b < 0)\r
-               return (-1);\r
-       handle->_msg_ptr += b;\r
-       if (handle->_msg_ptr + NS_INT16SZ > handle->_eom)\r
-               goto emsgsize;\r
-       NS_GET16(rr->type, handle->_msg_ptr);\r
-       if (handle->_msg_ptr + NS_INT16SZ > handle->_eom)\r
-               goto emsgsize;\r
-       NS_GET16(rr->rr_class, handle->_msg_ptr);\r
-       if (section == ns_s_qd) {\r
-               rr->ttl = 0;\r
-               rr->rdlength = 0;\r
-               rr->rdata = NULL;\r
-       } else {\r
-               if (handle->_msg_ptr + NS_INT32SZ > handle->_eom)\r
-                       goto emsgsize;\r
-               NS_GET32(rr->ttl, handle->_msg_ptr);\r
-               if (handle->_msg_ptr + NS_INT16SZ > handle->_eom)\r
-                       goto emsgsize;\r
-               NS_GET16(rr->rdlength, handle->_msg_ptr);\r
-               if (handle->_msg_ptr + rr->rdlength > handle->_eom)\r
-                       goto emsgsize;\r
-               rr->rdata = handle->_msg_ptr;\r
-               handle->_msg_ptr += rr->rdlength;\r
-       }\r
-       handle->_rrnum++;\r
-\r
-       /* All done. */\r
-       return (0);\r
- enodev:\r
-       errno = ENODEV;\r
-       return (-1);\r
- emsgsize:\r
-       errno = EMSGSIZE;\r
-       return (-1);\r
-}\r