4 * hook.c - Hooking Asynchronous Completion
8 * Copyright (c) 2000,2002 Japan Network Information Center.
11 * By using this file, you agree to the terms and conditions set forth bellow.
13 * LICENSE TERMS AND CONDITIONS
15 * The following License Terms and Conditions apply, unless a different
16 * license is obtained from Japan Network Information Center ("JPNIC"),
17 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
18 * Chiyoda-ku, Tokyo 101-0047, Japan.
20 * 1. Use, Modification and Redistribution (including distribution of any
21 * modified or derived work) in source and/or binary forms is permitted
22 * under this License Terms and Conditions.
24 * 2. Redistribution of source code must retain the copyright notices as they
25 * appear in each source code file, this License Terms and Conditions.
27 * 3. Redistribution in binary form must reproduce the Copyright Notice,
28 * this License Terms and Conditions, in the documentation and/or other
29 * materials provided with the distribution. For the purposes of binary
30 * distribution the "Copyright Notice" refers to the following language:
31 * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
33 * 4. The name of JPNIC may not be used to endorse or promote products
34 * derived from this Software without specific prior written approval of
37 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
40 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
41 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
44 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
45 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
46 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
55 #include "wrapcommon.h"
61 static HHOOK hookHandle
= NULL
;
63 typedef struct _HOOK
*HOOKPTR
;
65 typedef struct _HOOK
{
74 static HOOKREC hookList
= { 0 } ;
78 if (hookList
.prev
== NULL
|| hookList
.next
== NULL
) {
79 hookList
.prev
= &hookList
;
80 hookList
.next
= &hookList
;
85 hookListSearch(HWND hWnd
, u_int wMsg
) {
88 for (hp
= hookList
.next
; hp
!= &hookList
; hp
= hp
->next
) {
89 if (hp
->hWnd
== hWnd
&& hp
->wMsg
== wMsg
) {
97 hookListAppend(HWND hWnd
, u_int wMsg
, char FAR
*buf
, idn_resconf_t ctx
) {
98 HOOKPTR hp
, prev
, next
;
100 if ((hp
= (HOOKPTR
)malloc(sizeof(HOOKREC
))) == NULL
) {
101 idnPrintf("cannot create hook record\n");
104 memset(hp
, 0, sizeof(*hp
));
111 prev
= hookList
.prev
;
122 hookListDelete(HOOKPTR hp
)
139 while ((hp
= hookList
.next
) != &hookList
) {
145 * idnHookInit - initialize Hook Management
153 * idnHookDone - finalize Hook Management
157 if (hookHandle
!= NULL
) {
158 UnhookWindowsHookEx(hookHandle
);
165 * hookProc - hookprocedure, used as WH_GETMESSAGE hook
168 hookProc(int nCode
, WPARAM wParam
, LPARAM lParam
) {
171 struct hostent
*pHost
;
176 return (CallNextHookEx(hookHandle
, nCode
, wParam
, lParam
));
177 } else if (nCode
!= HC_ACTION
) {
180 if ((pMsg
= (MSG
*)lParam
) == NULL
) {
183 if ((pHook
= hookListSearch(pMsg
->hwnd
, pMsg
->message
)) == NULL
) {
188 * Convert the Host Name
190 pHost
= (struct hostent
*)pHook
->pBuf
;
191 idnPrintf("AsyncComplete Resulting <%s>\n",
192 dumpName(pHost
->h_name
, hbuff
, sizeof(hbuff
)));
193 if (idnConvRsp(pHook
->ctx
, pHost
->h_name
,
194 nbuff
, sizeof(nbuff
)) == TRUE
) {
195 idnPrintf("AsyncComplete Converted <%s>\n",
196 dumpName(nbuff
, hbuff
, sizeof(hbuff
)));
197 strcpy(pHost
->h_name
, nbuff
);
203 hookListDelete(pHook
);
209 * idnHook - hook async. completion message
212 idnHook(HWND hWnd
, u_int wMsg
, char FAR
*buf
, idn_resconf_t ctx
)
214 if (hookHandle
== NULL
) {
215 hookHandle
= SetWindowsHookEx(WH_GETMESSAGE
, hookProc
,
216 NULL
, GetCurrentThreadId());
218 if (hookHandle
== NULL
) {
219 idnPrintf("idnHook: cannot set hook\n");
222 if (hookListAppend(hWnd
, wMsg
, buf
, ctx
) != TRUE
) {