home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / winli.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  12.0 KB  |  395 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19.     #include "stdafx.h"
  20.     #include "prefapi.h"
  21.     #include "logindg.h"
  22.     #include "winli.h"
  23.     #include "li_public.h"
  24.     #include "net.h"
  25.     #include "cast.h"
  26.     
  27.     
  28.     /*   This function will "spin" until it retreives the necessary files (LI & MC).  It will then
  29.      *   continue with the normal initialization
  30.      */
  31.     Bool FEU_GetCriticalFiles(const char * szProfileName, const char * szProfileDir)
  32.     {
  33.         int iNumFiles = 0;
  34.          theApp.m_bInGetCriticalFiles = TRUE;
  35.     
  36.         LI_StartGettingCriticalFiles(&iNumFiles);
  37.          // REMIND:  Add Mission Control .JSC file retreival here
  38.     
  39.         while (iNumFiles > 0) {
  40.             NET_ProcessNet(NULL, NET_EVERYTIME_TYPE);
  41.             FEU_StayingAlive();
  42.         }
  43.          theApp.m_bInGetCriticalFiles = FALSE;
  44.     
  45.         return login_ProfileSelectedCompleteTheLogin(szProfileName,szProfileDir);    
  46.     }
  47.         
  48.  
  49.     Bool winli_QueryNetworkProfile(void) {
  50.      #ifdef _DEBUG
  51.          // REMIND  need to get rid of this.
  52.         PREF_SetCharPref("li.protocol","ldap");
  53.          PREF_SetCharPref("li.server.ldap.url","ldap://nearpoint.mcom.com/nsLIProfileName=$USERID,ou=LIProfiles,o=Airius.com");
  54.         PREF_SetCharPref("li.server.ldap.userbase","uid=$USERID,ou=People,o=Airius.com");
  55. //         PREF_SetCharPref("li.server.ldap.searchBase","uid=$USERID, ou=LIProfiles, o=airius.com");
  56. //         PREF_SetCharPref("li.login.name","");
  57.      #endif
  58.  
  59.         CRemoteProfileLoginDlg dlg;
  60.         if (dlg.DoModal() == IDOK) {
  61.             int ret;
  62.             XP_StatStruct statinfo; 
  63.     
  64.             PREF_SetBoolPref("li.enabled",TRUE);
  65.     
  66.             CString pTempDir;
  67.     
  68.             if(getenv("TEMP"))
  69.               pTempDir = getenv("TEMP");  // environmental variable
  70.             if (pTempDir.IsEmpty() && getenv("TMP"))
  71.               pTempDir = getenv("TMP");  // How about this environmental variable?
  72.             if (pTempDir.IsEmpty()) {
  73.                   // Last resort: put it in the windows directory
  74.               char path[_MAX_PATH];
  75.               GetWindowsDirectory(path, sizeof(path));
  76.               pTempDir = path;
  77.             }
  78.     
  79.             pTempDir += "\\nstmpusr";        
  80.             ret = _stat((char *)(const char *)pTempDir, &statinfo);
  81.             if (ret == 0) {
  82.                 XP_RemoveDirectoryRecursive(pTempDir, xpURL);
  83.             }
  84.             mkdir(pTempDir);
  85.     
  86.             login_CreateEmptyProfileDir(pTempDir,NULL,TRUE);
  87.     
  88.             theApp.m_UserDirectory = pTempDir;
  89.             if (!pTempDir.IsEmpty())
  90.                 PREF_SetDefaultCharPref( "profile.directory", pTempDir );
  91.     
  92.             return FEU_GetCriticalFiles(dlg.m_csLoginName,pTempDir);
  93.         }
  94.         return FALSE;
  95.     }
  96.     
  97.  
  98.     void verifyLoginCallbackFunction2(void * closure, LIStatus result) {
  99.         int * pi = (int *)closure;
  100.  
  101.         if(result == LINoError) {
  102.             *pi = 0;
  103.             return ;
  104.         }
  105.  
  106.         *pi = -result;
  107.  
  108.         LI_Shutdown();
  109.         //REMIND deal with error here.
  110.         AfxMessageBox("You cannot be logged in to the li server -- fix this error.");
  111.     }
  112.     
  113.     /*   This function will "spin" until it gets the verify login return  It will then
  114.      *   continue with FEU_GetCriticalFiles to fetch the startup files.
  115.      */
  116.     Bool FEU_StartGetCriticalFiles(const char * szProfileName, const char * szProfileDir)
  117.     {
  118.         int iResult = 1;
  119.          theApp.m_bInGetCriticalFiles = TRUE;
  120.     
  121.         LI_Init();
  122.  
  123.         LIMediator::verifyLogin(verifyLoginCallbackFunction2,(void*)&iResult);
  124.     
  125.         while (iResult > 0) {
  126.             NET_ProcessNet(NULL, NET_EVERYTIME_TYPE);
  127.             FEU_StayingAlive();
  128.         }
  129.         // the login failed if iResult is < 0 
  130.         // REMIND we need to find a way to get back to the profile dialog.
  131.         if (iResult < 0)
  132.             return FALSE;
  133.  
  134.          theApp.m_bInGetCriticalFiles = FALSE;
  135.     
  136.         return FEU_GetCriticalFiles(szProfileName, szProfileDir);    
  137.     }
  138.  
  139.     // Remote Profile Login Dialog code
  140.     CRemoteProfileLoginDlg::CRemoteProfileLoginDlg(CWnd* pParent /*=NULL*/)
  141.         : CDialog(CRemoteProfileLoginDlg::IDD, pParent)
  142.     {
  143.         //{{AFX_DATA_INIT(CLoginDlg)
  144.         m_csLoginName = _T("");
  145.         m_csPasswordName = _T("");
  146.         //}}AFX_DATA_INIT
  147.     }
  148.     
  149.     
  150.     void CRemoteProfileLoginDlg::DoDataExchange(CDataExchange* pDX) 
  151.     {
  152.         CDialog::DoDataExchange(pDX);
  153.         //{{AFX_DATA_MAP(CLoginDlg)
  154.         DDX_Text(pDX, IDC_LOGINNAME, m_csLoginName);
  155.         DDX_Text(pDX, IDC_PASSWORD, m_csPasswordName);
  156.         //}}AFX_DATA_MAP
  157.     }
  158.     
  159.     BOOL CRemoteProfileLoginDlg::OnInitDialog() 
  160.     {
  161.         BOOL bRet;
  162.         bRet = CDialog::OnInitDialog();
  163.     
  164.         CWnd * widget;
  165.         
  166.         widget = GetDlgItem(IDC_LOGINNAME);
  167.         widget->SetFocus();
  168.     
  169.         return bRet;
  170.     }
  171.     
  172. void verifyLoginCallbackFunction(void * closure, 
  173.                                         LIStatus result) {
  174.     if(result == LINoError) {
  175.         ((CRemoteProfileLoginDlg*)closure)->Done();
  176.         return;
  177.     }
  178.  
  179.     LI_Shutdown();
  180.     //REMIND deal with error here.
  181.     AfxMessageBox("Error");
  182. }
  183.  
  184. void CRemoteProfileLoginDlg::Done()
  185. {
  186.     CDialog::OnOK();
  187. }
  188.  
  189. void CRemoteProfileLoginDlg::OnOK() 
  190. {
  191.  
  192.     UpdateData();
  193.  
  194.     PREF_SetCharPref("li.login.name",m_csLoginName);
  195.     PREF_SetCharPref("li.login.password",m_csPasswordName);    
  196.  
  197.     LI_Init();
  198.  
  199.     LIMediator::verifyLogin(verifyLoginCallbackFunction,(void*)this);
  200. }
  201.  
  202.  
  203.     void CRemoteProfileLoginDlg::OnAdvanced() 
  204.     {
  205.         CAdvRemoteProfileLoginDlg dlg;
  206.         dlg.DoModal();
  207.     }
  208.     
  209.     BEGIN_MESSAGE_MAP(CRemoteProfileLoginDlg, CDialog)
  210.         //{{AFX_MSG_MAP(CLoginDlg)
  211.         ON_BN_CLICKED(IDC_ADVANCED, OnAdvanced)
  212.         //}}AFX_MSG_MAP
  213.     END_MESSAGE_MAP()
  214.     
  215.      /* fill the 'global' buffer that is passed in with the preference */
  216.     void GetPreferenceString(const CString name, CString& buffer) 
  217.     {
  218.         char *pstr;
  219.  
  220.         PREF_CopyCharPref(name, &pstr);
  221.         buffer = pstr;
  222.         if (pstr) 
  223.             XP_FREE(pstr);
  224.     }
  225.  
  226.     CAdvRemoteProfileLoginDlg::CAdvRemoteProfileLoginDlg(CWnd* pParent /*=NULL*/)
  227.         : CDialog(CAdvRemoteProfileLoginDlg::IDD, pParent)
  228.     {
  229.         CString csProtoStr;
  230.         //{{AFX_DATA_INIT(CLoginDlg)
  231.         GetPreferenceString("li.protocol", csProtoStr);
  232.         m_iLDAP = (csProtoStr == "ldap");
  233.         m_iHTTP = (csProtoStr == "http");
  234.         GetPreferenceString("li.server.ldap.url", m_csLdapAddress);
  235.         GetPreferenceString("li.server.ldap.userbase", m_csLdapBase);
  236.         GetPreferenceString("li.server.http.baseURL", m_csHttpBase);
  237.         PREF_GetBoolPref("li.client.bookmarks", &m_bBookmarks);
  238.         PREF_GetBoolPref("li.client.cookies",  &m_bCookies);
  239.         PREF_GetBoolPref("li.client.filters",  &m_bFilters);
  240.         PREF_GetBoolPref("li.client.addressbook",  &m_bAddressBook);
  241.         PREF_GetBoolPref("li.client.navcntr", &m_bNavcntr);
  242.         PREF_GetBoolPref("li.client.liprefs",  &m_bPrefs);
  243.         PREF_GetBoolPref("li.client.security",  &m_bSecurity);
  244.         PREF_GetBoolPref("li.client.javasecurity",  &m_bJavaSec);
  245.         //}}AFX_DATA_INIT
  246.     }
  247.     
  248.     BOOL CAdvRemoteProfileLoginDlg::OnInitDialog() 
  249.     {
  250.         BOOL bRet;
  251.         bRet = CDialog::OnInitDialog();
  252.         
  253.         CButton * widget;
  254.         
  255.         widget = (CButton *) GetDlgItem(IDC_LDAP_SERVER);
  256.         widget->SetCheck(1);
  257.     
  258.         widget = (CButton *) GetDlgItem(IDC_HTTP_SERVER);
  259.         widget->SetCheck(0);
  260.     
  261.         UpdateData(FALSE);
  262.         return bRet;
  263.     }
  264.     
  265.     void CAdvRemoteProfileLoginDlg::DoDataExchange(CDataExchange* pDX) 
  266.     {
  267.         CDialog::DoDataExchange(pDX);
  268.         //{{AFX_DATA_MAP(CLoginDlg)
  269.         DDX_Text(pDX, IDC_LDAP_ADDRESS, m_csLdapAddress);
  270.         DDX_Text(pDX, IDC_LDAP_SEARCHBASE, m_csLdapBase);
  271.         DDX_Text(pDX, IDC_HTTP_ADDRESS, m_csHttpBase);
  272.         DDX_Check(pDX, IDC_BOOKMARKS, m_bBookmarks);
  273.         DDX_Check(pDX, IDC_COOKIES, m_bCookies);
  274.         DDX_Check(pDX, IDC_FILTERS, m_bFilters);
  275.         DDX_Check(pDX, IDC_ADDBOOK, m_bAddressBook);
  276.         DDX_Check(pDX, IDC_SELECTEDBOOKMARKS, m_bNavcntr);
  277.         DDX_Check(pDX, IDC_SUGGESTIONS, m_bPrefs);
  278.         DDX_Check(pDX, IDC_JAVA, m_bJavaSec);
  279.         DDX_Check(pDX, IDC_SECURITY_TYPE, m_bSecurity);
  280.         DDX_Check(pDX, IDC_LDAP_SERVER, (BOOL)m_iLDAP);
  281.          DDX_Check(pDX, IDC_HTTP_SERVER, (BOOL)m_iHTTP);
  282.         //}}AFX_DATA_MAP
  283.     }
  284.     
  285.     void CAdvRemoteProfileLoginDlg::OnOK() 
  286.     {
  287.         CDialog::OnOK();
  288.         CButton * widget;
  289.         
  290.         widget = (CButton *) GetDlgItem(IDC_LDAP_SERVER);
  291.         m_iLDAP = widget->GetCheck();
  292.     
  293.         widget = (CButton *) GetDlgItem(IDC_HTTP_SERVER);
  294.         m_iHTTP = widget->GetCheck();
  295.     
  296.         if (m_iLDAP == 1) {
  297.             PREF_SetCharPref("li.protocol","ldap");
  298.               PREF_SetCharPref("li.server.ldap.url",m_csLdapAddress);
  299.             PREF_SetCharPref("li.server.ldap.userbase",m_csLdapBase);
  300.         }
  301.         if (m_iHTTP == 1) {
  302.             PREF_SetCharPref("li.protocol","http");
  303.             PREF_SetCharPref("li.server.http.baseURL",m_csHttpBase);
  304.         }
  305.         PREF_SetBoolPref("li.client.bookmarks", IsDlgButtonChecked(IDC_BOOKMARKS) );
  306.         PREF_SetBoolPref("li.client.cookies", IsDlgButtonChecked(IDC_COOKIES) );
  307.         PREF_SetBoolPref("li.client.filters", IsDlgButtonChecked(IDC_FILTERS) );
  308.         PREF_SetBoolPref("li.client.addressbook", IsDlgButtonChecked(IDC_ADDBOOK) );
  309.         PREF_SetBoolPref("li.client.navcntr", IsDlgButtonChecked(IDC_SELECTEDBOOKMARKS) );
  310.         PREF_SetBoolPref("li.client.liprefs", IsDlgButtonChecked(IDC_SUGGESTIONS) );
  311.         PREF_SetBoolPref("li.client.security", IsDlgButtonChecked(IDC_SECURITY_TYPE) );
  312.         PREF_SetBoolPref("li.client.javasecurity", IsDlgButtonChecked(IDC_JAVA) );
  313.     
  314.     }
  315.     
  316.     void CAdvRemoteProfileLoginDlg::OnLDAP() 
  317.     {
  318.         CWnd * widget;
  319.         
  320.         widget = GetDlgItem(IDC_HTTP_ADDRESS);
  321.         if (widget) widget->EnableWindow(FALSE);
  322.     
  323.         widget = GetDlgItem(IDC_LDAP_ADDRESS);
  324.         if (widget) widget->EnableWindow(TRUE);
  325.     
  326.         widget = GetDlgItem(IDC_LDAP_SEARCHBASE);
  327.         if (widget) widget->EnableWindow(TRUE);
  328.     
  329.     }
  330.     
  331.     void CAdvRemoteProfileLoginDlg::OnHTTP() 
  332.     {
  333.         CWnd * widget;
  334.         
  335.         widget = GetDlgItem(IDC_HTTP_ADDRESS);
  336.         if (widget) widget->EnableWindow(TRUE);
  337.     
  338.         widget = GetDlgItem(IDC_LDAP_ADDRESS);
  339.         if (widget) widget->EnableWindow(FALSE);
  340.     
  341.         widget = GetDlgItem(IDC_LDAP_SEARCHBASE);
  342.         if (widget) widget->EnableWindow(FALSE);
  343.     }
  344.     
  345.     BEGIN_MESSAGE_MAP(CAdvRemoteProfileLoginDlg, CDialog)
  346.         //{{AFX_MSG_MAP(CLoginDlg)
  347.         ON_BN_CLICKED( IDC_LDAP_SERVER, OnLDAP)
  348.         ON_BN_CLICKED( IDC_HTTP_SERVER, OnHTTP)
  349.         //}}AFX_MSG_MAP
  350.     END_MESSAGE_MAP()
  351.     
  352.     BOOL CXPProgressDialog::OnInitDialog( )
  353.     {
  354.         m_ProgressMeter.SubclassDlgItem( IDC_PROGRESSMETER, this );
  355.         return CDialog::OnInitDialog();
  356.     }
  357.     
  358.     BEGIN_MESSAGE_MAP(CXPProgressDialog, CDialog)
  359.         ON_WM_CREATE()
  360.     END_MESSAGE_MAP()
  361.     
  362.     CXPProgressDialog::CXPProgressDialog(CWnd* pParent /*=NULL*/)
  363.         : CDialog(IDD_XPPROGRESS, pParent)
  364.     {
  365.         m_Min =0;
  366.         m_Max =100;
  367.         m_Range = 100;
  368.          m_cancelCallback = NULL;
  369.         m_cancelClosure = NULL;
  370.     }
  371.     
  372.     BOOL CXPProgressDialog::PreTranslateMessage( MSG* pMsg )
  373.     {
  374.         return CDialog::PreTranslateMessage(pMsg);
  375.     }
  376.     
  377.     int CXPProgressDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  378.     {
  379.         int res = CDialog::OnCreate(lpCreateStruct);
  380.         return res;
  381.     }
  382.     
  383.     void CXPProgressDialog::OnCancel()
  384.     {
  385.         if (m_cancelCallback)
  386.             m_cancelCallback(m_cancelClosure);
  387.         DestroyWindow();
  388.     }
  389.     
  390.     void CXPProgressDialog::DoDataExchange(CDataExchange *pDX)
  391.     {
  392.         CDialog::DoDataExchange(pDX);
  393.         DDX_Control(pDX, IDC_PERCENTCOMPLETE, m_PercentComplete);
  394.     }
  395.