util.h revision 04bdb234571448ed6194e1d4048e6512f2446f1c
63b0524b961b6dce1aa18488d7175ca4ee17778fTinderbox User/* $Id: util.h,v 1.2 2000/11/14 00:15:35 ishisone Exp $ */
7bd455641455950eff7d21be652c8142b134d32fTinderbox User/*
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * Copyright (c) 2000 Japan Network Information Center. All rights reserved.
7bd455641455950eff7d21be652c8142b134d32fTinderbox User *
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * By using this file, you agree to the terms and conditions set forth bellow.
7bd455641455950eff7d21be652c8142b134d32fTinderbox User *
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * LICENSE TERMS AND CONDITIONS
7bd455641455950eff7d21be652c8142b134d32fTinderbox User *
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * The following License Terms and Conditions apply, unless a different
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * license is obtained from Japan Network Information Center ("JPNIC"),
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * a Japanese association, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * Tokyo, Japan.
7bd455641455950eff7d21be652c8142b134d32fTinderbox User *
7bd455641455950eff7d21be652c8142b134d32fTinderbox User * 1. Use, Modification and Redistribution (including distribution of any
8cbf3b6fc35091abde426930f2eadb8f53476c98Evan Hunt * modified or derived work) in source and/or binary forms is permitted
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * under this License Terms and Conditions.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * 2. Redistribution of source code must retain the copyright notices as they
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * appear in each source code file, this License Terms and Conditions.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * 3. Redistribution in binary form must reproduce the Copyright Notice,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * this License Terms and Conditions, in the documentation and/or other
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * materials provided with the distribution. For the purposes of binary
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * distribution the "Copyright Notice" refers to the following language:
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * "Copyright (c) Japan Network Information Center. All rights reserved."
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * 4. Neither the name of JPNIC may be used to endorse or promote products
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * derived from this Software without specific prior written approval of
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence * JPNIC.
866d106459313499d0ca7bfccb4b2d23d5e4377cDavid Lawrence *
74cb99072c4b0ebd2ccafcfa284288fa760f7a1aMark Andrews * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
bff64bf12b58a6f80e740e94f2e42a32df18113aEvan Hunt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
866d106459313499d0ca7bfccb4b2d23d5e4377cDavid Lawrence * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
7c74e180c206e6ed99e8beb820da5f399d845c3eDavid Lawrence * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
92b796c963e7ba0217debfa27a0709f94934f5d5Mark Andrews * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
03e200df5dc283f24a6a349f0b31d3eab26da893Mark Andrews * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
63dd46733010bb9622810faa17d88c3e3c28b730Mark Andrews * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley *
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff * 6. Indemnification by Licensee
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * Any person or entities using and/or redistributing this Software under
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * this License Terms and Conditions shall defend indemnify and hold
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * harmless JPNIC from and against any and all judgements damages,
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * expenses, settlement liabilities, cost and other liabilities of any
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * kind as a result of use and redistribution of this Software or any
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * claim, suite, action, litigation or proceeding by any third party
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * arising out of or relates to this License Terms and Conditions.
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews *
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * 7. Governing Law, Jurisdiction and Venue
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * This License Terms and Conditions shall be governed by and and
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * construed in accordance with the law of Japan. Any person or entities
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * using and/or redistributing this Software under this License Terms and
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * Conditions hereby agrees and consent to the personal and exclusive
914eeb33149a0008e26741d9e7d89dcd6f8b6d0bMark Andrews * jurisdiction and venue of Tokyo District Court of Japan.
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff */
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff#ifndef MDN_UTIL_H
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff#define MDN_UTIL_H 1
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff/*
3d776d762914d1b675b4fd49728ce353ccf6f77eBrian Wellington * Utility functions.
5b7abbef511cea0b568be0bc8d5b3120a0b9034dEvan Hunt */
6b66ee9147e940572a0e873ecbd67456ccb85c39Mark Andrews
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff/*
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * Case-insensitive string match.
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews *
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * This function compares two strings in case-insensitive way, like
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * strcasencmp() function which can be found in many systems.
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * However, this function only disregards the case difference of ASCII
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * letters ([A-Za-z]), so it is locale independent.
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * The result is 1 if 's1' and 's2' match, 0 otherwise.
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews */
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrewsextern int
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrewsmdn_util_casematch(const char *s1, const char *s2, size_t n);
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews/*
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt * Get a range of valid domain name characters.
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt *
1c1290afabb3c8f4dd498170ac9592e5be450161Mark Andrews * This function sees each character in string 's' until 'end',
1c1290afabb3c8f4dd498170ac9592e5be450161Mark Andrews * and checks if it is valid as a character in ASCII domain names.
b123b265e3a3d9b72a14230b6517e0f6fdb5c5b5Mark Andrews * It returns a pointer to the first invalid character, or 'end'
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews * if all characters are valid.
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews */
740e7340c55e9f0cf80c6fbbf7e8d3c1bdeaa255Mark Andrewsextern const char *
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrewsmdn_util_domainspan(const char *s, const char *end);
84f95ddb2572641022619950a211aff49e331c98Mukund Sivaraman
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews/*
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews * UTF-8 to UTF-16 conversion and vice versa.
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews */
71697fd082b1c76562dc80fa91787af3860146bfEvan Huntextern mdn_result_t
1c1290afabb3c8f4dd498170ac9592e5be450161Mark Andrewsmdn_util_utf8toutf16(const char *utf8, size_t fromlen,
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt unsigned short *utf16, size_t tolen, size_t *reslenp);
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrewsextern mdn_result_t
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntmdn_util_utf16toutf8(const unsigned short *utf16, size_t fromlen,
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt char *utf8, size_t tolen, size_t *reslenp);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
1831311ac6179951c8fcca75aa29dc2f5c0218b9Francis Dupont#endif /* MDN_UTIL_H */
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt