? dcop.patch
? dcop.pro
? iceauth
? moc
? obj
? vc70.idb
? KDE-ICE/KDE-ICE.pro
? KDE-ICE/kde-ice.def
? KDE-ICE/kdeice_d.vcproj
? KDE-ICE/moc
? KDE-ICE/obj
? KDE-ICE/vc70.idb
? dcopidl/dcopidl.ilk
? dcopidl/dcopidl.patch
? dcopidl/dcopidl.pro
? dcopidl/dcopidl.sln
? dcopidl/dcopidl.suo
? dcopidl/kappdcopiface.h
? dcopidl/moc
? dcopidl/obj
? dcopidl/vc70.idb
? dcopidl/yacc.output
? dcopidl2cpp/dcopidl2cpp.ilk
? dcopidl2cpp/dcopidl2cpp.pro
? dcopidl2cpp/moc
? dcopidl2cpp/obj
? dcopidl2cpp/vc70.idb
? dcopserver/Makefile
? dcopserver/dcop-path.h
? dcopserver/dcopserver.ncb
? dcopserver/dcopserver.pro
? dcopserver/dcopserver.sln
? dcopserver/dcopserver.suo
? dcopserver/dcopserver.vcproj
? dcopserver/moc
? dcopserver/obj
? dcopserver/rebuild
? dcopserver/vc70.idb
? dcopserver_shutdown/Makefile
? dcopserver_shutdown/dcopserver_shutdown.cpp
? dcopserver_shutdown/dcopserver_shutdown.pro
? dcopserver_shutdown/moc
? dcopserver_shutdown/obj
? dcopserver_shutdown/vc70.idb
? tests/moc
? tests/obj
? tests/tests.pro
? tests/vc70.idb
Index: dcopclient.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopclient.cpp,v
retrieving revision 1.190
diff -u -r1.190 dcopclient.cpp
--- dcopclient.cpp	26 Mar 2005 12:31:10 -0000	1.190
+++ dcopclient.cpp	9 Apr 2005 21:38:04 -0000
@@ -69,12 +69,10 @@
 #include <X11/Xmd.h> 
 #endif
 extern "C" {
-#ifdef Q_OS_UNIX
 #include <KDE-ICE/ICElib.h>
 #include <KDE-ICE/ICEutil.h>
 #include <KDE-ICE/ICEmsg.h>
 #include <KDE-ICE/ICEproto.h>
-#endif
 }
 
 // #define DCOPCLIENT_DEBUG	1
@@ -116,16 +114,12 @@
 
 template class QPtrList<DCOPObjectProxy>;
 template class QPtrList<DCOPClientTransaction>;
-#ifdef Q_OS_UNIX
 template class QPtrList<_IceConn>;
-#endif
 
 struct DCOPClientMessage
 {
     int opcode;
-#ifdef Q_OS_UNIX
     CARD32 key;
-#endif
     QByteArray data;
 };
 
@@ -156,9 +150,7 @@
 public:
     DCOPClient *parent;
     QCString appId;
-#ifdef Q_OS_UNIX
     IceConn iceConn;
-#endif
     int majorOpcode; // major opcode negotiated w/server and used to tag all comms.
 
     int majorVersion, minorVersion; // protocol versions negotiated w/server
@@ -182,7 +174,6 @@
     Q_INT32 transactionId;
     int opcode;
 
-#ifdef Q_OS_UNIX
     // Special key values:
     // 0 : Not specified
     // 1 : DCOPSend
@@ -191,7 +182,6 @@
     CARD32 key;
     CARD32 currentKey; 
     CARD32 currentKeySaved;
-#endif
 
     QTimer postMessageTimer;
     QPtrList<DCOPClientMessage> messages;
@@ -214,14 +204,20 @@
 {
 public:
     Q_INT32 id;
-#ifdef Q_OS_UNIX
     CARD32 key;
-#endif
     QCString senderId;
 };
 
 QCString DCOPClient::iceauthPath()
 {
+#ifdef Q_OS_WIN32
+	char	szPath[512];
+	char *	pszFilePart;
+	int		ret;
+	ret = SearchPathA(NULL,"iceauth.exe",NULL,sizeof(szPath)/sizeof(szPath[0]),szPath,&pszFilePart);
+	if(ret != 0)
+		return QCString(szPath);
+#else
     QCString path = ::getenv("PATH");
     if (path.isEmpty())
         path = "/bin:/usr/bin";
@@ -237,6 +233,7 @@
    
         fPath = strtok(NULL, ":\b");
     }
+#endif
     return 0;
 }
 
@@ -246,7 +243,8 @@
     if (!old && !fName.isEmpty())
         return fName;
     
-    fName = ::getenv("HOME");
+	fName = QDir::homeDirPath();
+//    fName = ::getenv("HOME");
     if (fName.isEmpty())
     {
         fprintf(stderr, "Aborting. $HOME is not set.\n");
@@ -312,9 +310,7 @@
 
 const char* DCOPClientPrivate::serverAddr = 0;
 
-#ifdef Q_OS_UNIX
 static void DCOPProcessInternal( DCOPClientPrivate *d, int opcode, CARD32 key, const QByteArray& dataReceived, bool canPost  );
-#endif
 
 void DCOPClient::handleAsyncReply(ReplyStruct *replyStruct)
 {
@@ -329,7 +325,6 @@
     delete replyStruct;
 }
 
-#ifdef Q_OS_UNIX
 /**
  * Callback for ICE.
  */
@@ -435,11 +430,9 @@
         DCOPProcessInternal( d, opcode, key, dataReceived, true );
     }
 }
-#endif
 
 void DCOPClient::processPostedMessagesInternal()
 {
-#ifdef Q_OS_UNIX
     if ( d->messages.isEmpty() )
         return;
     QPtrListIterator<DCOPClientMessage> it (d->messages );
@@ -455,10 +448,8 @@
     }
     if ( !d->messages.isEmpty() )
         d->postMessageTimer.start( 100, true );
-#endif
 }
 
-#ifdef Q_OS_UNIX
 /**
    Processes DCOPCall, DCOPFind and DCOPSend
  */
@@ -583,7 +574,6 @@
 static IcePoVersionRec DCOPClientVersions[] = {
     { DCOPVersionMajor, DCOPVersionMinor,  DCOPProcessMessage }
 };
-#endif
 
 
 static DCOPClient* dcop_main_client = 0;
@@ -603,11 +593,9 @@
 {
     d = new DCOPClientPrivate;
     d->parent = this;
-#ifdef Q_OS_UNIX
     d->iceConn = 0L;
     d->key = 0;
     d->currentKey = 0;
-#endif
     d->majorOpcode = 0;
     d->appId = 0;
     d->notifier = 0L;
@@ -646,11 +634,9 @@
         delete msg;
     }
 #endif
-#ifdef Q_OS_UNIX
     if (d->iceConn)
         if (IceConnectionStatus(d->iceConn) == IceConnectAccepted)
             detach();
-#endif
 
     if (d->registered)
         unregisterLocalClient( d->appId );
@@ -755,7 +741,6 @@
 
 bool DCOPClient::attachInternal( bool registerAsAnonymous )
 {
-#ifdef Q_OS_UNIX
     char errBuf[1024];
 
     if ( isAttached() )
@@ -802,6 +787,8 @@
             }
             else
             {
+				if(contents[pos - 1] == '\r')	// check for windows end of line
+					pos--;
                 dcopSrv = QString::fromLatin1(contents.left( pos ));
 //#ifndef NDEBUG
 //                qDebug("dcopserver address: %s", dcopSrv.latin1());
@@ -882,15 +869,11 @@
         registerAs( "anonymous", true );
 
     return true;
-#else //!Q_OS_UNIX
-    return false;
-#endif
 }
 
 
 bool DCOPClient::detach()
 {
-#ifdef Q_OS_UNIX
     int status;
 
     if (d->iceConn) {
@@ -910,21 +893,14 @@
     d->registered = false;
     d->foreign_server = true;
     return true;
-#else //!Q_OS_UNIX
-    return false;
-#endif
 }
 
 bool DCOPClient::isAttached() const
 {
-#ifdef Q_OS_UNIX
     if (!d->iceConn)
         return false;
 
     return (IceConnectionStatus(d->iceConn) == IceConnectAccepted);
-#else //!Q_OS_UNIX
-    return false;
-#endif
 }
 
 bool DCOPClient::isAttachedToForeignServer() const
@@ -1014,10 +990,8 @@
 
 int DCOPClient::socket() const
 {
-#ifdef Q_OS_UNIX
     if (d->iceConn)
         return IceConnectionNumber(d->iceConn);
-#endif //Q_OS_UNIX
     return 0;
 }
 
@@ -1064,7 +1038,6 @@
 bool DCOPClient::send(const QCString &remApp, const QCString &remObjId,
                       const QCString &remFun, const QByteArray &data)
 {
-#ifdef Q_OS_UNIX
     if (remApp.isEmpty())
        return false;
     DCOPClient *localClient = findLocalClient( remApp );
@@ -1113,7 +1086,6 @@
 
     if (IceConnectionStatus(d->iceConn) == IceConnectAccepted)
         return true;
-#endif //Q_OS_UNIX
     return false;
 }
 
@@ -1836,14 +1808,10 @@
                       QCString& replyType, QByteArray &replyData,
                       bool useEventLoop, int timeout, int minor_opcode)
 {
-#ifdef Q_OS_UNIX
     ReplyStruct replyStruct;
     replyStruct.replyType = &replyType;
     replyStruct.replyData = &replyData;
     return callInternal(remApp, remObjId, remFun, data, &replyStruct, useEventLoop, timeout, minor_opcode);
-#else //!Q_OS_UNIX
-    return false;
-#endif
 }
 
 bool DCOPClient::callInternal(const QCString &remApp, const QCString &remObjId,
@@ -1851,7 +1819,6 @@
                       ReplyStruct *replyStruct,
                       bool useEventLoop, int timeout, int minor_opcode)
 {
-#ifdef Q_OS_UNIX
     if ( !isAttached() )
         return false;
 
@@ -2000,9 +1967,6 @@
 
     d->currentKey = oldCurrentKey;
     return replyStruct->status != ReplyStruct::Failed;
-#else //!Q_OS_UNIX
-    return false;
-#endif
 }
 
 void DCOPClient::eventLoopTimeout()
@@ -2012,7 +1976,6 @@
 
 void DCOPClient::processSocketData(int fd)
 {
-#ifdef Q_OS_UNIX
     // Make sure there is data to read!
     fd_set fds;
     timeval timeout;
@@ -2043,7 +2006,6 @@
         qWarning("received an error processing data from the DCOP server!");
         return;
     }
-#endif //Q_OS_UNIX
 }
 
 void DCOPClient::setDefaultObject( const QCString& objId )
@@ -2085,9 +2047,7 @@
     trans->id = ++d->transactionId;
     if (d->transactionId < 0)  // Ensure that ids > 0
         d->transactionId = 0;
-#ifdef Q_OS_UNIX
     trans->key = d->currentKey;
-#endif
 
     d->transactionList->append( trans );
 
@@ -2137,7 +2097,6 @@
         return;
     }
 
-#ifdef Q_OS_UNIX
     DCOPMsg *pMsg;
 
     QByteArray ba;
@@ -2150,7 +2109,6 @@
     pMsg->length += ba.size();
 
     IceSendData( d->iceConn, ba.size(), const_cast<char *>(ba.data()) );
-#endif
 
     delete trans;
 }
@@ -2240,7 +2198,6 @@
 void
 DCOPClient::setPriorityCall(bool b)
 {
-#ifdef Q_OS_UNIX
     if (b)
     {
        if (d->currentKey == 2)
@@ -2256,7 +2213,6 @@
        if ( !d->messages.isEmpty() )
           d->postMessageTimer.start( 0, true ); // Process queued messages
     }
-#endif
 }
 
 
@@ -2273,7 +2229,6 @@
        list.append(it.current());
        ++it;
     }
-#ifdef Q_OS_UNIX
     for(DCOPClient *cl = list.first(); cl; cl = list.next())
     {
         if (cl->d->iceConn) {
@@ -2282,7 +2237,6 @@
             cl->d->iceConn = 0L;
         }
     }
-#endif
 }
 
 const char *
Index: dcopglobal.h
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopglobal.h,v
retrieving revision 1.30
diff -u -r1.30 dcopglobal.h
--- dcopglobal.h	7 Sep 2004 11:54:40 -0000	1.30
+++ dcopglobal.h	11 Feb 2005 17:24:28 -0000
@@ -37,8 +37,6 @@
 #define DCOPReplyDelayed 6
 #define DCOPFind 7
 
-#ifdef Q_OS_UNIX
-
 #define INT32 QINT32
 #ifdef Q_WS_X11
 #include <X11/Xlib.h>
@@ -83,6 +81,4 @@
   CARD32 key;
 };
 
-#endif /* Q_OS_UNIX */
-
 #endif
Index: dcopserver.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopserver.cpp,v
retrieving revision 1.173
diff -u -r1.173 dcopserver.cpp
--- dcopserver.cpp	21 Feb 2005 23:52:16 -0000	1.173
+++ dcopserver.cpp	10 Apr 2005 11:41:24 -0000
@@ -66,7 +66,7 @@
 #include <string.h>
 #endif
 
-// #define DCOP_DEBUG
+//#define DCOP_DEBUG
 
 DCOPServer* the_server;
 
@@ -83,6 +83,14 @@
 
 static QCString findDcopserverShutdown()
 {
+#ifdef Q_OS_WIN32
+	char	szPath[512];
+	char *	pszFilePart;
+	int		ret;
+	ret = SearchPathA(NULL,"dcopserver_shutdown","exe",sizeof(szPath)/sizeof(szPath[0]),szPath,&pszFilePart);
+	if(ret != 0)
+		return QCString(szPath);
+#else
    QCString path = getenv("PATH");
    char *dir = strtok(path.data(), ":");
    while (dir)
@@ -97,7 +105,7 @@
    file += "/dcopserver_shutdown";
    if (access(file.data(), X_OK) == 0)
       return file;
-
+#endif
    return QCString("dcopserver_shutdown");
 }
 
@@ -148,6 +156,11 @@
    return result;
 }
 
+
+extern "C" {
+extern int _kde_IceTransWrite (void * ciptr, char *buf, int size);
+};
+
 static unsigned long writeIceData(IceConn iceConn, unsigned long nbytes, char *ptr)
 {
     int fd = IceConnectionNumber(iceConn);
@@ -157,12 +170,29 @@
 	int nwritten;
 
 	if (iceConn->io_ok)
+	{
+		
+//		nwritten = _kde_IceTransWrite (iceConn->trans_conn, ptr, (int) nleft);
+
+		/*
+		Use special write handling on windows platform. The write function from
+		the runtime library (on MSVC) does not allow to write on sockets.
+		*/
+
+#ifdef Q_OS_WIN
+		nwritten = send(fd, ptr, (int) nleft, 0);
+#else
 	    nwritten = write(fd, ptr, (int) nleft);
+#endif
+
+	}
 	else
 	    return 0;
 
 	if (nwritten <= 0)
 	{
+			qDebug("write failed, errno %s (%i), %i",strerror(errno),errno,GetLastError());
+			
             if (errno == EINTR)
                continue;
 
@@ -224,7 +254,7 @@
 {
     DCOPConnection* conn = the_server->findConn( iceConn );
 #ifdef DCOP_DEBUG
-qWarning("DCOPServer: DCOPIceWriteChar() Writing %d bytes to %d [%s]", nbytes, fd, conn ? conn->appId.data() : "<unknown>");
+	qWarning("DCOPServer: DCOPIceWriteChar() Writing %d bytes to [%s]", nbytes, conn ? conn->appId.data() : "<unknown>");
 #endif
 
     if (conn)
@@ -256,7 +286,7 @@
 {
     DCOPConnection* conn = the_server->findConn( iceConn );
 #ifdef DCOP_DEBUG
-qWarning("DCOPServer: DCOPIceWrite() Writing %d bytes to %d [%s]", _data.size(), fd, conn ? conn->appId.data() : "<unknown>");
+qWarning("DCOPServer: DCOPIceWrite() Writing %d bytes to [%s]", _data.size(), conn ? conn->appId.data() : "<unknown>");
 #endif
     if (conn)
     {
@@ -323,7 +353,24 @@
 
    long fd_fl = fcntl(fd, F_GETFL, 0);
    fcntl(fd, F_SETFL, fd_fl | O_NDELAY);
-   int nwritten = write(fd, data.data()+outputBufferStart, data.size()-outputBufferStart);
+   /*
+	Use special write handling on windows platform. The write function from
+	the runtime library (on MSVC) does not allow to write on sockets.
+   */
+   int nwritten;
+#ifdef Q_OS_WIN
+   ::send(fd,data.data()+outputBufferStart,data.size()-outputBufferStart,0);
+/*
+	DWORD dwWritten;
+	if(WriteFile((HANDLE)fd,data.data()+outputBufferStart,data.size()-outputBufferStart,&dwWritten,NULL))
+		nwritten = (int)dwWritten;
+	else
+		nwritten = -1;
+*/
+#else
+    nwritten = write(fd, data.data()+outputBufferStart, data.size()-outputBufferStart);
+#endif
+   
    int e = errno;
    fcntl(fd, F_SETFL, fd_fl);
 
@@ -525,12 +572,25 @@
     char tempFile[PATH_MAX];
     char *ptr;
 
+#ifdef Q_OS_WIN
+    snprintf (tempFile, PATH_MAX, "%s\\%sXXXXXX", path, prefix);
+#else
     snprintf (tempFile, PATH_MAX, "%s/%sXXXXXX", path, prefix);
+#endif
     ptr = static_cast<char *>(malloc(strlen(tempFile) + 1));
     if (ptr != NULL)
 	{
+		int fd = mkstemps(tempFile, 0);
+		if(fd >= 0)
+		{
+			*pFd = fd;
 	    strcpy(ptr, tempFile);
-	    *pFd =  mkstemps(ptr, 0);
+		}
+		else
+		{
+			free(ptr);
+			ptr = NULL;
+		}
 	}
     return ptr;
 }
@@ -550,9 +610,21 @@
 
     original_umask = umask (0077);      /* disallow non-owner access */
 
+#ifdef Q_OS_WIN
+	char temppath[512];
+	DWORD dw = GetTempPathA(sizeof(temppath),temppath);
+	if(dw != 0)
+	{
+		temppath[dw - 1] = 0;
+		path = temppath;
+	}
+	else
+		path = ".";
+#else
     path = getenv ("DCOP_SAVE_DIR");
     if (!path)
 	path = "/tmp";
+#endif
     if ((addAuthFile = unique_filename (path, "dcop", &fd)) == NULL)
 	goto bad;
 
@@ -884,7 +956,7 @@
 					    int majorVersion, int minorVersion,
 					    char* vendor, char* release,
 					    IcePointer *clientDataRet,
-					    char **/*failureReasonRet*/)
+					    char ** /*failureReasonRet*/)
 {
     /*
      * vendor/release are undefined for ProtocolSetup in DCOP
@@ -900,6 +972,7 @@
     return (majorVersion == DCOPVersionMajor && minorVersion == DCOPVersionMinor);
 }
 
+#ifndef Q_OS_WIN
 static int pipeOfDeath[2];
 
 static void sighandler(int sig)
@@ -911,18 +984,24 @@
 
     write(pipeOfDeath[1], "x", 1);
 }
+#endif
+
+extern "C"
+{
+	extern int _kde_IceLastMajorOpcode; // from libICE
+};
 
 DCOPServer::DCOPServer(bool _suicide)
-    : QObject(0,0), currentClientNumber(0), appIds(263), clients(263)
+    : QObject(0, 0), currentClientNumber(0), appIds(263), clients(263)
 {
-    serverKey = 42;
+	serverKey = 42;
 
     suicide = _suicide;
     shutdown = false;
 
     dcopSignals = new DCOPSignals;
 
-    extern int _kde_IceLastMajorOpcode; // from libICE
+    
     if (_kde_IceLastMajorOpcode < 1 )
         IceRegisterForProtocolSetup(const_cast<char *>("DUMMY"),
 				    const_cast<char *>("DUMMY"),
@@ -976,12 +1055,14 @@
 	    }
 	    fprintf(f, "\n%i\n", getpid());
 	    fclose(f);
+#ifndef Q_OS_WIN32
 	    if (QCString(getenv("DCOPAUTHORITY")).isEmpty())
 	    {
                 // Create a link named like the old-style (KDE 2.x) naming
                 QCString compatName = DCOPClient::dcopServerFileOld();
                 ::symlink(fName,compatName);
             }
+#endif // Q_OS_WIN32
 	}
 
 #if 0
@@ -1010,6 +1091,19 @@
     m_deadConnectionTimer = new QTimer(this);
     connect( m_deadConnectionTimer, SIGNAL(timeout()), this, SLOT(slotCleanDeadConnections()) );
 
+#ifdef Q_OS_WIN
+	DWORD dwThreadId;
+	QString strPID;
+	strPID.sprintf("%i",GetCurrentProcessId());
+	QString fName = DCOPClient::dcopServerFile();
+	fName += strPID;
+	m_evTerminate = CreateEvent(NULL,TRUE,FALSE,(LPCTSTR)fName.unicode());
+	ResetEvent(m_evTerminate);
+	HANDLE hThread = CreateThread(NULL,0,TerminatorThread,this,0,&dwThreadId);
+	if(hThread)
+		CloseHandle(hThread);
+#endif
+
 #ifdef DCOP_LOG
     char hostname_buffer[256];
     memset( hostname_buffer, 0, sizeof( hostname_buffer ) );
@@ -1033,8 +1127,25 @@
     m_logger->close();
     delete m_logger;
 #endif
+#ifdef Q_OS_WIN
+	SetEvent(m_evTerminate);
+	CloseHandle(m_evTerminate);
+#endif
 }
 
+#ifdef Q_OS_WIN
+DWORD WINAPI DCOPServer::TerminatorThread(void * pParam)
+{
+DCOPServer * server = (DCOPServer*)pParam;
+	
+	WaitForSingleObject(server->m_evTerminate,INFINITE);
+	if(!server->shutdown)
+	{
+		server->slotShutdown();
+	}
+	return 0;
+}
+#endif
 
 DCOPConnection* DCOPServer::findApp( const QCString& appId )
 {
@@ -1096,8 +1207,10 @@
 
     IceSetShutdownNegotiation( iceConn, False );
 
+	printf("newClient\n");
     IceConnectStatus cstatus;
     while ((cstatus = IceConnectionStatus (iceConn))==IceConnectPending) {
+		printf("ProcessMsg\n");
 	(void) IceProcessMessages( iceConn, 0, 0 );
     }
 
@@ -1109,6 +1222,10 @@
         deadConnections.removeRef(iceConn);
 	(void) IceCloseConnection (iceConn);
     }
+	else
+	{
+		qDebug("New connection accepted");
+	}
 }
 
 void* DCOPServer::watchConnection( IceConn iceConn )
@@ -1243,7 +1360,9 @@
     fprintf( stderr, "DCOPServer : slotShutdown() -> waiting for clients to disconnect.\n" );
 #endif
     char c;
+#ifndef Q_OS_WIN
     read(pipeOfDeath[0], &c, 1);
+#endif
     if (!shutdown)
     {
        shutdown = true;
@@ -1568,6 +1687,25 @@
     return false;
 }
 
+#ifdef Q_OS_WIN
+BOOL WINAPI dcopServerConsoleProc(DWORD dwCtrlType)
+{
+BOOL	ret;
+	switch(dwCtrlType)
+	{
+	case	CTRL_CLOSE_EVENT:
+	case	CTRL_C_EVENT:
+		system(findDcopserverShutdown()+" --nokill");
+		ret = TRUE;
+		break;
+	default:
+		ret = FALSE;
+	}
+	return ret;
+}
+#endif 
+
+
 const char* const ABOUT =
 "Usage: dcopserver [--nofork] [--nosid] [--help]\n"
 "       dcopserver --serverid\n"
@@ -1581,6 +1719,7 @@
 
 extern "C" DCOP_EXPORT int kdemain( int argc, char* argv[] )
 {
+
     bool serverid = false;
     bool nofork = false;
     bool nosid = false;
@@ -1612,6 +1751,7 @@
     // check if we are already running
     if (isRunning(DCOPClient::dcopServerFile()))
        return 0;
+#ifndef Q_OS_WIN32
     if (QCString(getenv("DCOPAUTHORITY")).isEmpty() &&
         isRunning(DCOPClient::dcopServerFileOld()))
     {
@@ -1639,9 +1779,10 @@
           }
        }
     }
-
+#endif
     pipe(ready);
 
+#ifndef Q_OS_WIN32
     if (!nofork) {
         pid_t pid = fork();
 	if (pid > 0) {
@@ -1669,22 +1810,32 @@
 	if (fork() > 0)
 	    return 0; // get rid of controlling terminal
     }
-
-    pipe(pipeOfDeath);
+	pipe(pipeOfDeath);
 
     signal(SIGHUP, sighandler);
     signal(SIGTERM, sighandler);
     signal(SIGPIPE, SIG_IGN);
-
-    putenv(strdup("SESSION_MANAGER="));
+#else
+	{
+		char c = 1;
+		close(ready[1]);
+		read(ready[0], &c, 1); // Wait till dcopserver is started
+		close(ready[0]);
+	}
+#endif
+	putenv(strdup("SESSION_MANAGER="));
 
     QApplication a( argc, argv, false );
 
     IceSetIOErrorHandler (IoErrorHandler );
     DCOPServer *server = new DCOPServer(suicide); // this sets the_server
 
+#ifdef Q_OS_WIN
+	SetConsoleCtrlHandler(dcopServerConsoleProc,TRUE);
+#else
     QSocketNotifier DEATH(pipeOfDeath[0], QSocketNotifier::Read, 0, 0);
     server->connect(&DEATH, SIGNAL(activated(int)), SLOT(slotShutdown()));
+#endif
 
     int ret = a.exec();
     delete server;
Index: dcopserver.h
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopserver.h,v
retrieving revision 1.38
diff -u -r1.38 dcopserver.h
--- dcopserver.h	21 Feb 2005 23:52:16 -0000	1.38
+++ dcopserver.h	9 Apr 2005 20:52:36 -0000
@@ -24,8 +24,6 @@
 
 #include <qobject.h>
 
-#ifdef Q_OS_UNIX //not available yet for win32
-
 #include <qstring.h>
 #include <qsocketnotifier.h>
 #include <qptrlist.h>
@@ -151,6 +149,11 @@
 private:
     void broadcastApplicationRegistration( DCOPConnection* conn, const QCString type,
         const QString& data );
+
+#ifdef Q_OS_WIN
+	static DWORD WINAPI TerminatorThread(void * pParam);
+#endif
+
     bool suicide;
     bool shutdown;
     int majorOpcode;
@@ -165,6 +168,10 @@
     QIntDict<DCOPConnection> fd_clients; // index on fd
     QPtrList<_IceConn> deadConnections;
 
+#ifdef Q_OS_WIN
+	HANDLE			m_evTerminate;
+#endif
+
 #ifdef DCOP_LOG
     QTextStream *m_stream;
     QFile *m_logger;
@@ -173,6 +180,5 @@
 
 extern DCOPServer* the_server;
 
-#endif //Q_OS_UNIX
 
 #endif
Index: dcopsignals.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/dcopsignals.cpp,v
retrieving revision 1.9
diff -u -r1.9 dcopsignals.cpp
--- dcopsignals.cpp	7 Sep 2004 11:50:57 -0000	1.9
+++ dcopsignals.cpp	11 Feb 2005 17:25:10 -0000
@@ -37,7 +37,6 @@
 void
 DCOPSignals::emitSignal( DCOPConnection *conn, const QCString &_fun, const QByteArray &data, bool excludeSelf)
 {
-#ifdef Q_OS_UNIX
    QCString senderObj;
    QCString fun = _fun;
    int i = fun.find('#');
@@ -82,7 +81,6 @@
                                  current->slot, data);
       }
    }
-#endif //Q_OS_UNIX
 }
 
 /**
@@ -101,7 +99,6 @@
                        DCOPConnection *conn, const QCString &receiverObj,
                        const QCString &slot, bool Volatile)
 {
-#ifdef Q_OS_UNIX
    // TODO: Check if signal and slot match
    QCString signalArgs, slotArgs;
    int i,j;
@@ -157,9 +154,6 @@
    if (senderConn)
       senderConn->signalConnectionList()->append(current);
    return true;
-#else //!Q_OS_UNIX
-   return false;
-#endif
 }
 
 /**
@@ -190,7 +184,6 @@
    DCOPSignalConnection *next = 0;
    bool result = false;
 
-#ifdef Q_OS_UNIX
    for(DCOPSignalConnection *current = list->first(); current; current = next)
    {
       next = list->next();
@@ -225,7 +218,6 @@
          current->senderConn->signalConnectionList()->removeRef(current);
       delete current;
    }
-#endif //Q_OS_UNIX
    return result;
 }
 
@@ -238,7 +230,6 @@
 void
 DCOPSignals::removeConnections(DCOPConnection *conn, const QCString &obj)
 {
-#ifdef Q_OS_UNIX
    DCOPSignalConnectionList *list = conn->_signalConnectionList;
    if (!list)
       return; // Nothing to do...
@@ -278,7 +269,6 @@
       list->removeRef(current);
       delete current;
    }
-#endif //Q_OS_UNIX
 }
 
 
Index: testdcop.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/testdcop.cpp,v
retrieving revision 1.31
diff -u -r1.31 testdcop.cpp
--- testdcop.cpp	15 Jan 2004 14:12:12 -0000	1.31
+++ testdcop.cpp	6 Apr 2005 17:09:38 -0000
@@ -171,7 +171,9 @@
    qWarning("Value = %s", arg1.latin1());
 }
 
-int main(int argc, char **argv)
+extern KDEWIN32_EXPORT void kde_bootstrap();
+
+int kdemain(int argc, char **argv)
 {
   KApplication app(argc, argv, "testdcop");
 
Index: KDE-ICE/Xtrans.c
===================================================================
RCS file: /home/kde/kdelibs/dcop/KDE-ICE/Xtrans.c,v
retrieving revision 1.8
diff -u -r1.8 Xtrans.c
--- KDE-ICE/Xtrans.c	2 Jun 2004 20:28:25 -0000	1.8
+++ KDE-ICE/Xtrans.c	12 Feb 2005 17:10:28 -0000
@@ -176,7 +176,8 @@
      * a case insensitive match.
      */
 
-    strncpy (protobuf, protocol, PROTOBUFSIZE);
+    strncpy (protobuf, protocol, PROTOBUFSIZE - 1);
+    protobuf[PROTOBUFSIZE-1] = '\0';
 
     for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++)
 	if (isupper (protobuf[i]))
@@ -230,7 +231,9 @@
 
     _protocol = mybuf;
 
-    if ((mybuf = strpbrk (mybuf,"/:")) == NULL)
+
+   if ( ((mybuf = strchr (mybuf,'/')) == NULL) &&
+      ((mybuf = strrchr (tmpptr,':')) == NULL) )
     {
 	/* address is in a bad format */
 	*protocol = NULL;
@@ -243,7 +246,7 @@
     if (*mybuf == ':')
     {
 	/*
-	 * If there is a hostname, then assume inet, otherwise
+	 * If there is a hostname, then assume tcp, otherwise
 	 * it must be local.
 	 */
 	if (mybuf == tmpptr)
Index: KDE-ICE/Xtranssock.c
===================================================================
RCS file: /home/kde/kdelibs/dcop/KDE-ICE/Xtranssock.c,v
retrieving revision 1.11
diff -u -r1.11 Xtranssock.c
--- KDE-ICE/Xtranssock.c	21 Feb 2005 23:52:16 -0000	1.11
+++ KDE-ICE/Xtranssock.c	9 Apr 2005 10:07:24 -0000
@@ -107,13 +107,22 @@
 
 #else /* !WIN32 */
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <winsock2.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <io.h>
+#else
 #include <X11/Xwinsock.h>
 #include <X11/Xw32defs.h>
+#endif
 #undef close
 #define close closesocket
 #define ECONNREFUSED WSAECONNREFUSED
 #define EADDRINUSE WSAEADDRINUSE
 #define EPROTOTYPE WSAEPROTOTYPE
+#define EINPROGRESS WSAEINPROGRESS
 #undef EWOULDBLOCK
 #define EWOULDBLOCK WSAEWOULDBLOCK
 #undef EINTR
@@ -705,7 +714,7 @@
     return -1;
 }
 
-
+#ifdef UNIXCONN
 static int
 set_sun_path(const char *port, const char *upath, char *path)
 {
@@ -726,6 +735,7 @@
     }
     return 0;
 }
+#endif
 
 #ifdef TRANS_SERVER
 
@@ -1065,7 +1075,7 @@
     int namelen = sizeof(sockname);
 #endif
 
-    PRMSG (2, "SocketINETAccept(%x,%d)\n", ciptr, ciptr->fd, 0);
+    PRMSG (2, "SocketINETAccept(%p,%d)\n", ciptr, ciptr->fd, 0);
 
     if ((newciptr = (XtransConnInfo) xcalloc (
 	1, sizeof(struct _XtransConnInfo))) == NULL)
@@ -1145,7 +1155,7 @@
     int namelen = sizeof sockname;
 #endif
 
-    PRMSG (2, "SocketUNIXAccept(%x,%d)\n", ciptr, ciptr->fd, 0);
+    PRMSG (2, "SocketUNIXAccept(%p,%d)\n", ciptr, ciptr->fd, 0);
 
     if ((newciptr = (XtransConnInfo) xcalloc (
 	1, sizeof(struct _XtransConnInfo))) == NULL)
@@ -1288,7 +1298,11 @@
 
     if (tmpaddr == -1)
     {
+#ifdef WIN32
+		if ((hostp = gethostbyname(host)) == NULL)
+#else
 	if ((hostp = gethostbyname(host,hparams)) == NULL)
+#endif
 	{
 	    PRMSG (1,"SocketINETConnect: Can't get address for %s\n",
 		  host, 0, 0);
@@ -1745,7 +1759,7 @@
 TRANS(SocketINETClose) (XtransConnInfo ciptr)
 
 {
-    PRMSG (2,"SocketINETClose(%x,%d)\n", ciptr, ciptr->fd, 0);
+    PRMSG (2,"SocketINETClose(%x,%d)\n", ciptr, ciptr->fd, 0);	
 
     return close (ciptr->fd);
 }
Index: KDE-ICE/Xtransutil.c
===================================================================
RCS file: /home/kde/kdelibs/dcop/KDE-ICE/Xtransutil.c,v
retrieving revision 1.8
diff -u -r1.8 Xtransutil.c
--- KDE-ICE/Xtransutil.c	2 Jun 2004 20:28:25 -0000	1.8
+++ KDE-ICE/Xtransutil.c	7 Apr 2005 18:01:00 -0000
@@ -61,9 +61,10 @@
  * of these values are also defined by the ChangeHost protocol message.
  */
 
-#define FamilyInternet		0
+#define FamilyInternet		0	/* IPv4 */
 #define FamilyDECnet		1
 #define FamilyChaos		2
+#define FamilyInternet6		6
 #define FamilyAmoeba		33
 #define FamilyLocalHost		252
 #define FamilyKrb5Principal	253
@@ -281,7 +282,7 @@
 static jmp_buf env;
 
 #ifdef SIGALRM
-static int nameserver_timedout = 0;
+static volatile int nameserver_timedout = 0;
 
 static
 #ifdef SIGNALRETURNSINT
@@ -333,7 +334,7 @@
 	struct sockaddr_in *saddr = (struct sockaddr_in *) peer_addr;
 	struct hostent * hostp = NULL;
 
-#ifdef SIGALRM
+#if defined(SIGALRM) && !defined(WIN32)
 	/*
 	 * gethostbyaddr can take a LONG time if the host does not exist.
 	 * Assume that if it does not respond in NAMESERVER_TIMEOUT seconds
@@ -349,7 +350,7 @@
 #endif
 	    hostp = gethostbyaddr ((char *) &saddr->sin_addr,
 		sizeof (saddr->sin_addr), AF_INET);
-#ifdef SIGALRM
+#if defined(SIGALRM) && !defined(WIN32)
 	}
 	alarm (0);
 #endif
Index: KDE-ICE/authutil.c
===================================================================
RCS file: /home/kde/kdelibs/dcop/KDE-ICE/authutil.c,v
retrieving revision 1.5
diff -u -r1.5 authutil.c
--- KDE-ICE/authutil.c	2 Jun 2004 20:28:25 -0000	1.5
+++ KDE-ICE/authutil.c	14 Feb 2005 06:08:40 -0000
@@ -81,7 +81,11 @@
 IceAuthFileName ()
 
 {
+#ifdef WIN32
+    static char slashDotICEauthority[] = "\\.ICEauthority";
+#else
     static char slashDotICEauthority[] = "/.ICEauthority";
+#endif
     char    	*name;
     static char	*buf;
     static int	bsize;
@@ -99,12 +103,18 @@
     if (!name)
     {
 #ifdef WIN32
-	strcpy (dir, "/users/");
-	if (name = getenv ("USERNAME"))
-	{
-	    strcat (dir, name);
-	    name = dir;
+		if(name = getenv ("HOMEDRIVE"))
+		{
+			strcpy (dir, name);
+			if(name = getenv ("HOMEPATH"))
+				strcat (dir, name);
 	}
+		else
+		{
+			if(name = getenv ("USERPROFILE"))
+				strcpy (dir, name);
+    }
+		name = dir;
 	if (!name)
 #endif
 #ifdef __EMX__
Index: KDE-ICE/listen.c
===================================================================
RCS file: /home/kde/kdelibs/dcop/KDE-ICE/listen.c,v
retrieving revision 1.4
diff -u -r1.4 listen.c
--- KDE-ICE/listen.c	2 Jun 2004 20:28:25 -0000	1.4
+++ KDE-ICE/listen.c	12 Feb 2005 11:41:58 -0000
@@ -55,9 +55,14 @@
 
     while ((result < 0) && (count < 5))
     {
-       char buf[128];
-       sprintf(buf, "dcop%d-%ld", getpid(), time(NULL)+count);
-       result = _kde_IceTransMakeAllCOTSServerListeners (buf, &partial,
+       char port[128];
+#ifdef WIN32
+       int nTCPPort = ((getpid() + time(NULL) + count) % 32768) + 1024;
+       sprintf(port, "%d", nTCPPort);
+#else
+       sprintf(port, "dcop%d-%ld", getpid(), time(NULL)+count);
+#endif
+       result = _kde_IceTransMakeAllCOTSServerListeners (port, &partial,
                                               &transCount, &transConns);
        count++;
     }
Index: client/dcop.cpp
===================================================================
RCS file: /home/kde/kdelibs/dcop/client/dcop.cpp,v
retrieving revision 1.45
diff -u -r1.45 dcop.cpp
--- client/dcop.cpp	23 Jan 2005 21:27:28 -0000	1.45
+++ client/dcop.cpp	7 Apr 2005 17:49:52 -0000
@@ -78,7 +78,7 @@
 
 bool endsWith(QCString &id, char c)
 {
-   if (id.length() && (id[id.length()-1] == c))
+   if (id.length() && (id[(int)id.length()-1] == c))
    {
       id.truncate(id.length()-1);
       return true;
