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 78752 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]
patch
196435.txt (text/plain), 25.31 KB, created by
Igor Alelekov
on 2007-09-19 10:48:25 EDT
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Igor Alelekov
Created:
2007-09-19 10:48:25 EDT
Size:
25.31 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.tptp.platform.agentcontroller >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.10 >diff -u -r1.10 TPTPClientCompTL.dsp >--- src-native-new/src/transport/TPTPClientCompTL/TPTPClientCompTL.dsp 28 Mar 2006 19:33:34 -0000 1.10 >+++ src-native-new/src/transport/TPTPClientCompTL/TPTPClientCompTL.dsp 19 Sep 2007 14:35:39 -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/Connect2AC.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/TPTPClientCompTL/Connect2AC.c,v >retrieving revision 1.70 >diff -u -r1.70 Connect2AC.c >--- src-native-new/src/transport/TPTPClientCompTL/Connect2AC.c 21 Aug 2007 13:37:02 -0000 1.70 >+++ src-native-new/src/transport/TPTPClientCompTL/Connect2AC.c 19 Sep 2007 14:35:38 -0000 >@@ -1012,7 +1012,7 @@ > break; > } > if (i == 0) { >- if ((strlen(name) + strlen(value) + 100) > variableListSize) >+ if ((tptp_int32)(strlen(name) + strlen(value) + 100) > variableListSize) > { > variableListSize = (strlen(name) + strlen(value) + 100) * 2; > } >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.43 >diff -u -r1.43 ClientCTL.c >--- src-native-new/src/transport/TPTPClientCompTL/ClientCTL.c 24 May 2007 19:28:09 -0000 1.43 >+++ src-native-new/src/transport/TPTPClientCompTL/ClientCTL.c 19 Sep 2007 14:35:35 -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(); >+ > /** > ********************************************************* > * >@@ -201,11 +205,13 @@ > cctlData->isPolling = TRUE; > } > >- > /* Assume NO Security for now !!! */ > /******************************/ > /* Create JVM */ >- if (!cctlData->jvm) >+ if (!cctlData->securityEnabled) { >+ jvmCreated = FALSE; // skip jvm >+ } >+ else if (!cctlData->jvm) > { > TPTP_LOG_WARNING_MSG( stateData, "Cannot create JVM and therefore cannot create file server" ); > jvmCreated = FALSE; >@@ -293,7 +299,7 @@ > startFileServer(stateData, &_fileServerTID); > } > } >- else { >+ else if (cctlData->securityEnabled) { > //for linux we have already warned about not having > //File transfer. > TPTP_LOG_ERROR_MSG( stateData, "Cannot create JVM" ); >@@ -552,6 +558,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; >@@ -586,6 +594,18 @@ > return -1; // TODO: Use a more specific error > } > >+ >+ if (!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 ); > } > >@@ -835,27 +855,6 @@ > return 0; > } > >-#ifdef __linux__ >-int closeSocket (int socket) { >- struct linger linger; >- int rc; >- >- linger.l_onoff = 1; >- linger.l_linger = 0; >- >- rc = setsockopt(socket, SOL_SOCKET, SO_LINGER, (const char*) &linger, >- sizeof(linger)); >- >- close (socket); >- >- return rc; >-} >-#else >-int closeSocket (int socket) { >- return closeThisSocket(socket); >-} >-#endif >- > int closeConnections (tptp_object* tlo) { > tl_control_connection_t* con; > client_connection_block_t* client; >@@ -905,6 +904,7 @@ > tptp_int32 stopTransportListener(tptp_object* tlo) > { > closeConnections(tlo); >+ stopNativeFileServer(); > > return baseTL_stopTransportListener( tlo ); > } >Index: src-native-new/src/transport/transportSupport/TransportSupport.def >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/transportSupport/TransportSupport.def,v >retrieving revision 1.18 >diff -u -r1.18 TransportSupport.def >--- src-native-new/src/transport/transportSupport/TransportSupport.def 9 Apr 2007 17:01:24 -0000 1.18 >+++ src-native-new/src/transport/transportSupport/TransportSupport.def 19 Sep 2007 14:35:39 -0000 >@@ -52,4 +52,6 @@ > ipcCloseMem @49 > isMemOpen @50 > ipcMemDetach @51 >+ closeSocket @52 >+ > >\ No newline at end of file >Index: src-native-new/src/transport/transportSupport/TransportSupportSocket.c >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/src/transport/transportSupport/TransportSupportSocket.c,v >retrieving revision 1.22 >diff -u -r1.22 TransportSupportSocket.c >--- src-native-new/src/transport/transportSupport/TransportSupportSocket.c 8 Mar 2007 16:30:58 -0000 1.22 >+++ src-native-new/src/transport/transportSupport/TransportSupportSocket.c 19 Sep 2007 14:35:39 -0000 >@@ -470,5 +470,24 @@ > return ( send(sock, buffer, byteCount, 0) ) ; > } > >+#ifdef __linux__ >+int closeSocket (int socket) { >+ struct linger linger; >+ int rc; > >+ linger.l_onoff = 1; >+ linger.l_linger = 0; >+ >+ rc = setsockopt(socket, SOL_SOCKET, SO_LINGER, (const char*) &linger, >+ sizeof(linger)); >+ >+ close (socket); >+ >+ return rc; >+} >+#else >+int closeSocket (int socket) { >+ return closeThisSocket(socket); >+} >+#endif > >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.29 >diff -u -r1.29 TPTUtil.def >--- src-native-new/src/shared/TPTPUtil/TPTUtil.def 29 Aug 2007 19:53:12 -0000 1.29 >+++ src-native-new/src/shared/TPTPUtil/TPTUtil.def 19 Sep 2007 14:35:35 -0000 >@@ -99,4 +99,7 @@ > terminateXMLPlatformUtils > parseHostList > getExecutableName >- readStringFromBuffer >\ No newline at end of file >+ readStringFromBuffer >+ 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.36 >diff -u -r1.36 TPTPUtil.cpp >--- src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp 29 Aug 2007 19:53:12 -0000 1.36 >+++ src-native-new/src/shared/TPTPUtil/TPTPUtil.cpp 19 Sep 2007 14:35:35 -0000 >@@ -845,6 +845,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/include/tptp/TransportSupportSocket.h >=================================================================== >RCS file: /cvsroot/tptp/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/include/tptp/TransportSupportSocket.h,v >retrieving revision 1.8 >diff -u -r1.8 TransportSupportSocket.h >--- src-native-new/include/tptp/TransportSupportSocket.h 1 Nov 2006 22:47:16 -0000 1.8 >+++ src-native-new/include/tptp/TransportSupportSocket.h 19 Sep 2007 14:35:31 -0000 >@@ -196,8 +196,7 @@ > > int getPeerName(SOCKET sock, unsigned char *pAddr); > >- >- >+int closeSocket (int socket); > > #ifdef __cplusplus > } >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.22 >diff -u -r1.22 TPTPUtils.h >--- src-native-new/include/tptp/TPTPUtils.h 29 Aug 2007 19:53:13 -0000 1.22 >+++ src-native-new/include/tptp/TPTPUtils.h 19 Sep 2007 14:35:30 -0000 >@@ -234,6 +234,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,87 @@ >+#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,538 @@ >+#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 readFile(fs_connection_block_t* con, char* fileName) { >+ int contentLen; >+ FILE* fp; >+ int num; >+ >+ fp = fopen(fileName, "wb"); >+ if (fp == NULL) { >+ TPTP_LOG_DEBUG_MSG1(con->stateData, "NFS: 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) 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 (contentLen == gotLen) ? 0 : -1; >+} >+ >+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_DEBUG_MSG1(con->stateData, "NFS: unknown message: %s", str); >+ >+ return -1; // unknown command !!! save log >+} >+ >+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; >+ } >+} >+ >+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; >+} >+ >+char* getAbsolutePath(char* path) { >+ char *absPath, *tmpDir; >+ int tmpDirLen; >+ >+ if (isAbsolutePath(path)) return NULL; >+ >+ checkFileSeparators(path); >+ >+ 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); >+ >+ mkDirs(absPath); >+ >+ 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; >+ } >+ >+ 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=0; >+ >+ 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