/reload-config not working. Must restart service.

Need help with FileZilla Server? Something does not work as expected? In this forum you may find an answer.

Moderator: Project members

Message
Author
mbattaglia
504 Command not implemented
Posts: 9
Joined: 2011-05-17 18:44
First name: Michael
Last name: Battaglia

Re: /reload-config not working. Must restart service.

#16 Post by mbattaglia » 2011-05-20 16:36

Ok, I give up. I was able to successfully get the two unique HWNDs which, according to the C code, are used to receive the window message. However after posting the mesage to these window, the FileZilla Server UI still doesn't show any changes that were manually entered into the FileZilla Server.xml file.

Below is the code that I am using. The method called FileZillaServerReloadConfig() is what starts everything.

VB6:

Code: Select all

Option Explicit

Private Const MAX_PATH = 260

Private Const WM_APP = &H8000
Private Const WM_FILEZILLA_RELOADCONFIG = WM_APP

Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private mWindowHandlesInfo As String

Public Function GetWindowHandles() As String
    On Error GoTo Unexer
    
    mWindowHandlesInfo = vbNullString
    
    Call EnumWindows(AddressOf EnumWindowProc, &H0)
    
    GetWindowHandles = mWindowHandlesInfo
    
    Exit Function
Unexer:
    Debug.Print "ERROR (GetWindowHandles): " & Err.Description
End Function
Public Function EnumWindowProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
    'working vars
    Dim nSize As Long
    Dim sTitle As String
    Dim sClass As String
    Dim pos As Integer
    
    'set up the strings to receive the class and
    'window text. You could use GetWindowTextLength,
    'but I'll cheat and use MAX_PATH instead.
    sTitle = Space$(MAX_PATH)
    sClass = Space$(MAX_PATH)
    
    Call GetClassName(hWnd, sClass, MAX_PATH)
    Call GetWindowText(hWnd, sTitle, MAX_PATH)
    
    If LenB(mWindowHandlesInfo) <> 0 Then
        mWindowHandlesInfo = mWindowHandlesInfo & Chr$(255)
    End If
    
    'strip the trailing chr$(0)'s from the strings
    'returned above and add the window data to the list
    mWindowHandlesInfo = mWindowHandlesInfo & CStr(hWnd) & Chr$(254)
    mWindowHandlesInfo = mWindowHandlesInfo & TrimNull(sClass) & Chr$(254)
    mWindowHandlesInfo = mWindowHandlesInfo & TrimNull(sTitle)
                        
    'to continue enumeration, we must return True
    '(in C that's 1).  If we wanted to stop (perhaps
    'using if this as a specialized FindWindow method,
    'comparing a known class and title against the
    'returned values, and a match was found, we'd need
    'to return False (0) to stop enumeration. When 1 is
    'returned, enumeration continues until there are no
    'more windows left.
    EnumWindowProc = 1
End Function
Private Function TrimNull(item As String)
    'remove string before the terminating null(s)
    Dim pos As Integer
    
    pos = InStr(item, Chr$(0))
    
    If pos Then
        TrimNull = Left$(item, pos - 1)
    Else
        TrimNull = item
    End If
End Function

' mjb 05/20/11
Public Sub FileZillaServerReloadConfig()
    Dim WindowHandlesInfo As String
    Dim Array1() As String
    Dim Ubnd1 As Long
    Dim Index1 As Long
    Dim Array2() As String
    Dim Ubnd2 As Long
    Dim Index2 As Long
    
    Dim hWnd As Long
    Dim WindowClass As String
    Dim WindowText As String
    
    Dim RetVal As Long
    
    On Error GoTo Unexer
    
    ' Locate the hwnd for FileZilla Server
    WindowHandlesInfo = GetWindowHandles()
    
    Array1 = Split(WindowHandlesInfo, Chr$(255))
    Ubnd1 = -1
    On Error Resume Next
    Ubnd1 = UBound(Array1)
    On Error GoTo Unexer
    
    For Index1 = 0 To Ubnd1
        Array2 = Split(Array1(Index1), Chr$(254))
        hWnd = Val(Array2(0))
        WindowClass = CStr(Array2(1))
        WindowText = CStr(Array2(2))
        
        If hWnd <> 0 Then
            If WindowClass = "FileZilla Server Helper Window" Then
                Debug_Print "Posting message to " & CStr(hWnd)
                RetVal = PostMessage(hWnd, WM_FILEZILLA_RELOADCONFIG, 0, 0)
                Debug_Print "Posted message to " & CStr(hWnd)
            End If
        End If
    Next Index1
    
    Exit Sub
Unexer:
    Debug.Print "ERROR (FileZillaServerReloadConfig): " & Err.Description
End Sub

User avatar
botg
Site Admin
Posts: 33053
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse
Contact:

Re: /reload-config not working. Must restart service.

#17 Post by botg » 2011-05-20 22:09

Just to verify, the changes are picked up if you restart the server service?

mbattaglia
504 Command not implemented
Posts: 9
Joined: 2011-05-17 18:44
First name: Michael
Last name: Battaglia

Re: /reload-config not working. Must restart service.

#18 Post by mbattaglia » 2011-05-23 12:58

Yes, that is correct. Is is as if the PostMessage doesn't appear to do anything.

User avatar
botg
Site Admin
Posts: 33053
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse
Contact:

Re: /reload-config not working. Must restart service.

#19 Post by botg » 2011-05-23 20:10

Strange, I have no idea what is causing this. I think I'll have to add a small tool that does this using the administration port, should be less troublesome.

mbattaglia
504 Command not implemented
Posts: 9
Joined: 2011-05-17 18:44
First name: Michael
Last name: Battaglia

Re: /reload-config not working. Must restart service.

#20 Post by mbattaglia » 2011-05-23 20:22

In other words, instead of posting a window's message to the helper window, you send some network message to the server?

Could you please provide me with a sample code on how to invoke the reload-config this way?

User avatar
botg
Site Admin
Posts: 33053
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse
Contact:

Re: /reload-config not working. Must restart service.

#21 Post by botg » 2011-05-23 21:46

Not yet implemented in the service.

Post Reply