resconf.c revision 04bdb234571448ed6194e1d4048e6512f2446f1c
9eb24f1f84885d5c2e51a7f675264db398c31af7Tinderbox User#ifndef lint
7bd455641455950eff7d21be652c8142b134d32fTinderbox Userstatic char *rcsid = "$Id: resconf.c,v 1.4 2000/09/20 02:47:32 ishisone Exp $";
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#endif
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews/*
8cbf3b6fc35091abde426930f2eadb8f53476c98Evan Hunt * Copyright (c) 2000 Japan Network Information Center. All rights reserved.
866d106459313499d0ca7bfccb4b2d23d5e4377cDavid Lawrence *
74cb99072c4b0ebd2ccafcfa284288fa760f7a1aMark Andrews * By using this file, you agree to the terms and conditions set forth bellow.
bff64bf12b58a6f80e740e94f2e42a32df18113aEvan Hunt *
866d106459313499d0ca7bfccb4b2d23d5e4377cDavid Lawrence * LICENSE TERMS AND CONDITIONS
7c74e180c206e6ed99e8beb820da5f399d845c3eDavid Lawrence *
92b796c963e7ba0217debfa27a0709f94934f5d5Mark Andrews * The following License Terms and Conditions apply, unless a different
03e200df5dc283f24a6a349f0b31d3eab26da893Mark Andrews * license is obtained from Japan Network Information Center ("JPNIC"),
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * a Japanese association, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * Tokyo, Japan.
63dd46733010bb9622810faa17d88c3e3c28b730Mark Andrews *
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * 1. Use, Modification and Redistribution (including distribution of any
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * modified or derived work) in source and/or binary forms is permitted
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley * under this License Terms and Conditions.
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff *
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * 2. Redistribution of source code must retain the copyright notices as they
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * appear in each source code file, this License Terms and Conditions.
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews *
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * 3. Redistribution in binary form must reproduce the Copyright Notice,
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * this License Terms and Conditions, in the documentation and/or other
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * materials provided with the distribution. For the purposes of binary
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * distribution the "Copyright Notice" refers to the following language:
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * "Copyright (c) Japan Network Information Center. All rights reserved."
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews *
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * 4. Neither the name of JPNIC may be used to endorse or promote products
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * derived from this Software without specific prior written approval of
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews * JPNIC.
f4ea363e3acc321b24ffe95a64a583e8041d6fd5Mark Andrews *
914eeb33149a0008e26741d9e7d89dcd6f8b6d0bMark Andrews * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
3d776d762914d1b675b4fd49728ce353ccf6f77eBrian Wellington * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
5b7abbef511cea0b568be0bc8d5b3120a0b9034dEvan Hunt * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
6b66ee9147e940572a0e873ecbd67456ccb85c39Mark Andrews * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ccdac53c027e8964753b36c4d8c7b0e98af501c2Michael Graff * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews *
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews * 6. Indemnification by Licensee
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * Any person or entities using and/or redistributing this Software under
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * this License Terms and Conditions shall defend indemnify and hold
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * harmless JPNIC from and against any and all judgements damages,
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * expenses, settlement liabilities, cost and other liabilities of any
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * kind as a result of use and redistribution of this Software or any
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * claim, suite, action, litigation or proceeding by any third party
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * arising out of or relates to this License Terms and Conditions.
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews *
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * 7. Governing Law, Jurisdiction and Venue
11dbf2fc38eea8c5d3fe7123718bf197a8bb2e6bMark Andrews * This License Terms and Conditions shall be governed by and and
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews * construed in accordance with the law of Japan. Any person or entities
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews * using and/or redistributing this Software under this License Terms and
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews * Conditions hereby agrees and consent to the personal and exclusive
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt * jurisdiction and venue of Tokyo District Court of Japan.
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews */
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews#include <config.h>
1c1290afabb3c8f4dd498170ac9592e5be450161Mark Andrews
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews#include <stddef.h>
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews#include <stdarg.h>
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews#include <stdlib.h>
800cfc8a5ce9ffacfc076003b34b5f787f82c701Mark Andrews#include <stdio.h>
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews#include <string.h>
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews#include <ctype.h>
740e7340c55e9f0cf80c6fbbf7e8d3c1bdeaa255Mark Andrews#include <errno.h>
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews
84f95ddb2572641022619950a211aff49e331c98Mukund Sivaraman#include <mdn/result.h>
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews#include <mdn/assert.h>
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews#include <mdn/logmacro.h>
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews#include <mdn/converter.h>
71697fd082b1c76562dc80fa91787af3860146bfEvan Hunt#include <mdn/normalizer.h>
1c1290afabb3c8f4dd498170ac9592e5be450161Mark Andrews#include <mdn/translator.h>
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt#include <mdn/localencoding.h>
a97185d9e01800850222878c2af93ea5cb08a68cMark Andrews#include <mdn/resconf.h>
800cfc8a5ce9ffacfc076003b34b5f787f82c701Mark Andrews#include <mdn/debug.h>
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews
32ebb157b1d9409a186c86002827f8a1f4931f5aMark Andrews#ifndef MDN_RESCONF_DIR
800cfc8a5ce9ffacfc076003b34b5f787f82c701Mark Andrews#define MDN_RESCONF_DIR "/etc"
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt#endif
19d80ce5844e00a021643759adcbe27c11b485a0Witold Krecicki#define MDN_RESCONF_FILE MDN_RESCONF_DIR "/mdnres.conf"
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrewsstruct mdn_resconf {
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews char *local_encoding;
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews mdn_converter_t local_converter;
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews mdn_converter_t alternate_converter;
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews mdn_converter_t server_converter;
19d80ce5844e00a021643759adcbe27c11b485a0Witold Krecicki mdn_normalizer_t normalizer;
19d80ce5844e00a021643759adcbe27c11b485a0Witold Krecicki char *zld;
19d80ce5844e00a021643759adcbe27c11b485a0Witold Krecicki int edns0;
19d80ce5844e00a021643759adcbe27c11b485a0Witold Krecicki};
19d80ce5844e00a021643759adcbe27c11b485a0Witold Krecicki
19d80ce5844e00a021643759adcbe27c11b485a0Witold Krecickistatic mdn_result_t parse_conf(mdn_resconf_t ctx, FILE *fp);
8bcd80824c51c802c2927236b012cd526f569b04Mark Andrewsstatic mdn_result_t parse_normalize(mdn_resconf_t ctx, int argc,
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt char **argv);
8bcd80824c51c802c2927236b012cd526f569b04Mark Andrewsstatic mdn_result_t parse_alias_file(mdn_resconf_t ctx, int argc,
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt char **argv);
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrewsstatic mdn_result_t parse_server_encoding(mdn_resconf_t ctx, int argc,
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews char **argv);
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrewsstatic mdn_result_t parse_server_zld(mdn_resconf_t ctx, int argc,
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt char **argv);
206e697f24e47b8868bd68a5b6ef42f5f62e39d5Evan Huntstatic mdn_result_t parse_alternate_encoding(mdn_resconf_t ctx, int argc,
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt char **argv);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntstatic int split_args(char *s, char **av, int nav);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntstatic void resetconf(mdn_resconf_t ctx);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntstatic mdn_result_t update_local_converter(mdn_resconf_t ctx);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntstatic mdn_result_t mystrdup(const char *from, char **top);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntmdn_result_t
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntmdn_resconf_initialize(void) {
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt mdn_result_t r;
2a80bc01530013293016172b1dcc1d12471ccf33Mark Andrews
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt TRACE(("mdn_resconf_initialize()\n"));
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt if ((r = mdn_converter_initialize()) != mdn_success)
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt return (r);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt if ((r = mdn_normalizer_initialize()) != mdn_success)
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt return (r);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt return (r);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt}
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntmdn_result_t
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntmdn_resconf_create(mdn_resconf_t *ctxp) {
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt mdn_resconf_t ctx = NULL;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt assert(ctxp != NULL);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt TRACE(("mdn_resconf_create()\n"));
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt if ((ctx = malloc(sizeof(*ctx))) == NULL)
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt return (mdn_nomemory);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt ctx->local_encoding = NULL;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt ctx->local_converter = NULL;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt ctx->server_converter = NULL;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt ctx->alternate_converter = NULL;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt ctx->normalizer = NULL;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt ctx->zld = NULL;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt ctx->edns0 = 0;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt *ctxp = ctx;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt return (mdn_success);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt}
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntchar *
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntmdn_resconf_defaultfile() {
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt return MDN_RESCONF_FILE;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt}
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntmdn_result_t
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Huntmdn_resconf_loadfile(mdn_resconf_t ctx, const char *file) {
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt FILE *fp;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt mdn_result_t r;
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt assert(ctx != NULL);
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt TRACE(("mdn_resconf_loadfile(file=%s)\n",
206e697f24e47b8868bd68a5b6ef42f5f62e39d5Evan Hunt file == NULL ? "<null>" : file));
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt if ((r = mdn_converter_resetalias()) != mdn_success)
6fa84a3e255ef9e6233f0a8d134fc6d273f04599Evan Hunt return (r);
03e200df5dc283f24a6a349f0b31d3eab26da893Mark Andrews
03e200df5dc283f24a6a349f0b31d3eab26da893Mark Andrews resetconf(ctx);
03e200df5dc283f24a6a349f0b31d3eab26da893Mark Andrews
323a9f3430abf186f8f84d795549391a8ed7f274Francis Dupont if (file == NULL)
03e200df5dc283f24a6a349f0b31d3eab26da893Mark Andrews file = mdn_resconf_defaultfile();
03e200df5dc283f24a6a349f0b31d3eab26da893Mark Andrews if ((fp = fopen(file, "r")) == NULL) {
03e200df5dc283f24a6a349f0b31d3eab26da893Mark Andrews TRACE(("mdn_resconf_loadfile: cannot open %-.40s\n", file));
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrence return (mdn_nofile);
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrence }
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrence
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrence r = parse_conf(ctx, fp);
75a4dd0d377dca2f85cea44e28bf110314c1fe8cDavid Lawrence fclose(fp);
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafsson
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafsson return (r);
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafsson}
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafsson
91306d962f9d147d94b82fb14edb28f8d907cae7Andreas Gustafssonvoid
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrencemdn_resconf_destroy(mdn_resconf_t ctx) {
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence TRACE(("mdn_resconf_destroy()\n"));
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence resetconf(ctx);
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence free(ctx);
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence}
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrencemdn_converter_t
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrencemdn_resconf_localconverter(mdn_resconf_t ctx) {
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence TRACE(("mdn_resconf_localconverter()\n"));
e893dce91279d7313a579f72caae3941f6dc5a27David Lawrence if (update_local_converter(ctx) != mdn_success)
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley return (NULL);
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley return (ctx->local_converter);
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley}
8e06cea14c857429ab7e7299af2dce5eeeaa5ff0Michael Graff
ce8c568e0d6106bb87069453505e09bc66754b40Andreas Gustafssonmdn_converter_t
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halleymdn_resconf_serverconverter(mdn_resconf_t ctx) {
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley TRACE(("mdn_resconf_serverconverter()\n"));
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley return (ctx->server_converter);
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley}
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halleymdn_converter_t
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halleymdn_resconf_alternateconverter(mdn_resconf_t ctx) {
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley TRACE(("mdn_resconf_alternateconverter()\n"));
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley return (ctx->alternate_converter);
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley}
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halley
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halleyconst char *
3b77946b751f39bd4db5a7d1fe48a81e6b1e7a28Bob Halleymdn_resconf_zld(mdn_resconf_t ctx) {
8e06cea14c857429ab7e7299af2dce5eeeaa5ff0Michael Graff TRACE(("mdn_resconf_zld()\n"));
8e06cea14c857429ab7e7299af2dce5eeeaa5ff0Michael Graff return (ctx->zld);
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson}
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉mdn_normalizer_t
a27fe4c990f96bd792f2a07ca4d38c78d5b9df2cTatuya JINMEI 神明達哉mdn_resconf_normalizer(mdn_resconf_t ctx) {
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson TRACE(("mdn_resconf_normalizer()\n"));
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson return (ctx->normalizer);
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson}
3ecf3394e37dc2848a09ffc643565d454e9e6974Andreas Gustafsson
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrewsstatic mdn_result_t
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrewsparse_conf(mdn_resconf_t ctx, FILE *fp) {
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews char line[256];
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews char *argv[20];
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews int argc;
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews mdn_result_t r;
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews char *sencoding_line = NULL;
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews char *fencoding_line = NULL;
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews /*
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień * Parse config file. parsing of 'server-encoding' and
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień * 'alternate-encoding' lines are postponed because
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews * 'alias-file' line must be processed before them.
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews */
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt while (fgets(line, sizeof(line), fp) != NULL) {
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt char buf[256];
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt if (line[0] == '\n')
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt continue;
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt (void)strcpy(buf, line);
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews argc = split_args(buf, argv, 20);
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews if (argc == 0 || argv[0][0] == '#')
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews continue;
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews if (strcmp(argv[0], "normalize") == 0)
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews r = parse_normalize(ctx, argc, argv);
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews else if (strcmp(argv[0], "alias-file") == 0)
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt r = parse_alias_file(ctx, argc, argv);
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews else if (strcmp(argv[0], "server-zld") == 0)
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews r = parse_server_zld(ctx, argc, argv);
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews else if (strcmp(argv[0], "server-encoding") == 0)
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews r = mystrdup(line, &sencoding_line);
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews else if (strcmp(argv[0], "alternate-encoding") == 0)
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt r = mystrdup(line, &fencoding_line);
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt else {
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt mdn_log_error("mdnres: unrecognized command "
1f27b7873c640771df00a47ee3be188c4079479cFrancis Dupont "\"%-.30s\"\n", argv[0]);
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt r = mdn_invalid_syntax;
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt }
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews if (r != mdn_success)
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews return (r);
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews }
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews if (sencoding_line != NULL) {
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews argc = split_args(sencoding_line, argv, 50);
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews r = parse_server_encoding(ctx, argc, argv);
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews free(sencoding_line);
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews if (r != mdn_success)
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt return (r);
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt }
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt if (fencoding_line != NULL) {
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews argc = split_args(fencoding_line, argv, 50);
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews r = parse_alternate_encoding(ctx, argc, argv);
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews free(fencoding_line);
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews if (r != mdn_success)
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews return (r);
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt }
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt return (mdn_success);
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt}
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt
523f3d630243211ddfda852f5224f7eff681d3a5Evan Huntstatic mdn_result_t
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrewsparse_normalize(mdn_resconf_t ctx, int argc, char **argv) {
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews mdn_result_t r;
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews int i;
67247b4a8304bac790648a351a95b8b0f4c512a6Mark Andrews
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt if (ctx->normalizer == NULL) {
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt r = mdn_normalizer_create(&ctx->normalizer);
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień if (r != mdn_success)
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt return (r);
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień }
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień for (i = 1; i < argc; i++) {
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień r = mdn_normalizer_add(ctx->normalizer, argv[i]);
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień if (r != mdn_success) {
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień if (r == mdn_invalid_name)
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień mdn_log_error("mdnres: unknown "
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień "normalization scheme %-.30s\n",
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień argv[i]);
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień return (r);
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień }
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień }
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt return (mdn_success);
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt}
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt
523f3d630243211ddfda852f5224f7eff681d3a5Evan Huntstatic mdn_result_t
523f3d630243211ddfda852f5224f7eff681d3a5Evan Huntparse_alias_file(mdn_resconf_t ctx, int argc, char **argv) {
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt if (argc != 2) {
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt mdn_log_error("mdnres: wrong # of args for %s\n", argv[0]);
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt return (mdn_invalid_syntax);
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt }
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt return (mdn_converter_aliasfile(argv[1]));
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews}
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrewsstatic mdn_result_t
523f3d630243211ddfda852f5224f7eff681d3a5Evan Huntparse_server_encoding(mdn_resconf_t ctx, int argc, char **argv) {
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt if (argc != 2) {
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews mdn_log_error("mdnres: wrong # of args for %s\n", argv[0]);
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt return (mdn_invalid_syntax);
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt }
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews return (mdn_converter_create(argv[1], &ctx->server_converter,
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews MDN_CONVERTER_DELAYEDOPEN));
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews}
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrewsstatic mdn_result_t
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrewsparse_server_zld(mdn_resconf_t ctx, int argc, char **argv) {
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews#ifdef MDN_SUPPORT_ZLD
21e5f9c5cdb3052f282e3dbdc2dc47f29cfe1187Mark Andrews mdn_result_t r;
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt if (argc != 2) {
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt mdn_log_error("mdnres: wrong # of args for %s\n", argv[0]);
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt return (mdn_invalid_syntax);
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt }
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt r = mdn_translator_canonicalzld(argv[1], &ctx->zld);
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt if (r != mdn_success)
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt return (r);
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt return (mdn_success);
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt#else
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt mdn_log_warning("mdnres: ZLD support is disabled -- ignored\n");
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt return (mdn_success);
523f3d630243211ddfda852f5224f7eff681d3a5Evan Hunt#endif /* MDN_SUPPORT_ZLD */
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews}
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrewsstatic mdn_result_t
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrewsparse_alternate_encoding(mdn_resconf_t ctx, int argc, char **argv) {
66dddd906ada6035d65bbbad2ecbcd74037759a8Mark Andrews mdn_result_t r;
831f59eb43b56642b00f82e07722836d2f9593abEvan Hunt
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt if (argc != 2) {
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews mdn_log_error("mdnres: wrong # of args for %s\n", argv[0]);
d7729155dff87d3c7a2b9103bf6e5164ea4d7dd7Mark Andrews return (mdn_invalid_syntax);
66dddd906ada6035d65bbbad2ecbcd74037759a8Mark Andrews }
831f59eb43b56642b00f82e07722836d2f9593abEvan Hunt r = mdn_converter_create(argv[1], &ctx->alternate_converter,
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt MDN_CONVERTER_DELAYEDOPEN);
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews if (r == mdn_success &&
66dddd906ada6035d65bbbad2ecbcd74037759a8Mark Andrews !mdn_converter_isasciicompatible(ctx->alternate_converter)) {
831f59eb43b56642b00f82e07722836d2f9593abEvan Hunt mdn_log_error("mdnres: alternate encoding must be "
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt "ASCII-compatible\n");
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews mdn_converter_destroy(ctx->alternate_converter);
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień ctx->alternate_converter = NULL;
a22c3cf51567651f74aee5c263c597b8d752c2ccMichał Kępień return (mdn_invalid_name);
1cefb9df3fa34d08734f29005cfafa6be5cf3e93Mark Andrews }
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence return (r);
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence}
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
b587e1d83f007ce68a9ae93097c461d8eb7aa373Mark Andrewsstatic int
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrencesplit_args(char *s, char **av, int nav) {
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence int i;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence for (i = 0; i < nav; i++) {
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence while (isspace((unsigned char)*s))
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence s++;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence if (*s == '\0')
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence break;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence if (*s == '"' || *s == '\'') {
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence int qc = *s++;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence av[i] = s;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence while (*s != '\0' && *s != qc)
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence s++;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence } else {
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence av[i] = s;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence while (*s != '\0' && !isspace((unsigned char)*s))
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence s++;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews }
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews if (*s == '\0')
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews return (i + 1);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews *s++ = '\0';
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews }
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews return (i);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews}
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsstatic void
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsresetconf(mdn_resconf_t ctx) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews if (ctx->local_encoding != NULL) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews free(ctx->local_encoding);
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence ctx->local_encoding = NULL;
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt }
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt if (ctx->local_converter != NULL) {
ae4cbb69eef32ced103fe4561e8d2031ee4c3497David Lawrence mdn_converter_destroy(ctx->local_converter);
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence ctx->local_converter = NULL;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence }
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence if (ctx->server_converter != NULL) {
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence mdn_converter_destroy(ctx->server_converter);
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence ctx->server_converter = NULL;
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence }
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence if (ctx->alternate_converter != NULL) {
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence mdn_converter_destroy(ctx->alternate_converter);
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence ctx->alternate_converter = NULL;
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence }
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews if (ctx->normalizer != NULL) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews mdn_normalizer_destroy(ctx->normalizer);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ctx->normalizer = NULL;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews }
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews if (ctx->zld != NULL) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews free(ctx->zld);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ctx->zld = NULL;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews }
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ctx->edns0 = 0;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews}
2a80bc01530013293016172b1dcc1d12471ccf33Mark Andrews
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsstatic mdn_result_t
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrewsupdate_local_converter(mdn_resconf_t ctx) {
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence mdn_result_t r;
0293ad13207aa29bd5844cdc87d085ffc009d749David Lawrence const char *local_encoding = mdn_localencoding_name();
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence if (local_encoding == NULL) {
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence mdn_log_error("cannot determine local codeset name\n");
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence return (mdn_notfound);
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence }
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence if (ctx->local_encoding != NULL &&
df3c4c7988b9bae7d121a8ac9ed17a23366a948dDavid Lawrence strcmp(ctx->local_encoding, local_encoding) == 0 &&
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff ctx->local_converter != NULL) {
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff return (mdn_success);
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff }
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff if (ctx->local_encoding != NULL) {
1ce985ab3c6670662d555c108b35fed84a6a1001David Lawrence free(ctx->local_encoding);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ctx->local_encoding = NULL;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews }
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews if (ctx->local_converter != NULL) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews mdn_converter_destroy(ctx->local_converter);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews ctx->local_converter = NULL;
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews }
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence r = mystrdup(local_encoding, &ctx->local_encoding);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence if (r != mdn_success)
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence return (r);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence r = mdn_converter_create(ctx->local_encoding,
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence &ctx->local_converter,
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence MDN_CONVERTER_RTCHECK);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence return (r);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence}
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrencestatic mdn_result_t
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrencemystrdup(const char *from, char **top) {
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence char *s = malloc(strlen(from) + 1);
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence if (*top != NULL) {
4bcaefbcd3ced942139fdc830e007c6ea2b8d2feDavid Lawrence free(*top);
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff *top = NULL;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff }
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff if (s == NULL)
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff return (mdn_nomemory);
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff (void)strcpy(s, from);
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff *top = s;
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff return (mdn_success);
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff}
657ce0b9d84fbd66514df53d61a087e8f1161187Michael Graff