summaryrefslogtreecommitdiffstats
path: root/contrib/idn/idnkit-1.0-src/wsock/common
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/idn/idnkit-1.0-src/wsock/common')
-rw-r--r--contrib/idn/idnkit-1.0-src/wsock/common/checkdll.c242
-rw-r--r--contrib/idn/idnkit-1.0-src/wsock/common/convert.c180
-rw-r--r--contrib/idn/idnkit-1.0-src/wsock/common/dump.c118
-rw-r--r--contrib/idn/idnkit-1.0-src/wsock/common/encoding.c271
-rw-r--r--contrib/idn/idnkit-1.0-src/wsock/common/hook.c224
-rw-r--r--contrib/idn/idnkit-1.0-src/wsock/common/make.wnt102
-rw-r--r--contrib/idn/idnkit-1.0-src/wsock/common/printf.c138
-rw-r--r--contrib/idn/idnkit-1.0-src/wsock/common/wrapcommon.h109
8 files changed, 1384 insertions, 0 deletions
diff --git a/contrib/idn/idnkit-1.0-src/wsock/common/checkdll.c b/contrib/idn/idnkit-1.0-src/wsock/common/checkdll.c
new file mode 100644
index 0000000..a620cc9
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/wsock/common/checkdll.c
@@ -0,0 +1,242 @@
+/*
+ * checkdll.c - Winsock DLL/IDN processing status
+ */
+
+/*
+ * Copyright (c) 2000,2002 Japan Network Information Center.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set forth bellow.
+ *
+ * LICENSE TERMS AND CONDITIONS
+ *
+ * The following License Terms and Conditions apply, unless a different
+ * license is obtained from Japan Network Information Center ("JPNIC"),
+ * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, Japan.
+ *
+ * 1. Use, Modification and Redistribution (including distribution of any
+ * modified or derived work) in source and/or binary forms is permitted
+ * under this License Terms and Conditions.
+ *
+ * 2. Redistribution of source code must retain the copyright notices as they
+ * appear in each source code file, this License Terms and Conditions.
+ *
+ * 3. Redistribution in binary form must reproduce the Copyright Notice,
+ * this License Terms and Conditions, in the documentation and/or other
+ * materials provided with the distribution. For the purposes of binary
+ * distribution the "Copyright Notice" refers to the following language:
+ * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not be used to endorse or promote products
+ * derived from this Software without specific prior written approval of
+ * JPNIC.
+ *
+ * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
+ * "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 JPNIC 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 DAMAGES.
+ */
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "wrapcommon.h"
+
+static int winsock_idx; /* index of winsock_info[] */
+
+static struct winsock_type {
+ char *version; /* winsock version */
+ char *name; /* wrapper DLL name */
+ char *original_name; /* original DLL name */
+} winsock_info[] = {
+#define IDN_IDX_WS11 0
+ { "1.1", "WSOCK32", "WSOCK32O" },
+#define IDN_IDX_WS20 1
+ { "2.0", "WS2_32", "WS2_32O" },
+ { NULL, NULL, NULL },
+};
+
+static HINSTANCE load_original_dll(void);
+static BOOL check_idn_processing(void);
+static BOOL check_dll(const char *name);
+
+BOOL
+idnWinsockVersion(const char *version) {
+ int i;
+ for (i = 0; winsock_info[i].version != NULL; i++) {
+ if (strcmp(winsock_info[i].version, version) == 0) {
+ winsock_idx = i;
+ idnLogPrintf(idn_log_level_trace,
+ "idnWinsockVersion: version %s\n",
+ version);
+ return (TRUE);
+ }
+ }
+ idnLogPrintf(idn_log_level_fatal,
+ "idnWinsockVersion: unknown winsock version %s\n",
+ version);
+ return (FALSE);
+}
+
+HINSTANCE
+idnWinsockHandle(void) {
+ static HINSTANCE dll_handle = NULL;
+ static int initialized = 0;
+
+ if (!initialized) {
+ /* Get the handle of the original winsock DLL */
+ idnLogPrintf(idn_log_level_trace,
+ "idnWinsockHandle: loading original DLL..\n");
+ dll_handle = load_original_dll();
+ }
+ initialized = 1;
+ return (dll_handle);
+}
+
+idn_resconf_t
+idnGetContext(void) {
+ static int initialized = 0;
+ static idn_resconf_t ctx = NULL;
+
+ if (!initialized) {
+ /*
+ * Check whether IDN processing should be done
+ * in this wrapper DLL.
+ */
+ idnLogPrintf(idn_log_level_trace,
+ "idnGetContext: checking IDN status..\n");
+ if (check_idn_processing()) {
+ /* Initialize idnkit */
+ ctx = idnConvInit();
+ idnLogPrintf(idn_log_level_info,
+ "Processing context: %08x\n", ctx);
+ } else {
+ idnLogPrintf(idn_log_level_info,
+ "NOT process IDN here\n");
+ ctx = NULL;
+ }
+ initialized = 1;
+ }
+
+ return (ctx);
+}
+
+static HINSTANCE
+load_original_dll(void) {
+ /*
+ * Load Original DLL
+ */
+ char dllpath[MAX_PATH];
+ const char *dll_name = winsock_info[winsock_idx].original_name;
+ HINSTANCE handle;
+
+ /*
+ * Get idn wrapper's install directory, where the copies of
+ * the original winsock DLLs are saved.
+ */
+ dllpath[0] = '\0';
+ if (idnGetInstallDir(dllpath, sizeof(dllpath)) != TRUE) {
+ idnLogPrintf(idn_log_level_fatal,
+ "idnWinsockHandle: cannot find idn wrapper's "
+ "install directory\n");
+ abort();
+ return (NULL); /* for lint */
+ }
+ /* Strip the trailing backslash. */
+ if (dllpath[0] != '\0' &&
+ dllpath[strlen(dllpath) - 1] == '\\') {
+ dllpath[strlen(dllpath) - 1] = '\0';
+ }
+ /* Is the pathname is insanely long? */
+ if (strlen(dllpath) + strlen(dll_name) + 1 + 4 >= sizeof(dllpath)) {
+ idnLogPrintf(idn_log_level_fatal,
+ "idnWinsockHandle: idn wrapper's install path is "
+ "too long to be true\n");
+ abort();
+ return (NULL); /* for lint */
+ }
+ /* Append the DLL name to form a full pathname of the DLL. */
+ strcat(dllpath, "\\");
+ strcat(dllpath, dll_name);
+ strcat(dllpath, ".DLL");
+
+ idnLogPrintf(idn_log_level_trace,
+ "idnWinsockHandle: loading original winsock DLL (%s)\n",
+ dllpath);
+ if ((handle = LoadLibrary(dllpath)) == NULL) {
+ idnLogPrintf(idn_log_level_fatal,
+ "idnWinsockHandle: no DLL %-.100s\n", dllpath);
+ abort();
+ return (NULL); /* font lint */
+ }
+ return (handle);
+}
+
+static BOOL
+check_idn_processing(void) {
+ int where = idnEncodeWhere();
+ BOOL here = FALSE;
+
+ idnLogPrintf(idn_log_level_trace,
+ "idnGetContext: Winsock%s, where=%d\n",
+ winsock_info[winsock_idx].version, where);
+
+ switch (winsock_idx) {
+ case IDN_IDX_WS11:
+ switch (where) {
+ case IDN_ENCODE_ALWAYS:
+ case IDN_ENCODE_ONLY11:
+ return (TRUE);
+ case IDN_ENCODE_CHECK:
+ if (!check_dll(winsock_info[winsock_idx].name)) {
+ return (TRUE);
+ }
+ break;
+ }
+ break;
+ case IDN_IDX_WS20:
+ switch (where) {
+ case IDN_ENCODE_ALWAYS:
+ case IDN_ENCODE_ONLY20:
+ case IDN_ENCODE_CHECK:
+ return (TRUE);
+ break;
+ }
+ break;
+ }
+ return (FALSE);
+}
+
+static BOOL
+check_dll(const char *name) {
+ HINSTANCE hdll = NULL;
+
+#if 1
+ hdll = LoadLibrary(name);
+#else
+ /*
+ * Just check the existence of the named DLL, without taking
+ * the trouble of calling DllMain.
+ */
+ hdll = LoadLibraryEx(name, NULL, LOAD_LIBRARY_AS_DATAFILE);
+#endif
+ if (hdll == NULL) {
+ idnLogPrintf(idn_log_level_trace,
+ "idnGetContext: DLL %s does not exist\n");
+ return (FALSE);
+ } else {
+ idnLogPrintf(idn_log_level_trace,
+ "idnGetContext: DLL %s exists\n");
+ FreeLibrary(hdll);
+ return (TRUE);
+ }
+}
diff --git a/contrib/idn/idnkit-1.0-src/wsock/common/convert.c b/contrib/idn/idnkit-1.0-src/wsock/common/convert.c
new file mode 100644
index 0000000..b2c202e
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/wsock/common/convert.c
@@ -0,0 +1,180 @@
+/*
+ * convert.c - convert domain name
+ */
+
+/*
+ * Copyright (c) 2000,2002 Japan Network Information Center.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set forth bellow.
+ *
+ * LICENSE TERMS AND CONDITIONS
+ *
+ * The following License Terms and Conditions apply, unless a different
+ * license is obtained from Japan Network Information Center ("JPNIC"),
+ * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, Japan.
+ *
+ * 1. Use, Modification and Redistribution (including distribution of any
+ * modified or derived work) in source and/or binary forms is permitted
+ * under this License Terms and Conditions.
+ *
+ * 2. Redistribution of source code must retain the copyright notices as they
+ * appear in each source code file, this License Terms and Conditions.
+ *
+ * 3. Redistribution in binary form must reproduce the Copyright Notice,
+ * this License Terms and Conditions, in the documentation and/or other
+ * materials provided with the distribution. For the purposes of binary
+ * distribution the "Copyright Notice" refers to the following language:
+ * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not be used to endorse or promote products
+ * derived from this Software without specific prior written approval of
+ * JPNIC.
+ *
+ * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
+ * "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 JPNIC 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 DAMAGES.
+ */
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "wrapcommon.h"
+
+/*
+ * prepare/dispose conversion context
+ */
+
+void
+idnConvDone(idn_resconf_t ctx)
+{
+ if (ctx != NULL) {
+ idnLogReset();
+ idn_resconf_destroy(ctx);
+ }
+}
+
+idn_resconf_t
+idnConvInit(void)
+{
+ char encoding[256];
+ idn_resconf_t ctx;
+ idn_result_t r;
+
+ idnLogReset();
+
+ idnLogPrintf(idn_log_level_info, "idnkit version: %-.20s\n",
+ idn_version_getstring());
+
+ /*
+ * Initialize.
+ */
+ if ((r = idn_resconf_initialize()) != idn_success) {
+ idnPrintf("idnConvInit: cannot initialize idn library: %s\n",
+ idn_result_tostring(r));
+ return NULL;
+ }
+ if ((r = idn_resconf_create(&ctx)) != idn_success) {
+ idnPrintf("idnConvInit: cannot create context: %s\n",
+ idn_result_tostring(r));
+ return NULL;
+ }
+ /*
+ * load configuration file.
+ */
+ if ((r = idn_resconf_loadfile(ctx, NULL)) != idn_success) {
+ idnPrintf("idnConvInit: cannot read configuration file: %s\n",
+ idn_result_tostring(r));
+ if ((r = idn_resconf_setdefaults(ctx)) != idn_success) {
+ idnPrintf("idnConvInit: setting default configuration"
+ " failed: %s\n",
+ idn_result_tostring(r));
+ idnConvDone(ctx);
+ return (NULL);
+ }
+ idnPrintf("idnConvInit: using default configuration\n");
+ }
+ /*
+ * Set local codeset.
+ */
+ if (idnGetPrgEncoding(encoding, sizeof(encoding)) == TRUE) {
+ idnPrintf("Encoding PRG <%-.100s>\n", encoding);
+ r = idn_resconf_setlocalconvertername(ctx, encoding,
+ IDN_CONVERTER_RTCHECK);
+ if (r != idn_success) {
+ idnPrintf("idnConvInit: invalid local codeset "
+ "\"%-.100s\": %s\n",
+ encoding, idn_result_tostring(r));
+ idnConvDone(ctx);
+ return NULL;
+ }
+ }
+ return ctx;
+}
+
+/*
+ * idnConvReq - convert domain name in a DNS request
+ *
+ * convert local encoding to DNS encoding
+ */
+
+BOOL
+idnConvReq(idn_resconf_t ctx, const char FAR *from, char FAR *to, size_t tolen)
+{
+ idn_result_t r;
+
+ idnLogReset();
+
+ idnLogPrintf(idn_log_level_trace, "idnConvReq(from=%-.100s)\n", from);
+ if (ctx == NULL) {
+ idnLogPrintf(idn_log_level_trace, "idnConvReq: ctx is NULL\n");
+ if (strlen(from) >= tolen)
+ return FALSE;
+ strcpy(to, from);
+ return TRUE;
+ }
+
+ r = idn_res_encodename(ctx, IDN_ENCODE_APP, from, to, tolen);
+
+ if (r == idn_success) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * idnConvRsp - convert domain name in a DNS response
+ *
+ * convert DNS encoding to local encoding
+ */
+
+BOOL
+idnConvRsp(idn_resconf_t ctx, const char FAR *from, char FAR *to, size_t tolen)
+{
+ idnLogReset();
+
+ idnLogPrintf(idn_log_level_trace, "idnConvRsp(from=%-.100s)\n", from);
+ if (ctx == NULL) {
+ if (strlen(from) >= tolen)
+ return FALSE;
+ strcpy(to, from);
+ return TRUE;
+ } else if (idn_res_decodename(ctx, IDN_DECODE_APP,
+ from, to, tolen) == idn_success) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
diff --git a/contrib/idn/idnkit-1.0-src/wsock/common/dump.c b/contrib/idn/idnkit-1.0-src/wsock/common/dump.c
new file mode 100644
index 0000000..1f16bd5
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/wsock/common/dump.c
@@ -0,0 +1,118 @@
+/*
+ * dump.c - dump data
+ */
+
+/*
+ * Copyright (c) 2000 Japan Network Information Center. All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set forth bellow.
+ *
+ * LICENSE TERMS AND CONDITIONS
+ *
+ * The following License Terms and Conditions apply, unless a different
+ * license is obtained from Japan Network Information Center ("JPNIC"),
+ * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, Japan.
+ *
+ * 1. Use, Modification and Redistribution (including distribution of any
+ * modified or derived work) in source and/or binary forms is permitted
+ * under this License Terms and Conditions.
+ *
+ * 2. Redistribution of source code must retain the copyright notices as they
+ * appear in each source code file, this License Terms and Conditions.
+ *
+ * 3. Redistribution in binary form must reproduce the Copyright Notice,
+ * this License Terms and Conditions, in the documentation and/or other
+ * materials provided with the distribution. For the purposes of binary
+ * distribution the "Copyright Notice" refers to the following language:
+ * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not be used to endorse or promote products
+ * derived from this Software without specific prior written approval of
+ * JPNIC.
+ *
+ * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
+ * "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 JPNIC 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 DAMAGES.
+ */
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "wrapcommon.h"
+
+char *
+dumpAddr(const char FAR *addr, int len, char *buff, size_t size) {
+ int i;
+ char *p;
+
+ buff[0] = '\0';
+ for (i = 0, p = buff; i < len; i++) {
+ char digits[8];
+
+ sprintf(digits, "%d", (addr[i] & 0xff));
+ if (i + 1 < len) {
+ strcat(digits, ".");
+ }
+ if (strlen(digits) >= size) {
+ break;
+ }
+ strcpy(p, digits);
+ p += strlen(digits);
+ size -= strlen(digits);
+ }
+ return (buff);
+}
+
+char *
+dumpHost(const struct hostent FAR *hp, char *buff, size_t size) {
+ char *p = buff;
+
+ p[0] = '\0';
+ if (strlen(hp->h_name) + 1 < size) {
+ sprintf(p, "%s ", hp->h_name);
+ p += strlen(p);
+ size -= strlen(p);
+ }
+ dumpAddr(hp->h_addr_list[0], hp->h_length, p, size);
+ return (buff);
+}
+
+char *
+dumpName(const char *name, char *buff, size_t size) {
+ const char *sp;
+ char *dp;
+
+ for (sp = name, dp = buff; *sp != '\0'; sp++) {
+ if (*sp >= 0x21 && *sp <= 0x7e) {
+ if (size < 2) {
+ break;
+ }
+ *dp++ = *sp;
+ size--;
+ } else {
+ if (size < 5) {
+ break;
+ }
+ dp[0] = '\\';
+ dp[1] = 'x';
+ sprintf(dp + 2, "%02x", *sp & 0xff);
+ dp += 4;
+ size -= 4;
+ }
+ }
+ *dp = '\0';
+
+ return (buff);
+}
+
diff --git a/contrib/idn/idnkit-1.0-src/wsock/common/encoding.c b/contrib/idn/idnkit-1.0-src/wsock/common/encoding.c
new file mode 100644
index 0000000..f8ad9e7
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/wsock/common/encoding.c
@@ -0,0 +1,271 @@
+/*
+ * encoding.c - get DNS/Local encodings
+ *
+ * Software\JPNIC\IDN\Where
+ * \LogFile
+ * \LogLevel
+ * \InstallDir
+ * \PerProg\<name>\Where
+ * \PerProg\<name>\Encoding
+ */
+
+/*
+ * Copyright (c) 2000,2001,2002 Japan Network Information Center.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set forth bellow.
+ *
+ * LICENSE TERMS AND CONDITIONS
+ *
+ * The following License Terms and Conditions apply, unless a different
+ * license is obtained from Japan Network Information Center ("JPNIC"),
+ * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, Japan.
+ *
+ * 1. Use, Modification and Redistribution (including distribution of any
+ * modified or derived work) in source and/or binary forms is permitted
+ * under this License Terms and Conditions.
+ *
+ * 2. Redistribution of source code must retain the copyright notices as they
+ * appear in each source code file, this License Terms and Conditions.
+ *
+ * 3. Redistribution in binary form must reproduce the Copyright Notice,
+ * this License Terms and Conditions, in the documentation and/or other
+ * materials provided with the distribution. For the purposes of binary
+ * distribution the "Copyright Notice" refers to the following language:
+ * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not be used to endorse or promote products
+ * derived from this Software without specific prior written approval of
+ * JPNIC.
+ *
+ * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
+ * "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 JPNIC 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 DAMAGES.
+ */
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "wrapcommon.h"
+
+#define IDN_GLOBAL 1
+#define IDN_PERPROG 2
+#define IDN_CURUSER 4
+
+/*
+ * Registry of Encodings
+ */
+
+#define IDNKEY_WRAPPER "Software\\JPNIC\\IDN"
+#define IDNKEY_PERPROG "Software\\JPNIC\\IDN\\PerProg"
+#define IDNVAL_WHERE "Where"
+#define IDNVAL_ENCODE "Encoding"
+#define IDNVAL_LOGLVL "LogLevel"
+#define IDNVAL_LOGFILE "LogFile"
+#define IDNVAL_INSDIR "InstallDir"
+
+static int GetRegistry(HKEY top, const char *key, const char *name,
+ DWORD type, void *param, DWORD length);
+static char *GetPerProgKey(char *buf, size_t len);
+static int GetFromRegistry(const char *name, int where, DWORD type,
+ void *param, DWORD length);
+static int GetIntFromRegistry(const char *name, int defvalue, int where);
+static BOOL GetStringFromRegistry(const char *name, char *result,
+ size_t length, int where);
+
+static int
+GetRegistry(HKEY top, const char *key, const char *name, DWORD type,
+ void *param, DWORD length)
+{
+ LONG stat;
+ HKEY hk;
+ DWORD realtype;
+
+ stat = RegOpenKeyEx(top, key, 0, KEY_READ, &hk);
+ if (stat != ERROR_SUCCESS) {
+ return 0;
+ }
+
+ stat = RegQueryValueEx(hk, (LPCTSTR)name, NULL,
+ &realtype, (LPBYTE)param, &length);
+
+ RegCloseKey(hk);
+
+ if (stat != ERROR_SUCCESS || realtype != type)
+ return 0;
+
+ return 1;
+}
+
+static char *
+GetPerProgKey(char *buf, size_t len)
+{
+ char exename[256];
+ char prgname[256];
+ char *p, *last;
+
+ GetModuleFileName(NULL, exename, 256);
+
+ for (p = exename, last = NULL; *p != '\0'; p++) {
+ if (*p == '/' || *p == '\\') {
+ last = p;
+ }
+ }
+ strcpy(prgname, (last == NULL) ? exename : (last + 1));
+ if ((p = strrchr(prgname, '.')) != NULL) {
+ *p = '\0';
+ }
+
+ if (strlen(IDNKEY_PERPROG) + 1 + strlen(prgname) >= len) {
+ return (NULL);
+ }
+ sprintf(buf, "%s\\%s", IDNKEY_PERPROG, prgname);
+ return buf;
+}
+
+static int
+GetFromRegistry(const char *name, int where, DWORD type,
+ void *param, DWORD length)
+{
+ if (where & IDN_PERPROG) {
+ /*
+ * First, try program specific setting.
+ */
+ char keyname[256];
+
+ /*
+ * Try HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE.
+ */
+ if (GetPerProgKey(keyname, sizeof(keyname)) != NULL) {
+ if (((where & IDN_CURUSER) &&
+ GetRegistry(HKEY_CURRENT_USER, keyname, name,
+ type, param, length)) ||
+ GetRegistry(HKEY_LOCAL_MACHINE, keyname, name,
+ type, param, length)) {
+ return (1);
+ }
+ }
+ }
+
+ if (where & IDN_GLOBAL) {
+ /*
+ * Try global setting.
+ */
+ if (((where & IDN_CURUSER) &&
+ GetRegistry(HKEY_CURRENT_USER, IDNKEY_WRAPPER, name,
+ type, param, length)) ||
+ GetRegistry(HKEY_LOCAL_MACHINE, IDNKEY_WRAPPER, name,
+ type, param, length)) {
+ return (1);
+ }
+ }
+
+ /*
+ * Not found.
+ */
+ return (0);
+}
+
+static int
+GetIntFromRegistry(const char *name, int defvalue, int where)
+{
+ DWORD param;
+
+ if (GetFromRegistry(name, where, REG_DWORD, &param, sizeof(param))) {
+ return ((int)param);
+ }
+ return (defvalue);
+}
+
+static BOOL
+GetStringFromRegistry(const char *name, char *result, size_t length, int where)
+{
+ if (GetFromRegistry(name, where, REG_SZ, result, (DWORD)length)) {
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/*
+ * idnEncodeWhere - which module should convert domain name
+ */
+int
+idnEncodeWhere(void)
+{
+ int v = GetIntFromRegistry(IDNVAL_WHERE, IDN_ENCODE_ALWAYS,
+ IDN_GLOBAL|IDN_PERPROG|IDN_CURUSER);
+
+ idnLogPrintf(idn_log_level_trace, "idnEncodeWhere: %d\n", v);
+ return (v);
+}
+
+/*
+ * idnGetLogFile - refer to log file
+ */
+BOOL
+idnGetLogFile(char *file, size_t len)
+{
+ BOOL v = GetStringFromRegistry(IDNVAL_LOGFILE, file, len,
+ IDN_GLOBAL|IDN_CURUSER);
+
+ idnLogPrintf(idn_log_level_trace, "idnGetLogFile: %-.100s\n",
+ (v == TRUE) ? file : "<none>");
+ return (v);
+}
+
+/*
+ * idnGetPrgEncoding - refer to Program's Local Encoding
+ *
+ * use program name as registry key
+ */
+BOOL
+idnGetPrgEncoding(char *enc, size_t len)
+{
+ if (GetStringFromRegistry(IDNVAL_ENCODE, enc, len,
+ IDN_PERPROG|IDN_CURUSER) != TRUE ||
+ enc[0] == '\0') {
+ sprintf(enc, "CP%d", GetACP());
+ }
+ idnLogPrintf(idn_log_level_trace,
+ "idnGetPrgEncoding: %-.30s\n", enc);
+ return (TRUE);
+}
+
+/*
+ * idnGetLogLevel
+ */
+int
+idnGetLogLevel(void)
+{
+ int v = GetIntFromRegistry(IDNVAL_LOGLVL, 0,
+ IDN_GLOBAL|IDN_CURUSER);
+
+ idnLogPrintf(idn_log_level_trace, "idnGetLogLevel: %d\n", v);
+ return (v);
+}
+
+/*
+ * idnGetInstallDir - get idn wrapper install directory
+ */
+BOOL
+idnGetInstallDir(char *dir, size_t len)
+{
+ /* No need to look at HKEY_CURRENT_USER */
+ BOOL v = GetStringFromRegistry(IDNVAL_INSDIR, dir, len, IDN_GLOBAL);
+
+ idnLogPrintf(idn_log_level_trace, "idnGetInstallDir: %-.100s\n",
+ (v == TRUE) ? dir : "<none>");
+ return (v);
+}
diff --git a/contrib/idn/idnkit-1.0-src/wsock/common/hook.c b/contrib/idn/idnkit-1.0-src/wsock/common/hook.c
new file mode 100644
index 0000000..b520f10
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/wsock/common/hook.c
@@ -0,0 +1,224 @@
+/*
+ * hook.c - Hooking Asynchronous Completion
+ */
+
+/*
+ * Copyright (c) 2000,2002 Japan Network Information Center.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set forth bellow.
+ *
+ * LICENSE TERMS AND CONDITIONS
+ *
+ * The following License Terms and Conditions apply, unless a different
+ * license is obtained from Japan Network Information Center ("JPNIC"),
+ * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, Japan.
+ *
+ * 1. Use, Modification and Redistribution (including distribution of any
+ * modified or derived work) in source and/or binary forms is permitted
+ * under this License Terms and Conditions.
+ *
+ * 2. Redistribution of source code must retain the copyright notices as they
+ * appear in each source code file, this License Terms and Conditions.
+ *
+ * 3. Redistribution in binary form must reproduce the Copyright Notice,
+ * this License Terms and Conditions, in the documentation and/or other
+ * materials provided with the distribution. For the purposes of binary
+ * distribution the "Copyright Notice" refers to the following language:
+ * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not be used to endorse or promote products
+ * derived from this Software without specific prior written approval of
+ * JPNIC.
+ *
+ * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
+ * "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 JPNIC 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 DAMAGES.
+ */
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "wrapcommon.h"
+
+/*
+ * Hook Managements
+ */
+
+static HHOOK hookHandle = NULL ;
+
+typedef struct _HOOK *HOOKPTR;
+
+typedef struct _HOOK {
+ HOOKPTR prev;
+ HOOKPTR next;
+ idn_resconf_t ctx;
+ HWND hWnd;
+ u_int wMsg;
+ char FAR *pBuf;
+} HOOKREC;
+
+static HOOKREC hookList = { 0 } ;
+
+static void
+hookListInit(void) {
+ if (hookList.prev == NULL || hookList.next == NULL) {
+ hookList.prev = &hookList;
+ hookList.next = &hookList;
+ }
+}
+
+static HOOKPTR
+hookListSearch(HWND hWnd, u_int wMsg) {
+ HOOKPTR hp;
+
+ for (hp = hookList.next ; hp != &hookList ; hp = hp->next) {
+ if (hp->hWnd == hWnd && hp->wMsg == wMsg) {
+ return (hp);
+ }
+ }
+ return (NULL);
+}
+
+static BOOL
+hookListAppend(HWND hWnd, u_int wMsg, char FAR *buf, idn_resconf_t ctx) {
+ HOOKPTR hp, prev, next;
+
+ if ((hp = (HOOKPTR)malloc(sizeof(HOOKREC))) == NULL) {
+ idnPrintf("cannot create hook record\n");
+ return (FALSE);
+ }
+ memset(hp, 0, sizeof(*hp));
+
+ hp->ctx = ctx;
+ hp->hWnd = hWnd;
+ hp->wMsg = wMsg;
+ hp->pBuf = buf;
+
+ prev = hookList.prev;
+ next = prev->next;
+ prev->next = hp;
+ next->prev = hp;
+ hp->next = next;
+ hp->prev = prev;
+
+ return (TRUE);
+}
+
+static void
+hookListDelete(HOOKPTR hp)
+{
+ HOOKPTR prev, next;
+
+ prev = hp->prev;
+ next = hp->next;
+ prev->next = next;
+ next->prev = prev;
+
+ free(hp);
+}
+
+static void
+hookListDone(void)
+{
+ HOOKPTR hp;
+
+ while ((hp = hookList.next) != &hookList) {
+ hookListDelete(hp);
+ }
+}
+
+/*
+ * idnHookInit - initialize Hook Management
+ */
+void
+idnHookInit(void) {
+ hookListInit();
+}
+
+/*
+ * idnHookDone - finalize Hook Management
+ */
+void
+idnHookDone(void) {
+ if (hookHandle != NULL) {
+ UnhookWindowsHookEx(hookHandle);
+ hookHandle = NULL;
+ }
+ hookListDone();
+}
+
+/*
+ * hookProc - hookprocedure, used as WH_GETMESSAGE hook
+ */
+LRESULT CALLBACK
+hookProc(int nCode, WPARAM wParam, LPARAM lParam) {
+ MSG *pMsg;
+ HOOKPTR pHook;
+ struct hostent *pHost;
+ char nbuff[256];
+ char hbuff[256];
+
+ if (nCode < 0) {
+ return (CallNextHookEx(hookHandle, nCode, wParam, lParam));
+ } else if (nCode != HC_ACTION) {
+ return (0);
+ }
+ if ((pMsg = (MSG *)lParam) == NULL) {
+ return (0);
+ }
+ if ((pHook = hookListSearch(pMsg->hwnd, pMsg->message)) == NULL) {
+ return (0);
+ }
+
+ /*
+ * Convert the Host Name
+ */
+ pHost = (struct hostent *)pHook->pBuf;
+ idnPrintf("AsyncComplete Resulting <%s>\n",
+ dumpName(pHost->h_name, hbuff, sizeof(hbuff)));
+ if (idnConvRsp(pHook->ctx, pHost->h_name,
+ nbuff, sizeof(nbuff)) == TRUE) {
+ idnPrintf("AsyncComplete Converted <%s>\n",
+ dumpName(nbuff, hbuff, sizeof(hbuff)));
+ strcpy(pHost->h_name, nbuff);
+ }
+
+ /*
+ * Delete target
+ */
+ hookListDelete(pHook);
+
+ return (0);
+}
+
+/*
+ * idnHook - hook async. completion message
+ */
+BOOL
+idnHook(HWND hWnd, u_int wMsg, char FAR *buf, idn_resconf_t ctx)
+{
+ if (hookHandle == NULL) {
+ hookHandle = SetWindowsHookEx(WH_GETMESSAGE, hookProc,
+ NULL, GetCurrentThreadId());
+ }
+ if (hookHandle == NULL) {
+ idnPrintf("idnHook: cannot set hook\n");
+ return (FALSE);
+ }
+ if (hookListAppend(hWnd, wMsg, buf, ctx) != TRUE) {
+ return (FALSE);
+ }
+ return (TRUE);
+}
diff --git a/contrib/idn/idnkit-1.0-src/wsock/common/make.wnt b/contrib/idn/idnkit-1.0-src/wsock/common/make.wnt
new file mode 100644
index 0000000..4dde4dd
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/wsock/common/make.wnt
@@ -0,0 +1,102 @@
+#
+# Makefile for WinSock Wrapper (common part)
+#
+
+# Copyright (c) 2000 Japan Network Information Center. All rights reserved.
+#
+# By using this file, you agree to the terms and conditions set forth bellow.
+#
+# LICENSE TERMS AND CONDITIONS
+#
+# The following License Terms and Conditions apply, unless a different
+# license is obtained from Japan Network Information Center ("JPNIC"),
+# a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+# Chiyoda-ku, Tokyo 101-0047, Japan.
+#
+# 1. Use, Modification and Redistribution (including distribution of any
+# modified or derived work) in source and/or binary forms is permitted
+# under this License Terms and Conditions.
+#
+# 2. Redistribution of source code must retain the copyright notices as they
+# appear in each source code file, this License Terms and Conditions.
+#
+# 3. Redistribution in binary form must reproduce the Copyright Notice,
+# this License Terms and Conditions, in the documentation and/or other
+# materials provided with the distribution. For the purposes of binary
+# distribution the "Copyright Notice" refers to the following language:
+# "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
+#
+# 4. The name of JPNIC may not be used to endorse or promote products
+# derived from this Software without specific prior written approval of
+# JPNIC.
+#
+# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
+# "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 JPNIC 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 DAMAGES.
+
+!include <win32.mak>
+
+SYSLIBS = $(libcdll) kernel32.lib advapi32.lib user32.lib
+
+#
+# Files to use
+#
+
+HDRS = wrapcommon.h
+SRCS = printf.c dump.c checkdll.c encoding.c convert.c hook.c
+OBJS = printf.obj dump.obj checkdll.obj encoding.obj convert.obj hook.obj
+LIBS = ..\..\lib\idnkit.lib ..\..\win\iconv.lib
+
+cflags = $(cflags) -I..\..\include
+
+#
+# Targets to Build
+#
+
+TARGETS = wrapcommon.lib
+
+all : $(TARGETS)
+
+wrapcommon.lib : $(OBJS)
+ -del wrapcommon.lib
+ lib /out:wrapcommon.lib $(OBJS)
+
+install :
+
+clean : force
+ -del *.obj
+ -del *.lib
+ -del *.exp
+
+#
+# Dependencies
+#
+
+printf.obj : printf.c $(HDRS)
+ $(cc) $(cflags) $(cvarsdll) -DDEBUG $*.c
+
+dump.obj : dump.c $(HDRS)
+ $(cc) $(cflags) $(cvarsdll) -DDEBUG $*.c
+
+checkdll.obj : checkdll.c $(HDRS)
+ $(cc) $(cflags) $(cvarsdll) -DDEBUG $*.c
+
+encoding.obj : encoding.c $(HDRS)
+ $(cc) $(cflags) $(cvarsdll) -DDEBUG $*.c
+
+convert.obj : convert.c $(HDRS)
+ $(cc) $(cflags) $(cvarsdll) -DDEBUG $*.c
+
+hook.obj : hook.c $(HDRS)
+ $(cc) $(cflags) $(cvarsdll) -DDEBUG $*.c
+
+force :
+
diff --git a/contrib/idn/idnkit-1.0-src/wsock/common/printf.c b/contrib/idn/idnkit-1.0-src/wsock/common/printf.c
new file mode 100644
index 0000000..7d6d2e4
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/wsock/common/printf.c
@@ -0,0 +1,138 @@
+/*
+ * printf.c - printf like debug print function
+ */
+
+/*
+ * Copyright (c) 2000,2002 Japan Network Information Center.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set forth bellow.
+ *
+ * LICENSE TERMS AND CONDITIONS
+ *
+ * The following License Terms and Conditions apply, unless a different
+ * license is obtained from Japan Network Information Center ("JPNIC"),
+ * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, Japan.
+ *
+ * 1. Use, Modification and Redistribution (including distribution of any
+ * modified or derived work) in source and/or binary forms is permitted
+ * under this License Terms and Conditions.
+ *
+ * 2. Redistribution of source code must retain the copyright notices as they
+ * appear in each source code file, this License Terms and Conditions.
+ *
+ * 3. Redistribution in binary form must reproduce the Copyright Notice,
+ * this License Terms and Conditions, in the documentation and/or other
+ * materials provided with the distribution. For the purposes of binary
+ * distribution the "Copyright Notice" refers to the following language:
+ * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not be used to endorse or promote products
+ * derived from this Software without specific prior written approval of
+ * JPNIC.
+ *
+ * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
+ * "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 JPNIC 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 DAMAGES.
+ */
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <process.h>
+
+#include "wrapcommon.h"
+
+/*
+ * Debug Tracer for DLL
+ */
+
+static char logfile_name[256];
+static int log_level = -1;
+static char log_header[30];
+
+void
+idnPrintf(char *fmt, ...) {
+ va_list arg_ptr;
+ FILE *fp;
+ char msg[512];
+
+ if (log_level < 0 || logfile_name[0] == '\0')
+ return;
+
+ va_start(arg_ptr, fmt);
+ vsprintf(msg, fmt, arg_ptr);
+ va_end(arg_ptr);
+
+ if ((fp = fopen(logfile_name, "a")) != NULL) {
+ fputs(log_header, fp);
+ fputs(msg, fp);
+ fclose(fp);
+ }
+}
+
+void
+idnLogPrintf(int level, char *fmt, ...) {
+ va_list arg_ptr;
+ FILE *fp;
+ char msg[512];
+
+ if (level > log_level || logfile_name[0] == '\0')
+ return;
+
+ va_start(arg_ptr, fmt);
+ vsprintf(msg, fmt, arg_ptr);
+ va_end(arg_ptr);
+
+ if ((fp = fopen(logfile_name, "a")) != NULL) {
+ fputs(log_header, fp);
+ fputs(msg, fp);
+ fclose(fp);
+ }
+}
+
+static void
+log_proc(int level, const char *msg) {
+ FILE *fp;
+
+ if (log_level < 0 || logfile_name[0] == '\0')
+ return;
+
+ if ((fp = fopen(logfile_name, "a")) != NULL) {
+ fputs(msg, fp);
+ fclose(fp);
+ }
+}
+
+void
+idnLogInit(const char *title) {
+ log_level = idnGetLogLevel();
+ /* If log file is not stored in the registry, don't do logging. */
+ if (idnGetLogFile(logfile_name, sizeof(logfile_name)) == FALSE) {
+ log_level = -1;
+ }
+ sprintf(log_header, "%08x %-.16s: ", getpid(), title);
+ idn_log_setproc(log_proc);
+ idn_log_setlevel(log_level < 0 ? 0 : log_level);
+}
+
+void
+idnLogReset(void) {
+ idn_log_setproc(log_proc);
+}
+
+void
+idnLogFinish(void) {
+ idn_log_setproc(NULL);
+ /* idn_log_setlevel(0); */
+}
diff --git a/contrib/idn/idnkit-1.0-src/wsock/common/wrapcommon.h b/contrib/idn/idnkit-1.0-src/wsock/common/wrapcommon.h
new file mode 100644
index 0000000..c186a33
--- /dev/null
+++ b/contrib/idn/idnkit-1.0-src/wsock/common/wrapcommon.h
@@ -0,0 +1,109 @@
+/*
+ * wrapcommon.h
+ */
+
+/*
+ * Copyright (c) 2000,2002 Japan Network Information Center.
+ * All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set forth bellow.
+ *
+ * LICENSE TERMS AND CONDITIONS
+ *
+ * The following License Terms and Conditions apply, unless a different
+ * license is obtained from Japan Network Information Center ("JPNIC"),
+ * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
+ * Chiyoda-ku, Tokyo 101-0047, Japan.
+ *
+ * 1. Use, Modification and Redistribution (including distribution of any
+ * modified or derived work) in source and/or binary forms is permitted
+ * under this License Terms and Conditions.
+ *
+ * 2. Redistribution of source code must retain the copyright notices as they
+ * appear in each source code file, this License Terms and Conditions.
+ *
+ * 3. Redistribution in binary form must reproduce the Copyright Notice,
+ * this License Terms and Conditions, in the documentation and/or other
+ * materials provided with the distribution. For the purposes of binary
+ * distribution the "Copyright Notice" refers to the following language:
+ * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
+ *
+ * 4. The name of JPNIC may not be used to endorse or promote products
+ * derived from this Software without specific prior written approval of
+ * JPNIC.
+ *
+ * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
+ * "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 JPNIC 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 DAMAGES.
+ */
+
+#ifndef _WRAPCOMMON_H
+#define _WRAPCOMMON_H
+
+#include <idn/res.h>
+#include <idn/log.h>
+#include <idn/version.h>
+
+#define WRAPPER_EXPORT extern __declspec(dllexport)
+
+extern void idnPrintf(char *fmt, ...);
+extern void idnLogPrintf(int level, char *fmt, ...);
+extern void idnLogInit(const char *title);
+extern void idnLogReset(void);
+extern void idnLogFinish(void);
+
+extern char *dumpAddr(const char FAR *addr, int len, char *buff, size_t size);
+extern char *dumpHost(const struct hostent FAR *hp, char *buff, size_t size);
+extern char *dumpName(const char *name, char *buff, size_t size);
+
+extern int idnEncodeWhere(void);
+
+#define IDN_ENCODE_ALWAYS 0
+#define IDN_ENCODE_CHECK 1
+#define IDN_ENCODE_ONLY11 2
+#define IDN_ENCODE_ONLY20 3
+
+extern BOOL idnGetPrgEncoding(char *enc, size_t len);
+extern BOOL idnGetLogFile(char *file, size_t len);
+
+extern int idnGetLogLevel(void); /* 0 : fatal */
+ /* 1 : error */
+ /* 2 : warning */
+ /* 3 : info */
+ /* 4 : trace */
+ /* 5 : dump */
+extern int idnGetInstallDir(char *dir, size_t len);
+
+extern idn_resconf_t idnConvInit(void);
+extern void idnConvDone(idn_resconf_t ctx);
+
+extern BOOL idnWinsockVersion(const char *version);
+extern HINSTANCE idnWinsockHandle(void);
+extern idn_resconf_t idnGetContext(void);
+
+/*
+ * Converting Request/Response
+ */
+
+extern BOOL idnConvReq(idn_resconf_t ctx, const char FAR *from,
+ char FAR *to, size_t tolen);
+extern BOOL idnConvRsp(idn_resconf_t ctx, const char FAR *from,
+ char FAR *to, size_t tolen);
+
+/*
+ * Hook for Asynchronouse Query
+ */
+
+extern void idnHookInit(void);
+extern void idnHookDone(void);
+extern BOOL idnHook(HWND hWnd, u_int wMsg, char FAR *buf, idn_resconf_t ctx);
+
+#endif /* _WRAPCOMMON_H */