src/eric7/RemoteServerInterface/EricServerInterface.py

branch
eric7
changeset 11033
6b197c3389f7
parent 11006
a671918232f3
child 11090
f5f5f5803935
diff -r 84a66daa5e34 -r 6b197c3389f7 src/eric7/RemoteServerInterface/EricServerInterface.py
--- a/src/eric7/RemoteServerInterface/EricServerInterface.py	Sat Nov 02 19:28:14 2024 +0100
+++ b/src/eric7/RemoteServerInterface/EricServerInterface.py	Sun Nov 03 12:34:02 2024 +0100
@@ -102,6 +102,7 @@
         # no specific service interfaces have been created yet
 
         self.__connection = None
+        self.__clientId = b""  # prepended to each messge for validity checking
         self.__callbacks = {}  # callback references indexed by UUID
         self.__messageQueue = collections.deque()
         self.__connected = False
@@ -170,7 +171,7 @@
     ## Methods for handling the server connection.
     #######################################################################
 
-    def connectToServer(self, host, port=None, timeout=None):
+    def connectToServer(self, host, port=None, timeout=None, clientId=""):
         """
         Public method to connect to the given host and port.
 
@@ -181,6 +182,9 @@
         @param timeout timeout im seconds for the connection attempt
             (defaults to None)
         @type int (optional)
+        @param clientId string prepended to each message for validity checking
+            (defaults to "")
+        @type str (optional)
         @return flag indicating success
         @rtype bool
         """
@@ -215,6 +219,8 @@
             self.__connection = None
             return False
 
+        self.__clientId = clientId.encode("utf-8")
+
         self.__connection.readyRead.connect(self.__receiveJson)
         self.__connection.disconnected.connect(self.__handleDisconnect)
 
@@ -243,6 +249,8 @@
                 self.__connection = None
                 self.__callbacks.clear()
 
+        self.__clientId = b""
+
     def isServerConnected(self):
         """
         Public method to check, if a connection to an eric-ide server has been
@@ -267,6 +275,7 @@
         self.connectionStateChanged.emit(False)
         self.__connection = None
         self.__callbacks.clear()
+        self.__clientId = b""
 
     def getHost(self):
         """
@@ -457,6 +466,8 @@
         if self.__connection is not None:
             data = jsonString.encode("utf8", "backslashreplace")
             header = struct.pack(b"!II", len(data), zlib.adler32(data) & 0xFFFFFFFF)
+            if self.__clientId:
+                self.__connection.write(self.__clientId)
             self.__connection.write(header)
             self.__connection.write(data)
             if flush:
@@ -672,11 +683,11 @@
         self.stopServerAct.setEnabled(False)
         self.serverVersionsAct.setEnabled(False)
 
-    def initMenu(self):
+    def initMenus(self):
         """
-        Public slot to initialize the eric-ide server menu.
+        Public slot to initialize the eric-ide server menus.
 
-        @return the menu generated
+        @return reference to the main eric-ide server menu
         @rtype QMenu
         """
         self.__serverProfilesMenu = QMenu(self.tr("Connect to"))
@@ -757,14 +768,18 @@
         """
         Private slot to prepare the eric server profiles menu.
         """
-        profiles = Preferences.getEricServer("ConnectionProfiles")
+        serverProfiles = Preferences.getEricServer("ConnectionProfiles")
 
         self.__serverProfilesMenu.clear()
 
         if not self.isServerConnected():
-            for profile in sorted(profiles):
-                act = self.__serverProfilesMenu.addAction(profile)
-                act.setData(profiles[profile])
+            for serverProfile in sorted(serverProfiles):
+                act = self.__serverProfilesMenu.addAction(serverProfile)
+                data = serverProfiles[serverProfile]
+                if len(data) == 3:
+                    # profile generated before eric-ide 24.12
+                    data.append("")
+                act.setData(data)
             self.__serverProfilesMenu.addSeparator()
 
         self.__serverProfilesMenu.addAction(
@@ -818,8 +833,10 @@
 
         dlg = EricServerConnectionDialog(parent=self.__ui)
         if dlg.exec() == QDialog.DialogCode.Accepted:
-            hostname, port, timeout = dlg.getData()
-            self.connectToServer(hostname, port=port, timeout=timeout)
+            hostname, port, timeout, clientId = dlg.getData()
+            self.connectToServer(
+                hostname, port=port, timeout=timeout, clientId=clientId
+            )
 
     @pyqtSlot()
     def __shutdownServer(self):
@@ -849,8 +866,10 @@
         data = act.data()
         if data is not None:
             # handle the connection
-            hostname, port, timeout = data
-            self.connectToServer(hostname, port=port, timeout=timeout)
+            hostname, port, timeout, clientId = data
+            self.connectToServer(
+                hostname, port=port, timeout=timeout, clientId=clientId
+            )
 
     @pyqtSlot()
     def __manageServerProfiles(self):

eric ide

mercurial