home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / mucproc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.1 KB  |  257 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 "mucproc.h"
  21.  
  22. #define new DEBUG_NEW
  23. //********************************************************************************
  24. //
  25. // CMucProc constructor
  26. //
  27. //********************************************************************************
  28. CMucProc::CMucProc()
  29. {
  30.     acct_flag = FALSE;
  31.     modem_flag = FALSE;   
  32.     m_lpfnPEPluginFunc = NULL;
  33. }
  34.  
  35. //********************************************************************************
  36. //
  37. // LoadMuc
  38. //
  39. //********************************************************************************
  40. BOOL CMucProc::LoadMuc() 
  41. {
  42.     long m_version;
  43.  
  44.     if(m_lpfnPEPluginFunc != NULL) 
  45.         return TRUE;   
  46.     m_lpfnPEPluginFunc = (FARPEFUNC)::GetProcAddress(theApp.m_hPEInst,
  47.         "PEPluginFunc");
  48.     
  49.     if(m_lpfnPEPluginFunc == NULL)
  50.     {
  51.         FreeLibrary(theApp.m_hPEInst);
  52.         return FALSE;
  53.     }
  54.  
  55.     // check the MUC version number
  56.     (*m_lpfnPEPluginFunc)(kGetPluginVersion, NULL, &m_version);
  57.     if(m_version != 0x00010000)
  58.     {
  59.         FreeLibrary(theApp.m_hPEInst);  
  60.         m_lpfnPEPluginFunc = NULL;
  61.         return FALSE;
  62.     }
  63.     return TRUE;
  64. }
  65. // account information
  66. //********************************************************************************
  67. //
  68. // GetAcctNameList
  69. //
  70. //********************************************************************************
  71. BOOL CMucProc::GetAcctArray(CStringArray *acctList)
  72. {
  73.     if(!acct_flag)
  74.         GetAccountNames();
  75.     
  76.     int size = acctNames.GetSize();
  77.     
  78.     if(size !=0)
  79.     {   
  80. #ifdef XP_WIN32 
  81.         acctList->Copy(acctNames);       
  82. #else
  83.         for( int i=0; i<size; i++)
  84.             acctList->SetAtGrow(i, acctNames[i]);
  85. #endif                  
  86.         return TRUE;
  87.     }
  88.     return FALSE;
  89. }
  90.  
  91. //********************************************************************************
  92. //
  93. // IsAccountValid
  94. //
  95. //********************************************************************************
  96. BOOL CMucProc::IsAcctValid(char *acctStr)
  97. {
  98.     int             i = 0;
  99.  
  100.     if(!acct_flag)
  101.         GetAccountNames();
  102.  
  103.     int num = acctNames.GetSize();
  104.  
  105.     while(i<num)
  106.     {
  107.         if(_stricmp(acctStr, (const char*)acctNames[i]) == 0)
  108.             return TRUE;
  109.         else
  110.             i++;
  111.     }
  112.     return FALSE;
  113. }
  114.  
  115. // modem information
  116. //********************************************************************************
  117. //
  118. // GetModemList
  119. //
  120. //********************************************************************************
  121. BOOL CMucProc::GetModemArray(CStringArray *modemList)
  122. {
  123.     if(!modem_flag)
  124.         GetModemNames();
  125.  
  126.     
  127.     int num = modemNames.GetSize();
  128.     if(num !=0)
  129.     { 
  130. #ifdef WIN32
  131.         modemList->Copy(modemNames);      
  132. #else
  133.         for(int i=0; i<num; i++)
  134.             modemList->SetAtGrow(i, modemNames.GetAt(i));
  135. #endif
  136.         return TRUE;
  137.     }
  138.     return FALSE;
  139. }
  140.  
  141. //********************************************************************************
  142. //
  143. // IsModemValid
  144. //
  145. //********************************************************************************
  146. BOOL CMucProc::IsModemValid(char* modemStr)
  147. {
  148.     int             i = 0;
  149.  
  150.     if(!modem_flag)
  151.         GetModemNames();
  152.     
  153.     int num = modemNames.GetSize();
  154.  
  155.     while(i<num)
  156.     {
  157.         if(strcmp(modemStr, (const char*)modemNames.GetAt(i)) == 0)
  158.             return TRUE;
  159.         else
  160.             i++;
  161.     }
  162.     return FALSE;
  163. }
  164.  
  165. // GetModemList
  166.  
  167. //********************************************************************************
  168. //
  169. // GetModemNames
  170. //
  171. //********************************************************************************
  172.  
  173. BOOL CMucProc::GetModemNames()
  174. {
  175.     char    modemResults[MAX_PATH*10];
  176.     int             numDevices;
  177.     int             i;
  178.     char    temp[MAX_PATH];
  179.  
  180.     memset(modemResults, 0x00, MAX_PATH*10);
  181.  
  182.     if(0 == (*m_lpfnPEPluginFunc)(kSelectModemConfig, &numDevices, modemResults))
  183.     {
  184.         if(modemResults != NULL && numDevices != 0)
  185.         {
  186.             // decoding: the muc string is deliminated by "()"                                
  187.             CString         key = "()"; 
  188.             CString         str = modemResults;
  189.             int             pos;
  190.         
  191.         i=0;
  192.             while(i<numDevices)
  193.             {
  194.                 pos = str.Find(key);  
  195.                 modemNames.Add(str.Left(pos));
  196.                 str = str.Mid(pos+2);
  197.                 i++;
  198.             }
  199.             modem_flag = TRUE;
  200.             return TRUE;
  201.         }
  202.     }
  203.     return FALSE;
  204. }
  205.  
  206.  
  207.  
  208. //********************************************************************************
  209. //
  210. // GetAccountNames
  211. //
  212. //********************************************************************************
  213. BOOL CMucProc::GetAccountNames()
  214. {
  215.     int             numNames=0;
  216.     int             i=0;
  217.     char    acctResults[MAX_PATH*10];
  218.     char    temp[MAX_PATH];
  219.  
  220.     memset(acctResults, 0x00, MAX_PATH*10); 
  221.  
  222.       if(0==(*m_lpfnPEPluginFunc)(kSelectAcctConfig, &numNames, acctResults))
  223.     {
  224.         if(acctResults != NULL && numNames != 0)
  225.         { 
  226.             // decoding: the muc string is deliminated by "()"                                
  227.             CString         key = "()"; 
  228.             CString         str = acctResults;
  229.             int             pos;    
  230.             
  231.             i=0;
  232.             while(i<numNames)
  233.             {
  234.                 pos = str.Find(key);  
  235.                 acctNames.Add(str.Left(pos));
  236.                 str = str.Mid(pos+2);
  237.                 i++;
  238.             }
  239.             acct_flag = TRUE;
  240.             return TRUE;
  241.         }
  242.     }
  243.     return FALSE;
  244. }
  245.  
  246. //********************************************************************************
  247. //
  248. // SetDialOnDemand
  249. //
  250. //********************************************************************************
  251. void CMucProc::SetDialOnDemand(CString acctStr, BOOL flag)
  252. {
  253.     if(!LoadMuc())  return;
  254.  
  255.     (*m_lpfnPEPluginFunc)(kSelectDialOnDemand, (void*)((const char*)acctStr), &flag);
  256. }
  257.