Пример #1
0
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;
}
Пример #2
0
/*
 * 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);
}
Пример #3
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);
}
Пример #4
0
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);
}