⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remconn.cxx

📁 pwlib源码库
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* * remconn.cxx * * Remote Networking Connection class implmentation for Win32 RAS. * * Portable Windows Library * * Copyright (c) 1993-1998 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Portable Windows Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Portions are Copyright (C) 1993 Free Software Foundation, Inc. * All Rights Reserved. * * Contributor(s): ______________________________________. * * $Log: remconn.cxx,v $ * Revision 1.28  2004/04/03 08:22:22  csoutheren * Remove pseudo-RTTI and replaced with real RTTI * * Revision 1.27  2000/03/07 01:43:29  robertj * Removed double include of ras.h as no longer works with later versions. * * Revision 1.26  1999/06/27 04:21:59  robertj * Added more debugging to GetStatus() error reporting. * * Revision 1.25  1999/02/16 08:08:07  robertj * MSVC 6.0 compatibility changes. * * Revision 1.24  1998/11/30 04:50:16  robertj * New directory structure * * Revision 1.23  1998/10/15 05:41:51  robertj * New memory leak check code. * * Revision 1.22  1998/09/24 03:30:55  robertj * Added open software license. * * Revision 1.21  1998/07/24 06:51:56  robertj * Added ability to get IP number of RAS connection. * * Revision 1.20  1998/03/05 12:49:54  robertj * MemCheck fixes. * * Revision 1.19  1998/02/03 06:16:44  robertj * Added more error codes. * * Revision 1.18  1998/01/26 00:54:58  robertj * Added function to PRemoteConnection to get at OS error code. * * Revision 1.17  1997/04/06 07:45:28  robertj * Fixed bug in dialling already connected remotes. * * Revision 1.16  1997/04/01 06:00:06  robertj * Added Remove Configuration. * * Revision 1.15  1997/02/05 11:47:25  robertj * Fixed NT 3.51 support, again! (PAP compatibility) * * Revision 1.14  1997/01/25 02:22:47  robertj * Fixed backward compatibilty with NT3.51 and Win'95 * * Revision 1.13  1997/01/12 04:14:39  robertj * Added ability to add/change new connections. * * Revision 1.12  1996/12/01 07:01:28  robertj * Changed debugging asserts to simple PError output. * * Revision 1.11  1996/11/16 10:53:17  robertj * Added missing SetlastError() so assert has correct error value. * * Revision 1.10  1996/11/10 21:02:46  robertj * Try doing double sample before flagging a RAS connection disconnected. * * Revision 1.9  1996/11/04 09:45:26  robertj * Yet more debugging. * * Revision 1.8  1996/11/04 03:37:23  robertj * Added more debugging for remote drop outs. * * Revision 1.7  1996/10/31 12:39:53  robertj * Added RCS keywords. * */#include <ptlib.h>#include <ptlib/remconn.h>#define SizeWin400_RAS_MaxEntryName 256#define SizeWin400_RAS_MaxPhoneNumber 128#define SizeWin400_RAS_MaxCallbackNumber SizeWin400_RAS_MaxPhoneNumber#define SizeWin400_RAS_MaxDeviceType 16#define SizeWin400_RAS_MaxDeviceName 128#define SizeWin400_RASCONN (sizeof(DWORD) + \                            sizeof(HRASCONN) + \                            SizeWin400_RAS_MaxEntryName + 1)#define SizeWin400_RASDIALPARAMS (sizeof(DWORD) + \                                  SizeWin400_RAS_MaxEntryName + 1 + \                                  SizeWin400_RAS_MaxPhoneNumber + 1 + \                                  SizeWin400_RAS_MaxCallbackNumber + 1 + \                                  UNLEN + 1 + \                                  PWLEN + 1 + \                                  DNLEN + 1)#define SizeWin400_RASCONNSTATUS (sizeof(DWORD) + \                                  sizeof(RASCONNSTATE) + \                                  sizeof(DWORD) + \                                  SizeWin400_RAS_MaxDeviceType + 1 + \                                  SizeWin400_RAS_MaxDeviceName + 1)class PRASDLL : public PDynaLink{  PCLASSINFO(PRASDLL, PDynaLink)  public:    PRASDLL();  DWORD (FAR PASCAL *Dial)(LPRASDIALEXTENSIONS,LPTSTR,LPRASDIALPARAMS,DWORD,LPVOID,LPHRASCONN);  DWORD (FAR PASCAL *HangUp)(HRASCONN);  DWORD (FAR PASCAL *GetConnectStatus)(HRASCONN,LPRASCONNSTATUS);  DWORD (FAR PASCAL *EnumConnections)(LPRASCONN,LPDWORD,LPDWORD);  DWORD (FAR PASCAL *EnumEntries)(LPTSTR,LPTSTR,LPRASENTRYNAME,LPDWORD,LPDWORD);  DWORD (FAR PASCAL *GetEntryProperties)(LPTSTR, LPTSTR, LPRASENTRY, LPDWORD, LPBYTE, LPDWORD);  DWORD (FAR PASCAL *SetEntryProperties)(LPTSTR, LPTSTR, LPRASENTRY, DWORD, LPBYTE, DWORD);  DWORD (FAR PASCAL *DeleteEntry)(LPTSTR, LPTSTR);  DWORD (FAR PASCAL *ValidateEntryName)(LPTSTR, LPTSTR);  DWORD (FAR PASCAL *GetProjectionInfo)(HRASCONN, RASPROJECTION, LPVOID, LPDWORD);} Ras;PRASDLL::PRASDLL()#ifdef _WIN32  : PDynaLink("RASAPI32.DLL")#else  : PDynaLink("RASAPI16.DLL")#endif{  if (!GetFunction("RasDialA", (Function &)Dial) ||      !GetFunction("RasHangUpA", (Function &)HangUp) ||      !GetFunction("RasGetConnectStatusA", (Function &)GetConnectStatus) ||      !GetFunction("RasEnumConnectionsA", (Function &)EnumConnections) ||      !GetFunction("RasEnumEntriesA", (Function &)EnumEntries))    Close();  GetFunction("RasGetEntryPropertiesA", (Function &)GetEntryProperties);  GetFunction("RasSetEntryPropertiesA", (Function &)SetEntryProperties);  GetFunction("RasDeleteEntryA", (Function &)DeleteEntry);  GetFunction("RasValidateEntryNameA", (Function &)ValidateEntryName);  GetFunction("RasGetProjectionInfoA", (Function &)GetProjectionInfo);}#define new PNEWstatic BOOL IsWinVer401(){  OSVERSIONINFO verinf;  verinf.dwOSVersionInfoSize = sizeof(verinf);  GetVersionEx(&verinf);  if (verinf.dwPlatformId != VER_PLATFORM_WIN32_NT)    return FALSE;  if (verinf.dwMajorVersion < 4)    return FALSE;  return TRUE;}PRemoteConnection::PRemoteConnection(){  Construct();}PRemoteConnection::PRemoteConnection(const PString & name)  : remoteName(name){  Construct();}PRemoteConnection::~PRemoteConnection(){  Close();}BOOL PRemoteConnection::Open(const PString & name,                             const PString & user,                             const PString & pass,                             BOOL existing){  if (name != remoteName) {    Close();    remoteName = name;  }  userName = user;  password = pass;  return Open(existing);}BOOL PRemoteConnection::Open(const PString & name, BOOL existing){  if (name != remoteName) {    Close();    remoteName = name;  }  return Open(existing);}PObject::Comparison PRemoteConnection::Compare(const PObject & obj) const{  PAssert(PIsDescendant(&obj, PRemoteConnection), PInvalidCast);  return remoteName.Compare(((const PRemoteConnection &)obj).remoteName);}PINDEX PRemoteConnection::HashFunction() const{  return remoteName.HashFunction();}void PRemoteConnection::Construct(){  rasConnection = NULL;  osError = SUCCESS;}BOOL PRemoteConnection::Open(BOOL existing){  Close();  if (!Ras.IsLoaded())    return FALSE;  BOOL isVer401 = IsWinVer401();  RASCONN connection;  connection.dwSize = isVer401 ? sizeof(RASCONN) : SizeWin400_RASCONN;  LPRASCONN connections = &connection;  DWORD size = sizeof(connection);  DWORD numConnections;  osError = Ras.EnumConnections(connections, &size, &numConnections);  if (osError == ERROR_BUFFER_TOO_SMALL) {    connections = new RASCONN[size/connection.dwSize];    connections[0].dwSize = connection.dwSize;    osError = Ras.EnumConnections(connections, &size, &numConnections);  }  if (osError == 0) {    for (DWORD i = 0; i < numConnections; i++) {      if (remoteName == connections[i].szEntryName) {        rasConnection = connections[i].hrasconn;        break;      }    }  }  if (connections != &connection)    delete [] connections;  if (rasConnection != NULL && GetStatus() == Connected) {    osError = 0;    return TRUE;  }  rasConnection = NULL;  if (existing)    return FALSE;  RASDIALPARAMS params;  memset(&params, 0, sizeof(params));  params.dwSize = isVer401 ? sizeof(params) : SizeWin400_RASDIALPARAMS;  if (remoteName[0] != '.') {    PAssert(remoteName.GetLength() < sizeof(params.szEntryName)-1, PInvalidParameter);    strcpy(params.szEntryName, remoteName);  }  else {    PAssert(remoteName.GetLength() < sizeof(params.szPhoneNumber), PInvalidParameter);    strcpy(params.szPhoneNumber, remoteName(1, P_MAX_INDEX));  }  strcpy(params.szUserName, userName);  strcpy(params.szPassword, password);  osError = Ras.Dial(NULL, NULL, &params, 0, NULL, &rasConnection);  if (osError == 0)    return TRUE;  if (rasConnection != NULL) {    Ras.HangUp(rasConnection);    rasConnection = NULL;  }  SetLastError(osError);  return FALSE;}void PRemoteConnection::Close()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -