Sun Jun 28 18:37:02 1998 Alexandre Julliard <julliard@lrc.epfl.ch> * [if1632/signal.c] [miscemu/instr.c] [memory/virtual.c] Moved page-fault handling to INSTR_EmulateInstruction. * [scheduler/thread.c] Added locking and check for own thread in Suspend/ResumeThread. Sat Jun 27 21:25:21 1998 Ulrich Weigand <weigand@informatik.uni-erlangen.de> * [objects/dib.c] [objects/bitmap.c] [objects/oembitmap.c] [graphics/x11drv/bitblt.c] [include/bitmap.h] Improved DIB section handling using page fault handlers. (Note: This patch includes code contributed by Matthew J. Francis.) * [memory/virtual.c] [if1632/signal.c] [include/global.h] Page Fault handler support added. * [if1632/signal.c] [loader/signal.c] [tools/build.c] [misc/system.c] [misc/winsock_dns.c] [include/sig_context.h] [include/thread.h] 16-bit %fs handling improved: Always preserve 16-bit %fs value, always restore 32-bit %fs value for signal handlers. * [if1632/thunk.c] [loader/module.c] [misc/callback.c] [windows/user.c] [loader/ne/resource.c] [include/callback.h] [include/module.h] [if1632/kernel.spec] [if1632/wprocs.spec] Resource Handler function pointer stored as 16-bit SEGPTR. * [loader/task.c] [windows/win.c] [windows/winpos.c] [if1632/user.spec] [if1632/kernel.spec] [loader/ne/module.c] Some minor incompatibilities fixed (Win32s relies on those): GetExePtr, IsWindow16 should set ES on return; WINPOS_SendNCCalcSize should cope with having the WINDOWPOS structure trashed; the OFSTRUCT in the NE module image should be placed *last*. * [include/windows.h] Missing prototype for FlushViewOfFile. * [loader/task.c] Bugfix: Command line should *not* start with a blank. * [loader/ne/segment.c] Bugfix: Fixups to offset 0 were never applied. * [misc/lstr.c] Use debugstr_a in OutputDebugString16. * [msdos/dpmi.c] Stub for int 31 BL=2f AX=7a20 (NetWare: Get VLM Call Address) added. * [msdos/int21.c] Stub for int 21 AX=440d CL=6f (get drive map information) added. Fri Jun 26 18:08:30 1998 Rein Klazes <rklazes@casema.net> * [windows/winpos.c] Fix small buglet that mixed up maximized and minimized windows. * [include/x11drv.h] [objects/dc.c] [graphics/x11drv/pen.c] [graphics/x11drv/graphics.c] Fix some bugs with lines joining styles. Draws rectangles with thick pens now correctly. Fri Jun 26 16:22:23 1998 James Juran <jrj120@psu.edu> * [misc/shell.c] Fixed bug I introduced last release in InternalExtractIcon. * [win32/file.c] Added documentation for CreateFile32A. * [documentation/wine.man] Updated manpage. * [ChangeLog] Added my entry from last release. Fri Jun 26 13:33:30 1998 Huw D M Davies <daviesh@abacus.physics.ox.ac.uk> * [graphics/psdrv/*] [if1632/wineps.spec] [include/psdrv.h] [include/print.h] [objects/gdiobj.c] First stages of an internal Postscript driver. See graphics/psdrv/README . Should print text (badly) from win3.1 notepad, write and winword6. * [documentation/printing] Some notes on printing. * [controls/edit.c] Strip off WS_BORDER in WM_NCREATE, edit draws its own rectangle. EC_USEFONTINFO seems to be used as a left/right value for EM_SETMARGINS and not as an action as the docs say. This actually makes more sense. Scroll the caret back to zero after a WM_SETTEXT. Fri Jun 26 10:56:25 1998 Marcus Meissner <marcus@jet.franken.de> * [if1632/snoop.c] Added win16 inter-dll snooping. * [win32/ordinals.c] KERNEL_485 is GetProcessDword. * [include/xmalloc.h][include/bitmap.h][misc/xmalloc.c] Added xcalloc so we 0 initialize XImages. Fixes/Hides the 'junk around MOPYFish'. * [misc/ntdll.c] Some stubs added. Thu Jun 25 15:22:43 1998 Adrian Harvey <adrian@select.com.au> * [scheduler/thread.c] Implemented SuspendThread and ResumeThread. Thu Jun 25 00:55:03 1998 Peter Hunnisett <hunnise@nortel.ca> * [include/debug.h,dplay.h,dsound.h][multimedia/dsound.c,dplay.c] [relay32/dplayx.spec,dplay.spec][multimedia/Makefile.in] [documentation/status/directplay] Added preliminary support for DirectPlay & DirectPlayLobby. Moved the preliminary stubs put in the dsound files into two new files dplay.h and dplay.c. Added new debug channel (dplay) for this. Created new document to keep track of implementation. * [include/winioctl.h][win32/device.c] Added some framework in DeviceIoControl to, in the future, support the "builtin" windows dwIoControlCodes. Added new header file winioctl.h . * [multimedia/mmsystem.c] Added slightly improved debugging information for PlaySound. Wed Jun 24 12:00:00 1998 Juergen Schmied <juergen.schmied@metronet.de> * [files/profile.c][graphics/x11drv/xfont.c][loader/module.c] Changed lstrcmpi32A to strcasecmp, lstrncmpi32A to strncasecmp, lstrcpy32A to strcpy, lstrlen32A to strlen, lstrcmp32A to strcmp because it's not necessary to support locale on such places. It causes a huge overhead and even fails sometimes * [include/oleauto.h][include/winerror.h] Added some ole-related constants. * [misc/shell.c] SHELL32_DllGetClassObject, SHGetSpecialFolderLocation, SHGetPathFromIDList improved the stubs * [ole/folders.c] IShellFolder* functions rewrote the stubs so don't crash and give something sensible back, started implementation of. * [ole/typelib.c][relay32/oleaut32.spec] LoadTypeLib32, RegisterTypeLib stub. * [ole/ole2nls.c] Fixed a buffer overrun in CompareString32A. Test for a bad pointer in LCMapString32A (happens in winhlp32 while building a index for searching). * [relay32/oleaut32.spec] [ole/typelib.c] Added stub for LoadTypeLib (ole32) to make excel95 happy. Tue Jun 23 22:47:09 1998 Alex Priem <alexp@sci.kun.nl> * [files/profile.c] [relay32/kernel32.spec] Added WritePrivateProfileStructA, GetPrivateProfileStructA, GetPrivateProfileSectionNames16. Tue Jun 23 01:34:43 1998 Pascal Cuoq <pcuoq@ens-lyon.fr> * [ole/ole2nls.c] GetStringTypeEx32A: Implemented CT_CTYPE2 and CT_CTYPE3 cases. LCMapString32A: Map final '\0' for '\0'-terminated strings. * [misc/shellord.c] [files/profile.c] [graphics/driver.c] [loader/module.c] [msdos/int21.c] [windows/driver.c] [files/drive.c] Changed lstrcmpi32A -> strcasecmp. Should be OK in these places. Sat Jun 20 23:40:00 1998 Bertho Stultiens <bertho@akhphd.au.dk> * [tools/wrc/] Wrc version 1.0.2 (20-Jun-1998). Please revert to the file tools/wrc/CHANGES for details. Sat Jun 20 14:58:00 1998 Marcel Baur <mbaur@g26.ethz.ch> * [ole/ole2nls.c] [ole/nls/*] Added the first 57 nls files, most are not yet complete. Wed Jun 17 11:16:54 1998 David Luyer <luyer@ucs.uwa.edu.au> * [relay32/relay386.c] [if1632/relay.c] Move debug_relay_(include|exclude)_list handling into seperate function RELAY_ShowDebugmsgsRelay(). Include checking of this for 16 bit calls (originally only 32-bit calls). * [relay32/snoop.c] [misc/main.c] Add debug_snoop_(include|exclude)_list as per the relay stuff. Fix typo and add information on -debugmsg +/-relay=... in help on -debugmsg. Refer to availability of snoop too. Tue Jun 10 22:00:18 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de> * [controls/header.c][include/header.h][include/commctrl.h] Added owner draw support. * [windows/nonclient.c][windows/sysmetics.c] Fixed menu bar height for Win95 look. Split NC_AdjustRect95() into NC_AdjustRectOuter95() and NC_AdjustRectInner95 to fix a menu bar bug. Improved Win95 look. * [controls/progress.c] Improved drawing code. Borders will be drawn by non-client code. * [controls/updown.c] Changed memory allocation and fixed some bugs. * [controls/toolbar.c] Fixed TB_BUTTONSTRUCTSIZE bug in MFC programs. Several improvements. * [misc/shell.c] Added stub for BrowseForFoldersA(). * [misc/shellord.c] Added stub for SHELL32_147(). * [controls/comctl32undoc.c] Minor changes. * [documentation/common_controls] New File: Documentation about development status, undocumented features and functions of the common controls.
570 lines
16 KiB
C
570 lines
16 KiB
C
/*
|
|
* asynchronous DNS services
|
|
*
|
|
* (C) 1996,1997 Alex Korobka.
|
|
*
|
|
* TODO: Fork dns lookup helper during the startup (with a pipe
|
|
* for communication) and make it fork for a database request
|
|
* instead of forking the main process (i.e. something like
|
|
* Netscape 4.0).
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <signal.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/types.h>
|
|
#include <sys/ipc.h>
|
|
#include <sys/msg.h>
|
|
#include <sys/wait.h>
|
|
#include <errno.h>
|
|
#ifdef __EMX__
|
|
# include <sys/so_ioctl.h>
|
|
#endif
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
# include <sys/param.h>
|
|
#endif
|
|
#ifdef HAVE_SYS_FILIO_H
|
|
# include <sys/filio.h>
|
|
#endif
|
|
#ifdef __svr4__
|
|
# include <sys/file.h>
|
|
#endif
|
|
|
|
#include "winsock.h"
|
|
#include "windows.h"
|
|
#include "heap.h"
|
|
#include "ldt.h"
|
|
#include "message.h"
|
|
#include "selectors.h"
|
|
#include "miscemu.h"
|
|
#include "sig_context.h"
|
|
#include "debug.h"
|
|
|
|
#ifndef FASYNC
|
|
#define FASYNC FIOASYNC
|
|
#endif
|
|
|
|
typedef struct /* async DNS op control struct */
|
|
{
|
|
ws_async_op* ws_aop;
|
|
char* buffer;
|
|
int type;
|
|
union
|
|
{
|
|
char* init;
|
|
char* name;
|
|
char* addr;
|
|
} rq;
|
|
unsigned ilength;
|
|
} ws_async_ctl;
|
|
|
|
extern HANDLE16 __ws_gethandle( void* ptr );
|
|
extern void* __ws_memalloc( int size );
|
|
extern void __ws_memfree( void* ptr );
|
|
|
|
/* NOTE: ws_async_op list is traversed inside the SIGIO handler! */
|
|
|
|
static int __async_io_max_fd = 0;
|
|
static fd_set __async_io_fdset;
|
|
static ws_async_op* __async_op_list = NULL;
|
|
|
|
static void fixup_wshe(struct ws_hostent* p_wshe, void* base);
|
|
static void fixup_wspe(struct ws_protoent* p_wspe, void* base);
|
|
static void fixup_wsse(struct ws_servent* p_wsse, void* base);
|
|
|
|
/* ----------------------------------- async/non-blocking I/O */
|
|
|
|
int WINSOCK_async_io(int fd, int async)
|
|
{
|
|
int fd_flags;
|
|
|
|
#ifndef __EMX__
|
|
fcntl(fd, F_SETOWN, getpid());
|
|
#endif
|
|
|
|
fd_flags = fcntl(fd, F_GETFL, 0);
|
|
if (fcntl(fd, F_SETFL, (async)? fd_flags | FASYNC
|
|
: fd_flags & ~FASYNC ) != -1) return 0;
|
|
return -1;
|
|
}
|
|
|
|
int WINSOCK_unblock_io(int fd, int noblock)
|
|
{
|
|
int fd_flags;
|
|
|
|
fd_flags = fcntl(fd, F_GETFL, 0);
|
|
if (fcntl(fd, F_SETFL, (noblock)? fd_flags | O_NONBLOCK
|
|
: fd_flags & ~O_NONBLOCK ) != -1) return 0;
|
|
return -1;
|
|
}
|
|
|
|
int WINSOCK_check_async_op(ws_async_op* p_aop)
|
|
{
|
|
ws_async_op* p = __async_op_list;
|
|
while( p ) if( p == p_aop ) return 1;
|
|
else p = p->next;
|
|
return 0;
|
|
}
|
|
|
|
int WINSOCK_cancel_async_op(ws_async_op* p_aop)
|
|
{
|
|
/* SIGIO unsafe! */
|
|
|
|
if( WINSOCK_check_async_op(p_aop) )
|
|
{
|
|
if( !(p_aop->flags & WSMSG_DEAD_AOP) )
|
|
{
|
|
kill(p_aop->pid, SIGKILL);
|
|
waitpid(p_aop->pid, NULL, 0); /* just in case */
|
|
close(p_aop->fd[0]);
|
|
}
|
|
WINSOCK_unlink_async_op(p_aop);
|
|
EVENT_DeleteIO( p_aop->fd[0], EVENT_IO_READ );
|
|
p_aop->flags = 0;
|
|
p_aop->hWnd = p_aop->uMsg = 0;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void WINSOCK_cancel_task_aops(HTASK16 hTask, void (*__opfree)(void*))
|
|
{
|
|
/* SIGIO safe, hTask == 0 cancels all outstanding async ops */
|
|
|
|
int num = 0, num_dead = 0;
|
|
ws_async_op* p, *next;
|
|
|
|
TRACE(winsock," cancelling async DNS requests... \n");
|
|
|
|
SIGNAL_MaskAsyncEvents( TRUE );
|
|
next = __async_op_list;
|
|
while( (p = next) )
|
|
{
|
|
HTASK16 hWndTask = GetWindowTask16(p->hWnd);
|
|
|
|
next = p->next;
|
|
if(!hTask || !hWndTask || (hTask == hWndTask))
|
|
{
|
|
num++;
|
|
if( p->flags & WSMSG_DEAD_AOP )
|
|
num_dead++;
|
|
|
|
WINSOCK_cancel_async_op(p);
|
|
if( __opfree ) __opfree(p);
|
|
}
|
|
}
|
|
SIGNAL_MaskAsyncEvents( FALSE );
|
|
TRACE(winsock," -> %i total (%i active)\n", num, num - num_dead );
|
|
}
|
|
|
|
void WINSOCK_link_async_op(ws_async_op* p_aop)
|
|
{
|
|
/* SIGIO safe */
|
|
|
|
p_aop->prev = NULL;
|
|
SIGNAL_MaskAsyncEvents( TRUE );
|
|
if( __async_op_list )
|
|
{
|
|
ws_async_op* p = __async_op_list;
|
|
__async_op_list->prev = p_aop;
|
|
|
|
/* traverse the list and retire dead ops created
|
|
* by the signal handler (see below). */
|
|
|
|
while( p )
|
|
{
|
|
if( p->flags & WSMSG_DEAD_AOP )
|
|
{
|
|
ws_async_op* dead = p;
|
|
|
|
TRACE(winsock,"\treaping dead aop [%08x]\n", (unsigned)p );
|
|
|
|
p = p->next;
|
|
WINSOCK_unlink_async_op( dead );
|
|
__ws_memfree( dead );
|
|
continue;
|
|
}
|
|
p = p->next;
|
|
}
|
|
}
|
|
else FD_ZERO(&__async_io_fdset);
|
|
p_aop->next = __async_op_list;
|
|
__async_op_list = p_aop;
|
|
SIGNAL_MaskAsyncEvents( FALSE );
|
|
|
|
FD_SET(p_aop->fd[0], &__async_io_fdset);
|
|
if( p_aop->fd[0] > __async_io_max_fd )
|
|
__async_io_max_fd = p_aop->fd[0];
|
|
}
|
|
|
|
void WINSOCK_unlink_async_op(ws_async_op* p_aop)
|
|
{
|
|
/* SIGIO unsafe! */
|
|
|
|
if( p_aop == __async_op_list ) __async_op_list = p_aop->next;
|
|
else
|
|
p_aop->prev->next = p_aop->next;
|
|
if( p_aop->next ) p_aop->next->prev = p_aop->prev;
|
|
|
|
FD_CLR(p_aop->fd[0], &__async_io_fdset);
|
|
if( p_aop->fd[0] == __async_io_max_fd )
|
|
__async_io_max_fd--;
|
|
}
|
|
|
|
/* ----------------------------------- SIGIO handler -
|
|
*
|
|
* link_async_op/unlink_async_op allow to install generic
|
|
* async IO handlers (provided that aop_control function is defined).
|
|
*
|
|
* Note: pipe-based handlers must raise explicit SIGIO with kill(2).
|
|
*/
|
|
|
|
HANDLER_DEF(WINSOCK_sigio)
|
|
{
|
|
struct timeval timeout;
|
|
fd_set check_set;
|
|
ws_async_op* p_aop;
|
|
|
|
HANDLER_INIT();
|
|
|
|
check_set = __async_io_fdset;
|
|
memset(&timeout, 0, sizeof(timeout));
|
|
|
|
while( select(__async_io_max_fd + 1,
|
|
&check_set, NULL, NULL, &timeout) > 0)
|
|
{
|
|
for( p_aop = __async_op_list;
|
|
p_aop ; p_aop = p_aop->next )
|
|
if( FD_ISSET(p_aop->fd[0], &check_set) )
|
|
if( p_aop->aop_control(p_aop, AOP_IO) == AOP_CONTROL_REMOVE )
|
|
{
|
|
/* NOTE: memory management is signal-unsafe, therefore
|
|
* we can only set a flag to remove this p_aop later on.
|
|
*/
|
|
|
|
p_aop->flags = WSMSG_DEAD_AOP;
|
|
close(p_aop->fd[0]);
|
|
FD_CLR(p_aop->fd[0],&__async_io_fdset);
|
|
if( p_aop->fd[0] == __async_io_max_fd )
|
|
__async_io_max_fd = p_aop->fd[0];
|
|
if( p_aop->pid )
|
|
{
|
|
kill(p_aop->pid, SIGKILL);
|
|
waitpid(p_aop->pid, NULL, WNOHANG);
|
|
p_aop->pid = 0;
|
|
}
|
|
}
|
|
check_set = __async_io_fdset;
|
|
}
|
|
}
|
|
|
|
/* ----------------------------------- getXbyY requests */
|
|
|
|
static ws_async_ctl async_ctl; /* child process control struct */
|
|
|
|
static int aop_control(ws_async_op* p_aop, int flag )
|
|
{
|
|
unsigned lLength;
|
|
|
|
/* success: LOWORD(lLength) has the length of the struct
|
|
* to read.
|
|
* failure: LOWORD(lLength) is zero, HIWORD(lLength) contains
|
|
* the error code.
|
|
*/
|
|
|
|
read(p_aop->fd[0], &lLength, sizeof(unsigned));
|
|
if( LOWORD(lLength) )
|
|
{
|
|
if( (int)LOWORD(lLength) <= p_aop->buflen )
|
|
{
|
|
char* buffer = (p_aop->flags & WSMSG_WIN32_AOP)
|
|
? p_aop->b.lin_base : (char*)PTR_SEG_TO_LIN(p_aop->b.seg_base);
|
|
|
|
read(p_aop->fd[0], buffer, LOWORD(lLength));
|
|
switch( p_aop->flags & WSMSG_ASYNC_RQMASK )
|
|
{
|
|
case WSMSG_ASYNC_HOSTBYNAME:
|
|
case WSMSG_ASYNC_HOSTBYADDR:
|
|
fixup_wshe((struct ws_hostent*)buffer, p_aop->b.ptr_base); break;
|
|
case WSMSG_ASYNC_PROTOBYNAME:
|
|
case WSMSG_ASYNC_PROTOBYNUM:
|
|
fixup_wspe((struct ws_protoent*)buffer, p_aop->b.ptr_base); break;
|
|
case WSMSG_ASYNC_SERVBYNAME:
|
|
case WSMSG_ASYNC_SERVBYPORT:
|
|
fixup_wsse((struct ws_servent*)buffer, p_aop->b.ptr_base); break;
|
|
default:
|
|
if( p_aop->flags ) WARN(winsock,"Received unknown async request!\n");
|
|
return AOP_CONTROL_REMOVE;
|
|
}
|
|
}
|
|
else lLength = ((UINT32)LOWORD(lLength)) | ((unsigned)WSAENOBUFS << 16);
|
|
} /* failure */
|
|
|
|
/* was a __WS_ASYNC_DEBUG statement */
|
|
TRACE(winsock, "DNS aop completed: hWnd [%04x], uMsg [%04x], "
|
|
"aop [%04x], event [%08lx]\n",
|
|
p_aop->hWnd, p_aop->uMsg, __ws_gethandle(p_aop), (LPARAM)lLength);
|
|
|
|
/* FIXME: update num_async_rq */
|
|
EVENT_DeleteIO( p_aop->fd[0], EVENT_IO_READ );
|
|
PostMessage32A( p_aop->hWnd, p_aop->uMsg, __ws_gethandle(p_aop), (LPARAM)lLength );
|
|
|
|
return AOP_CONTROL_REMOVE; /* one-shot request */
|
|
}
|
|
|
|
|
|
HANDLE16 __WSAsyncDBQuery(LPWSINFO pwsi, HWND32 hWnd, UINT32 uMsg, INT32 type,
|
|
LPCSTR init, INT32 len, LPCSTR proto, void* sbuf, INT32 buflen, UINT32 flag)
|
|
{
|
|
/* queue 'flag' request and fork off its handler */
|
|
|
|
async_ctl.ws_aop = (ws_async_op*)__ws_memalloc(sizeof(ws_async_op));
|
|
|
|
if( async_ctl.ws_aop )
|
|
{
|
|
HANDLE16 handle = __ws_gethandle(async_ctl.ws_aop);
|
|
|
|
if( pipe(async_ctl.ws_aop->fd) == 0 )
|
|
{
|
|
async_ctl.rq.init = (char*)init;
|
|
async_ctl.ilength = len;
|
|
async_ctl.buffer = (char*)proto;
|
|
async_ctl.type = type;
|
|
|
|
async_ctl.ws_aop->hWnd = hWnd;
|
|
async_ctl.ws_aop->uMsg = uMsg;
|
|
async_ctl.ws_aop->b.ptr_base = sbuf;
|
|
async_ctl.ws_aop->buflen = buflen;
|
|
async_ctl.ws_aop->flags = flag;
|
|
async_ctl.ws_aop->aop_control = &aop_control;
|
|
|
|
WINSOCK_link_async_op( async_ctl.ws_aop );
|
|
|
|
EVENT_AddIO( async_ctl.ws_aop->fd[0], EVENT_IO_READ );
|
|
pwsi->num_async_rq++;
|
|
|
|
async_ctl.ws_aop->pid = fork();
|
|
if( async_ctl.ws_aop->pid )
|
|
{
|
|
TRACE(winsock, "\tasync_op = %04x (child %i)\n",
|
|
handle, async_ctl.ws_aop->pid);
|
|
|
|
close(async_ctl.ws_aop->fd[1]); /* write endpoint */
|
|
if( async_ctl.ws_aop->pid > 0 )
|
|
return __ws_gethandle(async_ctl.ws_aop);
|
|
|
|
/* fork() failed */
|
|
|
|
pwsi->num_async_rq--;
|
|
EVENT_DeleteIO( async_ctl.ws_aop->fd[0], EVENT_IO_READ );
|
|
close(async_ctl.ws_aop->fd[0]);
|
|
pwsi->err = WSAEWOULDBLOCK;
|
|
}
|
|
else
|
|
{
|
|
extern BOOL32 THREAD_InitDone;
|
|
|
|
THREAD_InitDone = FALSE;
|
|
/* child process */
|
|
|
|
close(async_ctl.ws_aop->fd[0]); /* read endpoint */
|
|
switch( flag & WSMSG_ASYNC_RQMASK )
|
|
{
|
|
case WSMSG_ASYNC_HOSTBYADDR:
|
|
case WSMSG_ASYNC_HOSTBYNAME:
|
|
WS_do_async_gethost(pwsi, flag);
|
|
break;
|
|
case WSMSG_ASYNC_PROTOBYNUM:
|
|
case WSMSG_ASYNC_PROTOBYNAME:
|
|
WS_do_async_getproto(pwsi, flag);
|
|
break;
|
|
case WSMSG_ASYNC_SERVBYPORT:
|
|
case WSMSG_ASYNC_SERVBYNAME:
|
|
WS_do_async_getserv(pwsi, flag);
|
|
break;
|
|
}
|
|
_exit(0); /* skip atexit()'ed cleanup */
|
|
}
|
|
}
|
|
else pwsi->err = wsaErrno(); /* failed to create pipe */
|
|
|
|
__ws_memfree((void*)async_ctl.ws_aop);
|
|
} else pwsi->err = WSAEWOULDBLOCK;
|
|
return 0;
|
|
}
|
|
|
|
static int _async_notify()
|
|
{
|
|
/* use half-duplex pipe to send variable length packets
|
|
* to the parent process */
|
|
|
|
write(async_ctl.ws_aop->fd[1], &async_ctl.ilength, sizeof(unsigned));
|
|
write(async_ctl.ws_aop->fd[1], async_ctl.buffer, async_ctl.ilength );
|
|
|
|
#ifndef __EMX__
|
|
kill(getppid(), SIGIO); /* simulate async I/O */
|
|
#endif
|
|
|
|
/* was a __WS_ASYNC_DEBUG statement */
|
|
TRACE(winsock, "handler - notify aop [%d, buf %d]\n",
|
|
async_ctl.ilength, async_ctl.ws_aop->buflen);
|
|
return 1;
|
|
}
|
|
|
|
static void _async_fail()
|
|
{
|
|
/* write a DWORD with error code (low word is zero) */
|
|
|
|
async_ctl.ilength =
|
|
(h_errno < 0) ? (unsigned)WSAMAKEASYNCREPLY( 0, wsaErrno() )
|
|
: (unsigned)WSAMAKEASYNCREPLY( 0, wsaHerrno() );
|
|
write(async_ctl.ws_aop->fd[1], &async_ctl.ilength, sizeof(unsigned) );
|
|
#ifndef __EMX__
|
|
kill(getppid(), SIGIO); /* simulate async I/O */
|
|
#endif
|
|
|
|
/* was a __WS_ASYNC_DEBUG statement */
|
|
TRACE(winsock, "handler - failed aop [%d, buf %d]\n",
|
|
async_ctl.ilength, async_ctl.ws_aop->buflen);
|
|
}
|
|
|
|
void dump_ws_hostent_offset(struct ws_hostent* wshe)
|
|
{
|
|
int i;
|
|
char* base = (char*)wshe;
|
|
unsigned* ptr;
|
|
|
|
DUMP("h_name = %08x\t[%s]\n",
|
|
(unsigned)wshe->h_name, base + (unsigned)wshe->h_name);
|
|
DUMP("h_aliases = %08x\t[%08x]\n",
|
|
(unsigned)wshe->h_aliases, (unsigned)(base+(unsigned)wshe->h_aliases));
|
|
ptr = (unsigned*)(base + (unsigned)wshe->h_aliases);
|
|
for(i = 0; ptr[i]; i++ )
|
|
{
|
|
DUMP("%i - %08x [%s]\n", i + 1, ptr[i], ((char*)base) + ptr[i]);
|
|
}
|
|
DUMP("h_length = %i\n", wshe->h_length);
|
|
}
|
|
|
|
void WS_do_async_gethost(LPWSINFO pwsi, unsigned flag )
|
|
{
|
|
int size = 0;
|
|
struct hostent* p_he;
|
|
|
|
close(async_ctl.ws_aop->fd[0]);
|
|
|
|
p_he = (flag & WSMSG_ASYNC_HOSTBYNAME)
|
|
? gethostbyname(async_ctl.rq.name)
|
|
: gethostbyaddr(async_ctl.rq.name,
|
|
async_ctl.ilength, async_ctl.type);
|
|
|
|
TRACE(winsock,"DNS: got hostent for [%s]\n", async_ctl.rq.name );
|
|
|
|
if( p_he ) /* convert to the Winsock format with internal pointers as offsets */
|
|
size = WS_dup_he(pwsi, p_he, WS_DUP_OFFSET |
|
|
((flag & WSMSG_WIN32_AOP) ? WS_DUP_LINEAR : WS_DUP_SEGPTR) );
|
|
if( size )
|
|
{
|
|
async_ctl.buffer = pwsi->buffer;
|
|
async_ctl.ilength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
|
|
_async_notify( flag );
|
|
}
|
|
else _async_fail();
|
|
}
|
|
|
|
void WS_do_async_getproto(LPWSINFO pwsi, unsigned flag )
|
|
{
|
|
int size = 0;
|
|
struct protoent* p_pe;
|
|
|
|
close(async_ctl.ws_aop->fd[0]);
|
|
p_pe = (flag & WSMSG_ASYNC_PROTOBYNAME)
|
|
? getprotobyname(async_ctl.rq.name)
|
|
: getprotobynumber(async_ctl.type);
|
|
|
|
TRACE(winsock,"DNS: got protoent for [%s]\n", async_ctl.rq.name );
|
|
|
|
if( p_pe ) /* convert to the Winsock format with internal pointers as offsets */
|
|
size = WS_dup_pe(pwsi, p_pe, WS_DUP_OFFSET |
|
|
((flag & WSMSG_WIN32_AOP) ? WS_DUP_LINEAR : WS_DUP_SEGPTR) );
|
|
if( size )
|
|
{
|
|
async_ctl.buffer = pwsi->buffer;
|
|
async_ctl.ilength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
|
|
_async_notify( flag );
|
|
}
|
|
else _async_fail();
|
|
}
|
|
|
|
void WS_do_async_getserv(LPWSINFO pwsi, unsigned flag )
|
|
{
|
|
int size = 0;
|
|
struct servent* p_se;
|
|
|
|
close(async_ctl.ws_aop->fd[0]);
|
|
p_se = (flag & WSMSG_ASYNC_SERVBYNAME)
|
|
? getservbyname(async_ctl.rq.name, async_ctl.buffer)
|
|
: getservbyport(async_ctl.type, async_ctl.buffer);
|
|
|
|
if( p_se ) /* convert to the Winsock format with internal pointers as offsets */
|
|
size = WS_dup_se(pwsi, p_se, WS_DUP_OFFSET |
|
|
((flag & WSMSG_WIN32_AOP) ? WS_DUP_LINEAR : WS_DUP_SEGPTR) );
|
|
if( size )
|
|
{
|
|
async_ctl.buffer = pwsi->buffer;
|
|
async_ctl.ilength = (unsigned)WSAMAKEASYNCREPLY( (UINT16)size, 0 );
|
|
_async_notify( flag );
|
|
}
|
|
else _async_fail();
|
|
}
|
|
|
|
/* ----------------------------------- helper functions -
|
|
*
|
|
* Raw results from the pipe contain internal pointers stored as
|
|
* offsets relative to the beginning of the buffer and we need
|
|
* to apply a fixup before passing them to applications.
|
|
*
|
|
* NOTE: It is possible to exploit the fact that fork() doesn't
|
|
* change the buffer address by storing fixed up pointers right
|
|
* in the handler. However, this will get in the way if we ever
|
|
* get around to implementing DNS helper daemon a-la Netscape 4.x.
|
|
*/
|
|
|
|
void fixup_wshe(struct ws_hostent* p_wshe, void* base)
|
|
{
|
|
/* add 'base' to ws_hostent pointers to convert them from offsets */
|
|
|
|
int i;
|
|
unsigned* p_aliases,*p_addr;
|
|
|
|
p_aliases = (unsigned*)((char*)p_wshe + (unsigned)p_wshe->h_aliases);
|
|
p_addr = (unsigned*)((char*)p_wshe + (unsigned)p_wshe->h_addr_list);
|
|
((unsigned)(p_wshe->h_name)) += (unsigned)base;
|
|
((unsigned)(p_wshe->h_aliases)) += (unsigned)base;
|
|
((unsigned)(p_wshe->h_addr_list)) += (unsigned)base;
|
|
for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
|
|
for(i=0;p_addr[i];i++) p_addr[i] += (unsigned)base;
|
|
}
|
|
|
|
void fixup_wspe(struct ws_protoent* p_wspe, void* base)
|
|
{
|
|
int i;
|
|
unsigned* p_aliases = (unsigned*)((char*)p_wspe + (unsigned)p_wspe->p_aliases);
|
|
((unsigned)(p_wspe->p_name)) += (unsigned)base;
|
|
((unsigned)(p_wspe->p_aliases)) += (unsigned)base;
|
|
for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
|
|
}
|
|
|
|
void fixup_wsse(struct ws_servent* p_wsse, void* base)
|
|
{
|
|
int i;
|
|
unsigned* p_aliases = (unsigned*)((char*)p_wsse + (unsigned)p_wsse->s_aliases);
|
|
((unsigned)(p_wsse->s_name)) += (unsigned)base;
|
|
((p_wsse->s_proto)) += (unsigned)base;
|
|
((p_wsse->s_aliases)) += (unsigned)base;
|
|
for(i=0;p_aliases[i];i++) p_aliases[i] += (unsigned)base;
|
|
}
|
|
|