Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
LdapApp Class Reference

#include <winldap.h>

Collaboration diagram for LdapApp:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LdapApp ()
BOOL IsConnected ()
LDAP * GetConnection ()
virtual BOOL InitInstance ()
virtual int ExitInstance ()
afx_msg void OnAppAbout ()
afx_msg void OnFileConnect ()
afx_msg void OnUpdateFileConnect (CCmdUI *pCmdUI)
afx_msg void OnFileDisconnect ()
afx_msg void OnUpdateFileDisconnect (CCmdUI *pCmdUI)
afx_msg void OnFileSearch ()
afx_msg void OnUpdateFileSearch (CCmdUI *pCmdUI)

Private Attributes

BOOL m_connected
CString m_dirHost
int m_dirPort
CString m_searchBase
CString m_searchFilter
int m_scope
LDAP * m_ld

Detailed Description

Definition at line 19 of file winldap.h.


Constructor & Destructor Documentation

Definition at line 43 of file winldap.cpp.


Member Function Documentation

int LdapApp::ExitInstance ( ) [virtual]

Definition at line 290 of file winldap.cpp.

{
       WriteProfileString( "Connection", "host", m_dirHost );
       WriteProfileInt( "Connection", "port", m_dirPort );
       WriteProfileString( "Search", "base", m_searchBase );
       WriteProfileInt( "Search", "scope", m_scope );
       WriteProfileString( "Search", "filter", m_searchFilter );
       
       return CWinApp::ExitInstance();
}
LDAP* LdapApp::GetConnection ( ) [inline]

Definition at line 26 of file winldap.h.

{ return m_ld; }
BOOL LdapApp::InitInstance ( ) [virtual]

Definition at line 57 of file winldap.cpp.

{
       // Standard initialization
#ifdef _WIN32
#ifdef _AFXDLL
       Enable3dControls();                // Call this when using MFC in a shared DLL
#else
       Enable3dControlsStatic();   // Call this when linking to MFC statically
#endif
#endif

       LoadStdProfileSettings();  // Load standard INI file options (including MRU)

       // Register document templates

       CSingleDocTemplate* pDocTemplate;
       pDocTemplate = new CSingleDocTemplate(
              IDR_MAINFRAME,
              RUNTIME_CLASS(LdapDoc),
              RUNTIME_CLASS(CMainFrame),       // main SDI frame window
              RUNTIME_CLASS(LdapView));
       AddDocTemplate(pDocTemplate);

#ifdef _WIN32
       // Parse command line for standard shell commands, DDE, file open
       CCommandLineInfo cmdInfo;
       ParseCommandLine(cmdInfo);

       // Dispatch commands specified on the command line
       if (!ProcessShellCommand(cmdInfo))
              return FALSE;
#else
       // create a new (empty) document
       OnFileNew();

       if (m_lpCmdLine[0] != '\0')
       {
       }
#endif

       m_dirHost = GetProfileString( "Connection", "host", "localhost" );
       m_dirPort = GetProfileInt( "Connection", "port", 389 );
       m_searchBase = GetProfileString( "Search", "base", "dc=example,dc=com" );

       m_scope = GetProfileInt( "Search", "scope", LDAP_SCOPE_SUBTREE );
       m_searchFilter = GetProfileString( "Search", "filter", "objectclass=*" );

       return TRUE;
}

Here is the call graph for this function:

BOOL LdapApp::IsConnected ( ) [inline]

Definition at line 25 of file winldap.h.

{ return m_connected; }

Here is the caller graph for this function:

Definition at line 154 of file winldap.cpp.

{
       CAboutDlg aboutDlg;
       aboutDlg.DoModal();
}

Definition at line 164 of file winldap.cpp.

{
       ConnDlg dlg;
       dlg.m_dirHost = m_dirHost;
       dlg.m_dirPort = m_dirPort;
       if ( IDOK == dlg.DoModal() )
       {
              m_dirHost = dlg.m_dirHost;
              m_dirPort = dlg.m_dirPort;
              m_ld = ldap_init( m_dirHost, m_dirPort );
              if ( NULL != m_ld )
              {
                     // Bind as anonymous
                     if ( ldap_bind_s( m_ld, "", "", LDAP_AUTH_SIMPLE )
                                   != LDAP_SUCCESS )
                     {
                            AfxMessageBox( "Error binding!" );
                            return;
                     }
              }
              else
              {
                     AfxMessageBox( "Error connecting!" );
                     return;
              }
              m_connected = TRUE;
              LdapView *view = (LdapView *)((CFrameWnd *)AfxGetMainWnd())->GetActiveView();
              if ( view )
              {
                     CString title;
                     title.Format( "Host %s, port %d", m_dirHost, m_dirPort );
                     view->GetDocument()->SetTitle( title );
              }
       }
}

Here is the call graph for this function:

Definition at line 206 of file winldap.cpp.

{
       ldap_unbind( m_ld );
       m_ld = NULL;
       m_connected = FALSE;
       LdapView *view = (LdapView *)((CFrameWnd *)AfxGetMainWnd())->GetActiveView();
       if ( view )
       {
              view->GetDocument()->SetTitle( "" );
       }
}

Here is the call graph for this function:

Definition at line 224 of file winldap.cpp.

{
       SearchDlg dlg;
       dlg.m_searchBase = m_searchBase;
       dlg.SetScope( m_scope );
       dlg.m_searchFilter = m_searchFilter;
       // Get desired search parameters
       if ( IDOK == dlg.DoModal() )
       {
              m_searchBase = dlg.m_searchBase;
              m_searchFilter = dlg.m_searchFilter;
              m_scope = dlg.GetScope();
              // Clear the result list
              LdapView *view = (LdapView *)((CFrameWnd *)AfxGetMainWnd())->GetActiveView();
              if ( view )
                     view->ClearLines();
              char *attrs[2];
              // "dn" is a pseudo-attribute; it is always returned anyway, but not as
              // an attribute
              attrs[0] = "dn";
              attrs[1] = NULL;
              if ( ldap_search( m_ld, m_searchBase, m_scope, m_searchFilter,
                            attrs, FALSE ) == -1 )
              {
                     AfxMessageBox( "Failed to start asynchronous search" );
                     return;
              }
              LDAPMessage *res;
              int rc;
              // Fetch all results as they become available
              while ( (rc = ldap_result( m_ld, LDAP_RES_ANY, 0, NULL, &res ))
                     == LDAP_RES_SEARCH_ENTRY )
              {
                     LDAPMessage *e = ldap_first_entry( m_ld, res );
                     // Get the distinguished name and show it
                     char *dn = ldap_get_dn( m_ld, e );
                     if ( view )
                            view->AddLine( dn, dn );
                     ldap_memfree( dn );
                     ldap_msgfree( res );
                     // Let the view be updated
#ifdef _WIN32
                     Sleep( 0 );
#else
                     Yield();
#endif
              }
              if ( rc == -1 )
              {
                     AfxMessageBox( "Error on ldap_result" );
                     return;
           }
              else if (( rc = ldap_result2error( m_ld, res, 0 )) != LDAP_SUCCESS )
              {
                     char *errString = ldap_err2string( rc );
                     AfxMessageBox( errString );
           }
              ldap_msgfree( res );
       }
}

Here is the call graph for this function:

void LdapApp::OnUpdateFileConnect ( CCmdUI *  pCmdUI)

Definition at line 200 of file winldap.cpp.

{
       pCmdUI->Enable( !IsConnected() );
}

Here is the call graph for this function:

void LdapApp::OnUpdateFileDisconnect ( CCmdUI *  pCmdUI)

Definition at line 218 of file winldap.cpp.

{
       pCmdUI->Enable( IsConnected() );
}

Here is the call graph for this function:

void LdapApp::OnUpdateFileSearch ( CCmdUI *  pCmdUI)

Definition at line 285 of file winldap.cpp.

{
       pCmdUI->Enable( IsConnected() );
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 29 of file winldap.h.

CString LdapApp::m_dirHost [private]

Definition at line 30 of file winldap.h.

Definition at line 31 of file winldap.h.

LDAP* LdapApp::m_ld [private]

Definition at line 35 of file winldap.h.

int LdapApp::m_scope [private]

Definition at line 34 of file winldap.h.

CString LdapApp::m_searchBase [private]

Definition at line 32 of file winldap.h.

CString LdapApp::m_searchFilter [private]

Definition at line 33 of file winldap.h.


The documentation for this class was generated from the following files: