Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 88778 Details for
Bug 196435
Eliminate jvm activation on AC startup
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
updated patch
196435_1.txt (text/plain), 27.15 KB, created by
Igor Alelekov
on 2008-02-04 10:13:21 EST
(
hide
)
Description:
updated patch
Filename:
MIME Type:
Creator:
Igor Alelekov
Created:
2008-02-04 10:13:21 EST
Size:
27.15 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.tptp.platform.agentcontroller >Index: src-native-new/src/shared/TPTPUtil/TPTUtil.def >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/shared/TPTPUtil/TPTUtil.def,v >retrieving revision 1.30 >diff -u -r1.30 TPTUtil.def >--- src-native-new/src/shared/TPTPUtil/TPTUtil.def 14 Jan 2008 07:49:59 -0000 1.30 >+++ src-native-new/src/shared/TPTPUtil/TPTUtil.def 4 Feb 2008 15:06:54 -0000 >@@ -101,4 +101,7 @@ > getExecutableName > readStringFromBuffer > vrfusrpwd >+ validateDirectory >+ isAbsolutePath >+ getTempDir > >\ No newline at end of file >Index: src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp,v >retrieving revision 1.38 >diff -u -r1.38 TPTPUtil.cpp >--- src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp 14 Jan 2008 07:49:59 -0000 1.38 >+++ src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp 4 Feb 2008 15:06:54 -0000 >@@ -846,6 +846,45 @@ > return statBuf.st_size; > } > >+int validateDirectory(char* dirName) { >+ struct STAT statBuf; >+ >+ if (STAT(dirName, &statBuf) != 0) { >+ return 0; >+ } >+ >+ return (S_ISDIR(statBuf.st_mode)) ? 1 : 0; >+} >+ >+int isAbsolutePath(const char* path) { >+ int n; >+ >+ if (path == NULL) return 0; >+ >+ n = strlen(path); >+ if (n == 0) return 0; >+ >+#ifdef _WIN32 >+ if(n >= 3 && isalpha(*path) && *(path+1)==':' && *(path+2)=='\\') return 1; >+ return (*path == '\\') ? 1 : 0; >+#else >+ return (*path == '/') ? 1 : 0; >+#endif >+} >+ >+char* getTempDir() { >+ char* dir; >+ >+ dir = getenv("TEMP"); >+ if(dir != NULL) return dir; >+ >+#ifdef _WIN32 >+ return "C:\\tmp"; >+#else >+ return "/tmp"; >+#endif >+} >+ > int getConfigElementName( const char* cmdStr, char** elemName) > { > int i=0; >Index: src-native-new/src/transport/TPTPClientCompTL/TPTPClientCompTL.dsp >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/TPTPClientCompTL.dsp,v >retrieving revision 1.11 >diff -u -r1.11 TPTPClientCompTL.dsp >--- src-native-new/src/transport/TPTPClientCompTL/TPTPClientCompTL.dsp 25 Jan 2008 10:47:07 -0000 1.11 >+++ src-native-new/src/transport/TPTPClientCompTL/TPTPClientCompTL.dsp 4 Feb 2008 15:06:54 -0000 >@@ -118,6 +118,10 @@ > # End Source File > # Begin Source File > >+SOURCE=.\nativeFileServer.c >+# End Source File >+# Begin Source File >+ > SOURCE=.\RACClientSupport.c > # End Source File > # Begin Source File >@@ -166,6 +170,10 @@ > # End Source File > # Begin Source File > >+SOURCE=.\nativeFileServer.h >+# End Source File >+# Begin Source File >+ > SOURCE=.\RACClientSupport.h > # End Source File > # Begin Source File >Index: src-native-new/src/transport/TPTPClientCompTL/ClientCTL.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/ClientCTL.h,v >retrieving revision 1.24 >diff -u -r1.24 ClientCTL.h >--- src-native-new/src/transport/TPTPClientCompTL/ClientCTL.h 1 Nov 2006 22:47:17 -0000 1.24 >+++ src-native-new/src/transport/TPTPClientCompTL/ClientCTL.h 4 Feb 2008 15:06:54 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2006 Intel Corporation. >+ * Copyright (c) 2005, 2008 Intel Corporation. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -35,6 +35,7 @@ > BOOL isDataMultiplexed; > BOOL isPolling; > TID pollingThread; >+ BOOL isJavaUnsecuredFileServer; > > /* Peer monitoring related fields */ > int usePeerAttachPort; >Index: src-native-new/src/transport/TPTPClientCompTL/ClientCTL.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/ClientCTL.c,v >retrieving revision 1.45 >diff -u -r1.45 ClientCTL.c >--- src-native-new/src/transport/TPTPClientCompTL/ClientCTL.c 25 Jan 2008 10:47:07 -0000 1.45 >+++ src-native-new/src/transport/TPTPClientCompTL/ClientCTL.c 4 Feb 2008 15:06:54 -0000 >@@ -17,6 +17,7 @@ > #include <sys/socket.h> > #endif > >+#include <string.h> > #include "tptp/TPTPTypes.h" > #include "tptp/TPTPSupportTypes.h" > #include "tptp/TransportSupport.h" >@@ -39,6 +40,9 @@ > extern void *processPollingThread(void *args); > #endif > >+THREAD_USER_FUNC_RET_TYPE startNativeFileServer(LPVOID args); >+extern int stopNativeFileServer(); >+ > /** > ********************************************************* > * >@@ -59,6 +63,7 @@ > tptp_string *isDataMultiplexed; > tptp_string *processPolling; > tptp_string *securityEnabled; >+ tptp_string *fileServer; > > rc = baseTL_createTransportListener( cmo, pTransportData, tlo, "Client Compatibility TL" ); > if ( ( rc == 0 ) && (tlo != NULL) && (tlo->data != NULL) ) >@@ -191,18 +196,44 @@ > cctlData->isPolling = TRUE; > } > >- >+ rc = getConfigurationString(pTransportData->configurationData, "JavaUnsecuredFileServer", &fileServer); >+ if (rc ==0 ) { >+#ifdef _WIN32 >+#ifdef _WIN64 >+ if (0 == strcasecmp(processPolling, "true")) >+#else >+ if (0 == strcmpi(processPolling, "true")) >+#endif >+#else >+ if (0 == strcasecmp(processPolling, "true")) >+#endif >+ { >+ cctlData->isJavaUnsecuredFileServer = TRUE; >+ } >+ else { >+ cctlData->isJavaUnsecuredFileServer = FALSE; >+ } >+ >+ tptp_free(fileServer); >+ } >+ else { >+ cctlData->isJavaUnsecuredFileServer = FALSE; >+ } >+ > /* Assume NO Security for now !!! */ >- /******************************/ >+ > /* Create JVM */ >- rc = tptpCreateJavaVitualMachine(stateData, NULL); >- if (rc == 0) { >- jvmCreated = TRUE; >- } >- else >- { >- TPTP_LOG_WARNING_MSG( stateData, "Cannot create JVM and therefore cannot create file server" ); >- jvmCreated = FALSE; >+ if (cctlData->isJavaUnsecuredFileServer || cctlData->securityEnabled) { >+ if (tptpCreateJavaVitualMachine(stateData, NULL) == 0) { >+ jvmCreated = TRUE; >+ } >+ else { >+ jvmCreated = FALSE; >+ TPTP_LOG_ERROR_MSG(stateData, "Cannot create JVM"); >+ } >+ } >+ else { >+ jvmCreated = FALSE; // skip jvm > } > > /* Start createFileServer */ >@@ -242,25 +273,20 @@ > } > > if(isValid) { >- /* Start secure file server... this needs to be done after vairiables are read from config */ >+ /* Start secure java file server... this needs to be done after vairiables are read from config */ > startSecuredFileServer(stateData, &_fileServerTID); > /* Start the secured file server */ > startSecuredServer(stateData, &_secsvrtid); > } > else { >- TPTP_LOG_ERROR_MSG( stateData, "Cannot start secured server. Some required parameters are missing from the configuration file" ); >+ TPTP_LOG_ERROR_MSG( stateData, "Cannot start secured server. Some required parameters are missing from the configuration file" ); > } > } > else { >- /* Start the insecured file server */ >+ /* Start the insecured java file server */ > startFileServer(stateData, &_fileServerTID); > } > } >- else { >- //for linux we have already warned about not having >- //File transfer. >- TPTP_LOG_ERROR_MSG( stateData, "Cannot create JVM" ); >- } > } > > return 0; >@@ -515,6 +541,8 @@ > struct sockaddr_in myServerSockAddr ; > tl_state_data_t* stateData; > cctl_state_data_t* cctlData; >+ TID threadId; >+ HANDLE threadHandle; > > if ( !isValidTPTPBlock(tlo, TPTP_BASETL_MAKE_OBJECT_ID(tlo)) ) > return TPTP_ERROR_INVALID_PARAMETER; >@@ -549,6 +577,16 @@ > return -1; // TODO: Use a more specific error > } > >+ if ((!cctlData->isJavaUnsecuredFileServer) && !cctlData->securityEnabled) { >+ rc = tptpStartThread(startNativeFileServer, (LPVOID)stateData, &threadId, &threadHandle); >+ if (rc == 0) { >+ TPTP_LOG_INFO_MSG1(stateData, "Native file server started listening on port %d", cctlData->filePort); >+ } >+ else { >+ TPTP_LOG_ERROR_MSG(stateData, "Native file server could not start"); >+ } >+ } >+ > return baseTL_startTransportListener( tlo, serveRequests ); > } > >Index: src-native-new/include/tptp/TPTPUtils.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/include/tptp/TPTPUtils.h,v >retrieving revision 1.23 >diff -u -r1.23 TPTPUtils.h >--- src-native-new/include/tptp/TPTPUtils.h 14 Jan 2008 07:49:58 -0000 1.23 >+++ src-native-new/include/tptp/TPTPUtils.h 4 Feb 2008 15:06:54 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2007 Intel Corporation. >+ * Copyright (c) 2005, 2008 Intel Corporation. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -236,6 +236,9 @@ > int tptp_postSemaphore(Semaphore_t *pSem); > > int getFileSize(char *fileName); >+int validateDirectory(char* dirName); >+int isAbsolutePath(const char* path); >+char* getTempDir(); > > /* String utilities */ > void tptp_strcopy(tptp_string* destination, const tptp_string* source); >Index: src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h >=================================================================== >RCS file: src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h >diff -N src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.h 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,101 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Intel Corporation. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Intel - Initial API and Implementation >+ * >+ * $Id: nativeFileServer.h,v 1.0 2008/02/04 22:47:17 ialelekov Exp $ >+ * >+ *******************************************************************************/ >+ >+#ifndef _NATIVE_FILE_SERVER >+#define _NATIVE_FILE_SERVER >+ >+#include <string.h> >+ >+#ifdef _WIN32 >+ #include <direct.h> >+#else >+ #include <sys/stat.h> >+ #include <sys/types.h> >+#endif >+ >+#include "tptp/TPTPTypes.h" >+#include "tptp/TPTPSupportTypes.h" >+#include "tptp/TransportSupport.h" >+#include "tptp/TPTPBaseTL.h" >+#include "tptp/compatibility/RAComm.h" >+#include "ClientCTL.h" >+ >+#ifdef _WIN32 >+ #define pathSeparatorCharacter '\\' >+ #define pathSeparator "\\" >+#else >+ #define pathSeparatorCharacter '/' >+ #define pathSeparator "/" >+#endif >+ >+typedef struct { >+ SOCKET socket; >+ char* buffer; >+ int bufferLength; >+ tl_state_data_t* stateData; >+} fs_connection_block_t; >+ >+#define DETERMINE_SERVER_REACH_COMMAND 1 >+#define DETERMINE_SERVER_REACH_COMMAND_STR "org.eclipse.hyades.internal.execution.core.file.dynamic.DetermineServerReachCommand" >+ >+#define GET_FILE_COMMAND 2 >+#define GET_FILE_COMMAND_STR "org.eclipse.hyades.internal.execution.core.file.dynamic.GetFileCommand" >+ >+#define PUT_FILE_COMMAND 3 >+#define PUT_FILE_COMMAND_STR "org.eclipse.hyades.internal.execution.core.file.dynamic.PutFileCommand" >+ >+#define DELETE_FILE_COMMAND 4 >+#define DELETE_FILE_COMMAND_STR "org.eclipse.hyades.internal.execution.core.file.dynamic.DeleteFileCommand" >+ >+#define DELETE_DIR_COMMAND 5 >+#define DELETE_DIR_COMMAND_STR "org.eclipse.hyades.internal.execution.core.file.dynamic.DeleteDirectoryCommand" >+ >+#define VALIDATE_DIR_COMMAND 6 >+#define VALIDATE_DIR_COMMAND_STR "org.eclipse.hyades.internal.execution.core.file.dynamic.ValidateDirectoryExistenceCommand" >+ >+#define QUERY_SERVER_STATUS_COMMAND 7 >+#define QUERY_SERVER_STATUS_COMMAND_STR "org.eclipse.hyades.internal.execution.core.file.dynamic.QueryServerStatusCommand" >+ >+#define MDFY_PERMISSION_COMMAND 8 >+#define MDFY_PERMISSION_COMMAND_STR "org.eclipse.hyades.internal.execution.core.file.dynamic.ModifyPermissionCommand" >+ >+#define LIST_CONTENT_COMMAND 9 >+#define LIST_CONTENT_COMMAND_STR "org.eclipse.hyades.internal.execution.core.file.dynamic.ListContentCommandCommand" >+ >+#define OPEN_CONTROL_DIALOG "org.eclipse.hyades.execution.core.loader.ScopedChannelClassLoader$AbstractControlDirective$BeginControlDirective" >+#define CLOSE_CONTROL_DIALOG "org.eclipse.hyades.execution.core.loader.ScopedChannelClassLoader$AbstractControlDirective$EndControlDirective" >+ >+#define FS_TRUE 127 // java.lang.Boolean.MAX_VALUE >+#define FS_FALSE -128 // java.lang.Boolean.MIN_VALUE >+ >+extern int readInt (SOCKET socket, int* value); >+extern char* readString(SOCKET socket); >+ >+extern int writeByte(SOCKET socket, int byte); >+extern int writeBoolean(SOCKET socket, int d); >+extern int writeInt (SOCKET socket, int v); >+extern int writeString(SOCKET socket, char* buffer); >+extern int writeStrings(SOCKET socket, char** array, int len); >+ >+extern char* readStringIntoBuffer(fs_connection_block_t* con); >+extern int readFile(fs_connection_block_t* con, char* fileName); >+ >+extern int writeFile(fs_connection_block_t* con, char* fileName); >+ >+extern int openControlDialog(fs_connection_block_t* con); >+extern int closeControlDialog(fs_connection_block_t* con); >+ >+extern THREAD_USER_FUNC_RET_TYPE startNativeFileServer(LPVOID args); >+ >+#endif >Index: src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c >=================================================================== >RCS file: src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c >diff -N src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src-native-new/src/transport/TPTPClientCompTL/nativeFileServer.c 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,556 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Intel Corporation. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Intel - Initial API and Implementation >+ * >+ * $Id: nativeFileServer.c,v 1.0 2008/02/04 22:47:17 ialelekov Exp $ >+ * >+ *******************************************************************************/ >+ >+#include "nativeFileServer.h" >+ >+int readInt (SOCKET socket, int* value) { >+ int bytesRead, bytesToRead, i, d, r; >+ unsigned char* p; >+ char buf[5]; // readFromSocket() appends terminating 0 >+ >+ bytesToRead = 4; >+ while(bytesToRead > 0) { >+ if (readFromSocket(socket, buf+4-bytesToRead, bytesToRead, &bytesRead) <= 0) { >+ return -1; >+ } >+ >+ bytesToRead -= bytesRead; >+ } >+ >+ for (i=0, p=(unsigned char*)buf, r=0; i<4; i++, p++) { >+ d = *p; >+ r = (r << 8) + d; >+ } >+ >+ *value = r; >+ >+ return 0; >+} >+ >+char* readString(SOCKET socket) { >+ int bytesRead; >+ int stringLength, stringReadBytes; >+ char* str; >+ >+ if (readInt(socket, &stringLength) < 0) { >+ return NULL; >+ } >+ >+ if (stringLength < 0) stringLength *= -1; // negative means hyades dynamic command loading >+ >+ str = (char*) tptp_malloc(stringLength+1); >+ if (str == NULL) return NULL; >+ >+ stringReadBytes = 0; >+ >+ while(stringReadBytes < stringLength) { >+ if (readFromSocket(socket, str+stringReadBytes, stringLength-stringReadBytes, &bytesRead) <= 0) { >+ tptp_free(str); >+ return NULL; >+ } >+ >+ stringReadBytes += bytesRead; >+ } >+ >+ *(str + stringLength) = '\0'; >+ >+ return str; >+} >+ >+char* readStringIntoBuffer(fs_connection_block_t* con) { >+ int bytesRead; >+ int stringLength, stringReadBytes; >+ >+ if (readInt(con->socket, &stringLength) < 0) return NULL; >+ >+ if (stringLength < 0) stringLength *= -1; // negative means hyades dynamic command loading >+ >+ if (stringLength > (con->bufferLength-1)) return NULL; // including terminting 0 >+ >+ stringReadBytes = 0; >+ >+ while(stringReadBytes < stringLength) { >+ if (readFromSocket(con->socket, con->buffer+stringReadBytes, stringLength-stringReadBytes, &bytesRead) < 0) { >+ return NULL; >+ } >+ >+ stringReadBytes += bytesRead; >+ } >+ >+ *(con->buffer + stringLength) = '\0'; >+ >+ return con->buffer; >+} >+ >+int writeByte(SOCKET socket, int byte) { >+ char c = (char) (byte & 0xff); >+ >+ return writeToSocket(socket, &c, 1); >+} >+ >+int writeBoolean(SOCKET socket, int d) { >+ d = (d != 0) ? FS_TRUE : FS_FALSE; >+ return writeByte(socket, d); >+} >+ >+int writeInt (SOCKET socket, int v) { >+ writeByte (socket, (v >> 24)); >+ writeByte (socket, (v >> 16)); >+ writeByte (socket, (v >> 8)); >+ return writeByte(socket, v); >+} >+ >+int writeString(SOCKET socket, char* buffer) { >+ int len = strlen(buffer); >+ writeInt(socket, len); >+ return writeToSocket(socket, buffer, len); >+} >+ >+int writeStrings(SOCKET socket, char** array, int len) { >+ int i; >+ >+ writeInt(socket, len); >+ for (i=0; i<len; i++) { >+ writeString(socket, array[i]); >+ } >+ >+ return 0; >+} >+ >+int mkDirs(char* path) { >+ char *p; >+ >+ p = path; >+ while(1) { >+ p = strchr(p, pathSeparatorCharacter); >+ if (p == NULL) break; >+ >+ *p = '\0'; >+ >+#ifdef _WIN32 >+ _mkdir(path); >+#else >+ mkdir(path, 0777); >+#endif >+ >+ *p++ = pathSeparatorCharacter; >+ } >+ >+ return 0; >+} >+ >+int readFile(fs_connection_block_t* con, char* fileName) { >+ int contentLen; >+ FILE* fp; >+ int num; >+ >+ mkDirs(fileName); >+ >+ fp = fopen(fileName, "wb"); >+ if (fp == NULL) { >+ TPTP_LOG_ERROR_MSG1(con->stateData, "NFS: write file open error: %s", fileName); >+ return -1; >+ } >+ >+ readInt(con->socket, &contentLen); // high 4 bytes >+ readInt(con->socket, &contentLen); >+ >+ while (contentLen > 0) { >+ int bytesToRead = contentLen; >+ if (bytesToRead > con->bufferLength) bytesToRead = con->bufferLength; >+ >+ if (readFromSocket(con->socket, con->buffer, bytesToRead, &num) < 0) break; >+ if (num <= 0) break; >+ >+ fwrite(con->buffer, num, 1, fp); >+ contentLen -= num; >+ } >+ >+ fclose(fp); >+ >+ writeInt(con->socket, 0); // high 4 bytes >+ writeInt(con->socket, getFileSize(fileName)); >+ >+ return 0; >+} >+ >+int writeFile(fs_connection_block_t* con, char* fileName) { >+ int contentLen; >+ int gotLen; >+ FILE* fp; >+ int n; >+ >+ contentLen = getFileSize(fileName); >+ if (contentLen < 0) return -1; >+ >+ fp = fopen(fileName, "rb"); >+ if (fp == NULL) { >+ TPTP_LOG_ERROR_MSG1(con->stateData, "NFS: read file open error: %s", fileName); >+ return -1; >+ } >+ >+ writeInt(con->socket, 0); // high 4 bytes of contentLength (64-bit) >+ writeInt(con->socket, contentLen); >+ >+ while ((n = fread((void *) con->buffer, 1, con->bufferLength, fp)) > 0) { >+ writeToSocket(con->socket, con->buffer, n); >+ } >+ >+ fclose(fp); >+ >+ readInt(con->socket, &gotLen); // high 4 bytes >+ readInt(con->socket, &gotLen); >+ >+ return 0; >+} >+ >+int openControlDialog(fs_connection_block_t* con) { >+ return writeString(con->socket, OPEN_CONTROL_DIALOG); >+} >+ >+int closeControlDialog(fs_connection_block_t* con) { >+ return writeString(con->socket, CLOSE_CONTROL_DIALOG); >+} >+ >+int readFSCommand(fs_connection_block_t* con) { >+ char* str; >+ >+ str = readStringIntoBuffer(con); >+ if (str == NULL) { >+ return -1; >+ } >+ >+ if (!strcmp(str, DETERMINE_SERVER_REACH_COMMAND_STR)) return DETERMINE_SERVER_REACH_COMMAND; >+ if (!strcmp(str, GET_FILE_COMMAND_STR)) return GET_FILE_COMMAND; >+ if (!strcmp(str, PUT_FILE_COMMAND_STR)) return PUT_FILE_COMMAND; >+ if (!strcmp(str, DELETE_FILE_COMMAND_STR)) return DELETE_FILE_COMMAND; >+ if (!strcmp(str, DELETE_DIR_COMMAND_STR)) return DELETE_DIR_COMMAND; >+ if (!strcmp(str, VALIDATE_DIR_COMMAND_STR)) return VALIDATE_DIR_COMMAND; >+ if (!strcmp(str, QUERY_SERVER_STATUS_COMMAND_STR)) return QUERY_SERVER_STATUS_COMMAND; >+ if (!strcmp(str, MDFY_PERMISSION_COMMAND_STR)) return MDFY_PERMISSION_COMMAND; >+ if (!strcmp(str, LIST_CONTENT_COMMAND_STR)) return LIST_CONTENT_COMMAND; >+ >+ TPTP_LOG_ERROR_MSG1(con->stateData, "NFS: unknown message: %s", str); >+ >+ return -1; >+} >+ >+int processServerReachCmd(fs_connection_block_t* con) { >+ char* host; >+ int port; >+ int d, rc; >+ SOCKET testSocket; >+ unsigned long ipAddr; >+ >+ host = readStringIntoBuffer(con); >+ if (host == NULL) return -1; >+ >+ readInt (con->socket, &port); >+ >+ d = 0; >+ rc = convertIPAddressStringToUlong(host, &ipAddr); // reverse call >+ if (rc == 0) { >+ if (!connectToTCPServer(ipAddr, (unsigned short) port, &testSocket)) { >+ d = 1; >+ closeSocket(testSocket); >+ } >+ } >+ >+ writeByte(con->socket, d); // "server is reachable" responce >+ >+ return 0; >+} >+ >+int getFiles(fs_connection_block_t* con, char** names, int num) { >+ int i; >+ char* name; >+ >+ for(i=0; i<num; i++) { >+ name = readString(con->socket); >+ if (name == NULL) { >+ return -1; >+ } >+ >+ names[i] = name; >+ } >+ >+ for (i=0; i<num; i++) { >+ if (writeFile(con, names[i])) { >+ return -1; >+ } >+ } >+ >+ return 0; >+} >+ >+void checkFileSeparators(char* path) { >+ char ips; >+ char* p; >+ >+#ifdef _WIN32 >+ ips = '/'; >+#else >+ ips = '\\'; >+#endif >+ >+ p = path; >+ while (1) { >+ p = strchr(p, ips); >+ if (p == NULL) break; >+ >+ *p = pathSeparatorCharacter; >+ } >+} >+ >+char* getAbsolutePath(char* path) { >+ char *absPath, *tmpDir; >+ int tmpDirLen; >+ >+ if (isAbsolutePath(path)) return NULL; >+ >+ tmpDir = getTempDir(); >+ tmpDirLen = strlen(tmpDir); >+ >+ absPath = (char*) tptp_malloc(strlen(tmpDir) + strlen(path) + 2); // including trailing null and file separator >+ strcpy(absPath, tmpDir); >+ if (*(absPath+tmpDirLen-1) != pathSeparatorCharacter) strcat(absPath, pathSeparator); >+ strcat(absPath, path); >+ >+ return absPath; >+} >+ >+int putFiles(fs_connection_block_t* con, char** names, int num) { >+ int i; >+ char *name, *absName; >+ >+ for(i=0; i<num; i++) { >+ name = readStringIntoBuffer(con); >+ if (name == NULL) { >+ return -1; >+ } >+ >+ checkFileSeparators(name); >+ >+ absName = getAbsolutePath(name); >+ if (absName != NULL) { >+ names[i] = absName; >+ } >+ else { >+ names[i] = (char*) tptp_malloc(strlen(name)+1); >+ strcpy(names[i], name); >+ } >+ } >+ >+ for (i=0; i<num; i++) { >+ if (readFile(con, names[i])) { >+ return -1; >+ } >+ } >+ >+ writeStrings(con->socket, names, num); // files resolution >+ >+ return 0; >+} >+ >+int processDeleteFileCmd(fs_connection_block_t* con) { >+ int i, numFiles, num; >+ char* name; >+ >+ readInt(con->socket, &numFiles); >+ readInt(con->socket, &num); >+ if (num <= 0) return -1; >+ >+ for (i=0; i<num; i++) { >+ name = readStringIntoBuffer(con); >+ if (name == NULL) return -1; >+ >+ remove(name); >+ } >+ >+ return 0; >+} >+ >+int validateDir(fs_connection_block_t* con, char** names, int num) { >+ int i; >+ char* name; >+ >+ for(i=0; i<num; i++) { >+ name = readString(con->socket); >+ if (name == NULL) { >+ return -1; >+ } >+ >+ names[i] = name; >+ } >+ >+ writeInt(con->socket, num); // reponse array size >+ for (i=0; i<num; i++) { >+ writeBoolean(con->socket, validateDirectory(names[i])); >+ } >+ >+ return 0; >+} >+ >+int processQueryServerStatusCmd(fs_connection_block_t* con) { >+ char* message; >+ >+ message = readStringIntoBuffer(con); >+ if (message == NULL) return -1; >+ >+ writeString(con->socket, message); >+ >+ return 0; >+} >+ >+int processDummyCmd(fs_connection_block_t* con) { >+ return 0; >+} >+ >+int processFileArrayCmd(fs_connection_block_t* con, int cmd) { >+ int i, numFiles, num; >+ char** names=NULL; >+ int res=-1; >+ >+ readInt(con->socket, &numFiles); >+ readInt(con->socket, &num); >+ if (num <= 0) return -1; >+ >+ names = (char**) malloc(num*sizeof(char*)); >+ memset(names, 0, num*sizeof(char*)); >+ >+ switch(cmd) { >+ case GET_FILE_COMMAND: >+ res = getFiles(con, names, num); >+ break; >+ >+ case PUT_FILE_COMMAND: >+ res = putFiles(con, names, num); >+ break; >+ >+ case VALIDATE_DIR_COMMAND: >+ res = validateDir(con, names, num); >+ break; >+ } >+ >+ for (i=0; i<num; i++) { >+ if (names[i] != NULL) tptp_free(names[i]); >+ } >+ >+ tptp_free(names); >+ >+ return res; >+} >+ >+int processFSCommand (fs_connection_block_t* con, int cmd) { >+ openControlDialog(con); >+ closeControlDialog(con); >+ >+ switch(cmd) { >+ case DETERMINE_SERVER_REACH_COMMAND: >+ return processServerReachCmd(con); >+ >+ case GET_FILE_COMMAND: >+ case PUT_FILE_COMMAND: >+ case VALIDATE_DIR_COMMAND: >+ return processFileArrayCmd(con, cmd); >+ >+ case DELETE_FILE_COMMAND: >+ case DELETE_DIR_COMMAND: >+ return processDeleteFileCmd(con); >+ >+ case QUERY_SERVER_STATUS_COMMAND: >+ return processQueryServerStatusCmd(con); >+ >+ case MDFY_PERMISSION_COMMAND: >+ case LIST_CONTENT_COMMAND: >+ return processDummyCmd(con); >+ } >+ >+ >+ return -1; >+} >+ >+THREAD_USER_FUNC_RET_TYPE processFSRequest(LPVOID args){ >+ SOCKET socket; >+ fs_connection_block_t* con; >+ int cmd; >+ >+ con = (fs_connection_block_t*)args; >+ socket = con->socket; >+ >+ while ((cmd = readFSCommand(con)) > 0) { >+ if (processFSCommand(con, cmd)) break; >+ } >+ >+ tptp_free(con->buffer); >+ tptp_free(con); >+ closeSocket(socket); >+ >+ return 0; >+} >+ >+static SOCKET serverSocket; >+ >+THREAD_USER_FUNC_RET_TYPE startNativeFileServer(LPVOID args){ >+ int rc, port; >+ struct sockaddr_in fsSockAddr; >+ SOCKET clientSock; >+ fs_connection_block_t* con; >+ tl_state_data_t* stateData; >+ TID threadId; >+ HANDLE threadHandle; >+ >+ stateData = (tl_state_data_t*) args; >+ port = ((cctl_state_data_t*)stateData->implData)->filePort; >+ if (port <= 0) port = RA_FILE_PORT_NUM_SERVER; >+ >+ serverSocket = getTheSocket(port, &fsSockAddr); >+ if (serverSocket < 0) { >+ TPTP_LOG_ERROR_MSG(stateData, "NFS: unable to create the file server socket."); >+ return 0; >+ } >+ >+ rc = bindAndListen(serverSocket, (struct sockaddr*)&fsSockAddr); >+ if (rc != 0) { >+ TPTP_LOG_ERROR_MSG(stateData, "NFS: cannot bind to server socket"); >+ return 0; >+ } >+ >+ while(1) { >+ clientSock = acceptSocketConnection(serverSocket); >+ if (clientSock < 0) break; >+ >+ con = (fs_connection_block_t*) tptp_malloc(sizeof(fs_connection_block_t)); >+ if (con == NULL) { >+ closeSocket(clientSock); >+ continue; >+ } >+ >+ con->socket = clientSock; >+ con->buffer = (char*) tptp_malloc(TPTP_DEFAULT_BUFFER_LENGTH+1); // +1 since readFromSocket() adds terminating 0 >+ con->bufferLength = TPTP_DEFAULT_BUFFER_LENGTH; >+ con->stateData = stateData; >+ >+ tptpStartThread(processFSRequest, (LPVOID)con, &threadId, &threadHandle) ; >+ } >+ >+ closeSocket(serverSocket); >+ >+ return 0; >+} >+ >+int stopNativeFileServer() { >+ closeSocket(serverSocket); >+ return 0; >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 196435
:
78752
|
80661
| 88778