From 4d4a5905cabe0edf37553a0b7315d6fd2080da1c Mon Sep 17 00:00:00 2001 From: Frank Li Date: Fri, 17 Apr 2009 22:07:58 +0800 Subject: [PATCH] Send email to multi person success and add CC and TO list Signed-off-by: Frank Li --- src/Resources/TortoiseProcENG.rc | Bin 422160 -> 422340 bytes src/TortoiseProc/Patch.cpp | 51 ++-- src/TortoiseProc/Patch.h | 5 +- src/TortoiseProc/SVNProgressDlg.cpp | 41 ++- src/TortoiseProc/SVNProgressDlg.h | 9 +- src/TortoiseProc/resource.h | Bin 157250 -> 157434 bytes src/Utils/HwSMTP.cpp | 232 +++++++++++--- src/Utils/HwSMTP.h | 41 ++- src/Utils/NetAdapterInfo.cpp | 581 ------------------------------------ src/Utils/NetAdapterInfo.h | 100 ------- 10 files changed, 286 insertions(+), 774 deletions(-) delete mode 100644 src/Utils/NetAdapterInfo.cpp delete mode 100644 src/Utils/NetAdapterInfo.h diff --git a/src/Resources/TortoiseProcENG.rc b/src/Resources/TortoiseProcENG.rc index 833d3950e8b8ccd8416870488f329195b0b73bed..b27fb366a3ede38fbddbaf1d98d458b99e8495c0 100644 GIT binary patch delta 137 zcmbR6Nb<;I$%Yoj7N!>F7M2#)Eo_rwr%#AvW)TiyaAXK#2w_lQP+|yXNM*=lNSVGc zg++OKfgY>K^b4_U8>V|%v5HMskYwSTz9^PiNZ1vqK8V2|h(UT>8HyN+reEC1Dm%R( imQ6`Gp1}nu=LZxA$+|G)GvrMd1b delta 72 zcmV-O0Js0d;~9|R8GwWVgaU*Egam{Iv<8x02_OI<03rZW0A-gyxdkbga4G}}mmoI; e1edm61`e0-T?U|+$Rz|0mkeqK8n;|u251sXOcpBu diff --git a/src/TortoiseProc/Patch.cpp b/src/TortoiseProc/Patch.cpp index 7bebda9..f9a06f8 100644 --- a/src/TortoiseProc/Patch.cpp +++ b/src/TortoiseProc/Patch.cpp @@ -31,46 +31,28 @@ void CPatch::ConvertToArray(CString &to,CStringArray &Array) int CPatch::Send(CString &pathfile,CString &TO,CString &CC,bool bAttachment) { - CSmtp mail; - - if(mail.GetLastError() != CSMTP_NO_ERROR ) - { - return -1; - } - + CHwSMTP mail; if(this->Parser(pathfile) ) return -1; - int at=TO.Find(_T('@')); - int start =0; - TO = TO.Tokenize(_T(";"),start); - - CString server=TO.Mid(at+1); - - PDNS_RECORD pDnsRecord; - - DnsQuery(server, DNS_TYPE_MX,DNS_QUERY_BYPASS_CACHE, - NULL, //Contains DNS server IP address. - &pDnsRecord, //Resource record that contains the response. - NULL); - - CString name,address; - GetNameAddress(this->m_Author,name,address); - - - CStringArray attchments,CCArray; + CStringArray attachments,CCArray; if(bAttachment) { - attchments.Add(pathfile); + attachments.Add(pathfile); } - ConvertToArray(CC,CCArray); + //ConvertToArray(CC,CCArray); - SendEmail(FALSE,pDnsRecord->Data.MX.pNameExchange, - NULL,NULL,FALSE,address,TO,this->m_Author,TO,this->m_Subject,m_strBody,0,&attchments,&CCArray); - - DnsRecordListFree(pDnsRecord,DnsFreeRecordList); + CString sender; + sender.Format(_T("%s <%s> "),g_Git.GetUserName(),g_Git.GetUserEmail()); + if(mail.SendSpeedEmail(this->m_Author,TO,this->m_Subject,this->m_strBody,NULL,&attachments,CC,25,sender)) + return 0; + else + { + this->m_LastError=mail.GetLastErrorText(); + return -1; + } #if 0 CRegString server(REG_SMTP_SERVER); CRegDWORD port(REG_SMTP_PORT,25); @@ -142,7 +124,7 @@ int CPatch::Parser(CString &pathfile) g_Git.StringAppend(&m_strBody,&m_Body[0],CP_ACP); - + return 0; } void CPatch::GetNameAddress(CString &in, CString &name,CString &address) @@ -159,7 +141,7 @@ void CPatch::GetNameAddress(CString &in, CString &name,CString &address) else address=in; } - +#if 0 void CPatch::AddRecipient(CSmtp &mail, CString &tolist, bool isCC) { int pos=0; @@ -191,4 +173,5 @@ void CPatch::AddRecipient(CSmtp &mail, CString &tolist, bool isCC) mail.AddRecipient(CUnicodeUtils::GetUTF8(one)); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TortoiseProc/Patch.h b/src/TortoiseProc/Patch.h index 8cc6c7a..769ff49 100644 --- a/src/TortoiseProc/Patch.h +++ b/src/TortoiseProc/Patch.h @@ -1,6 +1,6 @@ #pragma once -#include "csmtp.h" +#include "hwsmtp.h" #define REG_SMTP_SERVER _T("Software\\TortoiseGit\\EMAIL\\SMTPSERVER") #define REG_SMTP_PORT _T("Software\\TortoiseGit\\EMAIL\\PORT") @@ -11,7 +11,7 @@ class CPatch { protected: - void AddRecipient(CSmtp &mail, CString &tolist, bool isCC= FALSE); +// void AddRecipient(CSmtp &mail, CString &tolist, bool isCC= FALSE); void GetNameAddress(CString &in, CString &name,CString &address); public: CPatch(); @@ -19,6 +19,7 @@ public: int Parser(CString &pathfile); int Send(CString &pathfile,CString &To, CString &CC,bool bAttachment); + CString m_LastError; CString m_Author; CString m_Date; CString m_Subject; diff --git a/src/TortoiseProc/SVNProgressDlg.cpp b/src/TortoiseProc/SVNProgressDlg.cpp index 2d5a888..febe50b 100644 --- a/src/TortoiseProc/SVNProgressDlg.cpp +++ b/src/TortoiseProc/SVNProgressDlg.cpp @@ -217,7 +217,9 @@ void CGitProgressDlg::AddItemToList() } -BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action +BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t action, + int status , + CString *strErr /* svn_node_kind_t kind, const CString& mime_type, svn_wc_notify_state_t content_state, @@ -234,6 +236,7 @@ BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t actio data->path = path; data->action = action; data->sPathColumnText=path.GetGitPathString(); + data->bAuxItem = false; #if 0 data->kind = kind; data->mime_type = mime_type; @@ -268,11 +271,30 @@ BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t actio data->color = m_Colors.GetColor(CColors::Added); // } break; - case git_wc_notify_sendmail: - data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL); + case git_wc_notify_sendmail_start: + data->bAuxItem = true; + data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_START); data->color = m_Colors.GetColor(CColors::Modified); break; + case git_wc_notify_sendmail_error: + data->bAuxItem = true; + data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_ERROR); + if(strErr) + data->sPathColumnText = *strErr; + else + data->sPathColumnText.Empty(); + data->color = m_Colors.GetColor(CColors::Modified); + break; + + case git_wc_notify_sendmail_done: + + data->sActionColumnText.LoadString(IDS_SVNACTION_SENDMAIL_DONE); + data->sPathColumnText.Empty(); + data->color = m_Colors.GetColor(CColors::Modified); + break; + + case git_wc_notify_resolved: data->sActionColumnText.LoadString(IDS_SVNACTION_RESOLVE); break; @@ -493,7 +515,7 @@ BOOL CGitProgressDlg::Notify(const CTGitPath& path, git_wc_notify_action_t actio { m_arData.push_back(data); AddItemToList(); - if (/*(!data->bAuxItem)&&*/(m_itemCount > 0)) + if ((!data->bAuxItem) && (m_itemCount > 0)) { m_itemCount--; @@ -2690,9 +2712,14 @@ bool CGitProgressDlg::CmdSendMail(CString& sWindowTitle, bool& /*localoperation* for(int i=0;im_SendMailTO, - this->m_SendMailCC,this->m_SendMailFlags&SENDMAIL_ATTACHMENT); - Notify(m_targetPathList[i],git_wc_notify_sendmail); + Notify(m_targetPathList[i],git_wc_notify_sendmail_start); + int ret=patch.Send((CString&)m_targetPathList[i].GetWinPathString(),this->m_SendMailTO, + this->m_SendMailCC,this->m_SendMailFlags&SENDMAIL_ATTACHMENT); + if(ret) + { + Notify(m_targetPathList[i],git_wc_notify_sendmail_error,ret,&patch.m_LastError); + } + Notify(m_targetPathList[i],git_wc_notify_sendmail_done,ret); } return true; } \ No newline at end of file diff --git a/src/TortoiseProc/SVNProgressDlg.h b/src/TortoiseProc/SVNProgressDlg.h index 7d7d102..898e588 100644 --- a/src/TortoiseProc/SVNProgressDlg.h +++ b/src/TortoiseProc/SVNProgressDlg.h @@ -69,7 +69,9 @@ typedef enum typedef enum { git_wc_notify_add, - git_wc_notify_sendmail, + git_wc_notify_sendmail_start, + git_wc_notify_sendmail_error, + git_wc_notify_sendmail_done, git_wc_notify_resolved }git_wc_notify_action_t; @@ -198,7 +200,10 @@ private: protected: //Need update in the future implement the virtual methods from Git base class - virtual BOOL Notify(const CTGitPath& path, git_wc_notify_action_t action + virtual BOOL Notify(const CTGitPath& path, + git_wc_notify_action_t action, + int status = 0, + CString *strErr =NULL /* git_node_kind_t kind, const CString& mime_type, git_wc_notify_state_t content_state, diff --git a/src/TortoiseProc/resource.h b/src/TortoiseProc/resource.h index d474ad01fb9a88fb6202befcb8470bc4b4db50b0..ed8db1c18f4bf9a05a83795ba0837808234d4bce 100644 GIT binary patch delta 98 zcmX?fhV$21&W0AoElg@*jPa8VKMPN{3S+u4dBIeP>0)6_0*vv~H #ifdef _DEBUG @@ -29,14 +29,16 @@ public: BOOL bMustAuth, LPCTSTR lpszAddrFrom, LPCTSTR lpszAddrTo, - LPCTSTR lpszSenderName, + LPCTSTR lpszFromName, LPCTSTR lpszReceiverName, LPCTSTR lpszSubject, LPCTSTR lpszBody, LPCTSTR lpszCharSet, CStringArray *pStrAryAttach, - CStringArray *pStrAryCC, - UINT nSmtpSrvPort + LPCTSTR pStrAryCC, + UINT nSmtpSrvPort, + LPCTSTR pSender, + LPCTSTR pToList ) { m_csSmtpSrvHost = GET_SAFE_STRING(lpszSmtpSrvHost); @@ -45,15 +47,18 @@ public: m_bMustAuth = bMustAuth; m_csAddrFrom = GET_SAFE_STRING(lpszAddrFrom); m_csAddrTo = GET_SAFE_STRING(lpszAddrTo); - m_csSenderName = GET_SAFE_STRING(lpszSenderName); + m_csFromName = GET_SAFE_STRING(lpszFromName); m_csReceiverName = GET_SAFE_STRING(lpszReceiverName); m_csSubject = GET_SAFE_STRING(lpszSubject); m_csBody = GET_SAFE_STRING(lpszBody); m_csCharSet = GET_SAFE_STRING(lpszCharSet); + m_StrCC = GET_SAFE_STRING(pStrAryCC); + m_csSender = GET_SAFE_STRING(pSender); + m_csToList = GET_SAFE_STRING(pToList); + if ( pStrAryAttach ) m_StrAryAttach.Append ( *pStrAryAttach ); - if ( pStrAryCC ) - m_StrAryCC.Append ( *pStrAryCC ); + m_nSmtpSrvPort = nSmtpSrvPort; m_hThread = NULL; } @@ -65,14 +70,16 @@ public: BOOL m_bMustAuth; CString m_csAddrFrom; CString m_csAddrTo; - CString m_csSenderName; + CString m_csFromName; CString m_csReceiverName; CString m_csSubject; CString m_csBody; CString m_csCharSet; CStringArray m_StrAryAttach; - CStringArray m_StrAryCC; + CString m_StrCC; UINT m_nSmtpSrvPort; + CString m_csSender; + CString m_csToList; HANDLE m_hThread; }; @@ -96,6 +103,116 @@ CHwSMTP::~CHwSMTP() { } +void CHwSMTP::GetNameAddress(CString &in, CString &name,CString &address) +{ + int start,end; + start=in.Find(_T('<')); + end=in.Find(_T('>')); + + if(start >=0 && end >=0) + { + name=in.Left(start); + address=in.Mid(start+1,end-start-1); + } + else + address=in; +} + +CString CHwSMTP::GetServerAddress(CString &email) +{ + CString str; + int start,end; + + start = email.Find(_T("<")); + end = email.Find(_T(">")); + + if(start>=0 && end >=0) + { + str=email.Mid(start+1,end-start-1); + } + else + { + str=email; + } + + start = str.Find(_T('@')); + return str.Mid(start+1); + +} + +BOOL CHwSMTP::SendSpeedEmail + ( + LPCTSTR lpszAddrFrom, + LPCTSTR lpszAddrTo, + LPCTSTR lpszSubject, + LPCTSTR lpszBody, + LPCTSTR lpszCharSet, // ×Ö·û¼¯ÀàÐÍ£¬ÀýÈ磺·±ÌåÖÐÎÄÕâÀïÓ¦ÊäÈë"big5"£¬¼òÌåÖÐÎÄʱÊäÈë"gb2312" + CStringArray *pStrAryAttach, + LPCTSTR pStrAryCC, + UINT nSmtpSrvPort, + LPCTSTR pSend + ) +{ + + BOOL ret=true; + CString To; + To += GET_SAFE_STRING(lpszAddrTo); + To += _T(";"); + To += GET_SAFE_STRING(pStrAryCC); + + std::map> Address; + + int start = 0; + while( start >= 0 ) + { + CString one= To.Tokenize(_T(";"),start); + one=one.Trim(); + if(one.IsEmpty()) + continue; + + CString addr; + addr = GetServerAddress(one); + if(addr.IsEmpty()) + continue; + + + Address[addr].push_back(one); + + } + + std::map>::iterator itr1 = Address.begin(); + for( ; itr1 != Address.end(); ++itr1 ) + { + PDNS_RECORD pDnsRecord; + + DnsQuery(itr1->first , + DNS_TYPE_MX,DNS_QUERY_BYPASS_CACHE, + NULL, //Contains DNS server IP address. + &pDnsRecord, //Resource record that contains the response. + NULL + ); + + CString to; + to.Empty(); + for(int i=0;isecond.size();i++) + { + to+=itr1->second[i]; + to+=_T(";"); + } + if(to.IsEmpty()) + continue; + + if(!SendEmail(pDnsRecord->Data.MX.pNameExchange,NULL,NULL,false, + lpszAddrFrom,to,lpszSubject,lpszBody,lpszCharSet,pStrAryAttach,pStrAryCC, + 25,pSend,lpszAddrTo)) + ret = false; + + //SendEmail(itr1.first,NULL,NULL,false,lpszAddrFrom,,lpszFromname); + DnsRecordListFree(pDnsRecord,DnsFreeRecordList); + } + + return ret; +} BOOL CHwSMTP::SendEmail ( LPCTSTR lpszSmtpSrvHost, LPCTSTR lpszUserName, @@ -103,19 +220,21 @@ BOOL CHwSMTP::SendEmail ( BOOL bMustAuth, LPCTSTR lpszAddrFrom, LPCTSTR lpszAddrTo, - LPCTSTR lpszSenderName, - LPCTSTR lpszReceiverName, LPCTSTR lpszSubject, LPCTSTR lpszBody, LPCTSTR lpszCharSet, // ×Ö·û¼¯ÀàÐÍ£¬ÀýÈ磺·±ÌåÖÐÎÄÕâÀïÓ¦ÊäÈë"big5"£¬¼òÌåÖÐÎÄʱÊäÈë"gb2312" CStringArray *pStrAryAttach/*=NULL*/, - CStringArray *pStrAryCC/*=NULL*/, - UINT nSmtpSrvPort/*=25*/ + LPCTSTR pStrAryCC/*=NULL*/, + UINT nSmtpSrvPort,/*=25*/ + LPCTSTR pSender, + LPCTSTR pToList ) { - TRACE ( _T("·¢ËÍÓʼþ£º%s, %s, %s\n"), lpszAddrTo, lpszReceiverName, lpszBody ); + TRACE ( _T("·¢ËÍÓʼþ£º%s, %s\n"), lpszAddrTo, lpszBody ); m_StrAryAttach.RemoveAll(); - m_StrAryCC.RemoveAll(); + + m_StrCC += GET_SAFE_STRING(pStrAryCC); + m_csSmtpSrvHost = GET_SAFE_STRING ( lpszSmtpSrvHost ); if ( m_csSmtpSrvHost.GetLength() <= 0 ) { @@ -133,18 +252,21 @@ BOOL CHwSMTP::SendEmail ( m_csAddrFrom = GET_SAFE_STRING ( lpszAddrFrom ); m_csAddrTo = GET_SAFE_STRING ( lpszAddrTo ); - m_csSenderName = GET_SAFE_STRING ( lpszSenderName ); - m_csReceiverName = GET_SAFE_STRING ( lpszReceiverName ); +// m_csFromName = GET_SAFE_STRING ( lpszFromName ); +// m_csReceiverName = GET_SAFE_STRING ( lpszReceiverName ); m_csSubject = GET_SAFE_STRING ( lpszSubject ); m_csBody = GET_SAFE_STRING ( lpszBody ); + + this->m_csSender = GET_SAFE_STRING(pSender); + this->m_csToList = GET_SAFE_STRING(pToList); + m_nSmtpSrvPort = nSmtpSrvPort; + if ( lpszCharSet && lstrlen(lpszCharSet) > 0 ) m_csCharSet.Format ( _T("\r\n\tcharset=\"%s\"\r\n"), lpszCharSet ); if ( - m_csAddrFrom.GetLength() <= 0 || m_csAddrTo.GetLength() <= 0 || - m_csSenderName.GetLength() <= 0 || m_csReceiverName.GetLength() <= 0 || - m_csSubject.GetLength() <= 0 || m_csBody.GetLength() <= 0 + m_csAddrFrom.GetLength() <= 0 || m_csAddrTo.GetLength() <= 0 ) { m_csLastError.Format ( _T("Parameter Error!") ); @@ -158,12 +280,8 @@ BOOL CHwSMTP::SendEmail ( if ( m_StrAryAttach.GetSize() < 1 ) m_csMIMEContentType = _T( "text/plain"); - if ( pStrAryCC ) - { - m_StrAryCC.Append ( *pStrAryCC ); - } - // ´´½¨Socket + m_SendSock.Close(); if ( !m_SendSock.Create () ) { m_csLastError.Format ( _T("Create socket failed!") ); @@ -347,21 +465,39 @@ BOOL CHwSMTP::auth() BOOL CHwSMTP::SendHead() { CString str; - str.Format( _T("MAIL From: <%s>\r\n"), m_csAddrFrom ); + CString name,addr; + GetNameAddress(m_csAddrFrom,name,addr); + + str.Format( _T("MAIL From: <%s>\r\n"), addr ); if ( !Send ( str ) ) return FALSE; if ( !GetResponse ( _T("250") ) ) return FALSE; - str.Format(_T("RCPT TO: <%s>\r\n"), m_csAddrTo ); - if ( !Send ( str ) ) return FALSE; - if ( !GetResponse ( _T("250") ) ) return FALSE; + int start=0; + while(start>=0) + { + CString one=m_csAddrTo.Tokenize(_T(";"),start); + one=one.Trim(); + if(one.IsEmpty()) + continue; + + GetNameAddress(one,name,addr); + + str.Format(_T("RCPT TO: <%s>\r\n"), addr ); + if ( !Send ( str ) ) return FALSE; + if ( !GetResponse ( _T("250") ) ) return FALSE; + } + +#if 0 for ( int i=0; i\r\n"), m_StrAryCC.GetAt(i) ); if ( !Send ( str ) ) return FALSE; if ( !GetResponse ( _T("250") ) ) return FALSE; } +#endif + if ( !Send ( CString(_T("DATA\r\n") ) ) ) return FALSE; if ( !GetResponse ( CString(_T("354") )) ) return FALSE; @@ -378,7 +514,22 @@ BOOL CHwSMTP::SendSubject() csSubject += GetCompatibleString(FormatDateTime (tNow, _T("%a, %d %b %y %H:%M:%S %Z")).GetBuffer(0),FALSE); } csSubject += _T("\r\n"); - csSubject += FormatString ( _T("From: %s\r\nTo: %s\r\n"), m_csSenderName, m_csReceiverName ); + csSubject += FormatString ( _T("From: %s\r\n"), this->m_csAddrFrom); + + csSubject += FormatString ( _T("CC: %s\r\n"), this->m_StrCC); + + if(m_csSender.IsEmpty()) + m_csSender = this->m_csAddrFrom; + + csSubject += FormatString ( _T("Sender: %s\r\n"), this->m_csSender); + + if(this->m_csToList.IsEmpty()) + m_csToList = m_csReceiverName; + + csSubject += FormatString ( _T("To: %s\r\n"), this->m_csToList); + + CString m_csToList; + csSubject += FormatString ( _T("Subject: %s\r\n"), m_csSubject ); csSubject += FormatString ( _T("X-Mailer: TortoiseGit\r\nMIME-Version: 1.0\r\nContent-Type: %s; %s boundary=%s\r\n\r\n") , m_csMIMEContentType, m_csCharSet, m_csPartBoundary ); @@ -512,14 +663,13 @@ DWORD WINAPI ThreadProc_SendEmail( LPVOID lpParameter ) pEMailObject->m_bMustAuth, pEMailObject->m_csAddrFrom, pEMailObject->m_csAddrTo, - pEMailObject->m_csSenderName, - pEMailObject->m_csReceiverName, pEMailObject->m_csSubject, pEMailObject->m_csBody, pEMailObject->m_csCharSet, &pEMailObject->m_StrAryAttach, - &pEMailObject->m_StrAryCC, - pEMailObject->m_nSmtpSrvPort + pEMailObject->m_StrCC, + pEMailObject->m_nSmtpSrvPort, + pEMailObject->m_csSender ); if ( !bRet) { @@ -551,14 +701,16 @@ BOOL SendEmail ( BOOL bMustAuth, LPCTSTR lpszAddrFrom, LPCTSTR lpszAddrTo, - LPCTSTR lpszSenderName, + LPCTSTR lpszFromName, LPCTSTR lpszReceiverName, LPCTSTR lpszSubject, LPCTSTR lpszBody, LPCTSTR lpszCharSet/*=NULL*/, CStringArray *pStrAryAttach/*=NULL*/, - CStringArray *pStrAryCC/*=NULL*/, - UINT nSmtpSrvPort/*=25*/ + LPCTSTR pStrAryCC/*=NULL*/, + UINT nSmtpSrvPort/*=25*/, + LPCTSTR lpszSender, + LPCTSTR lpszToList ) { if ( !lpszSmtpSrvHost || lstrlen(lpszSmtpSrvHost) < 1 || @@ -576,14 +728,16 @@ BOOL SendEmail ( bMustAuth, lpszAddrFrom, lpszAddrTo, - lpszSenderName, + lpszFromName, lpszReceiverName, lpszSubject, lpszBody, lpszCharSet, pStrAryAttach, pStrAryCC, - nSmtpSrvPort + nSmtpSrvPort, + lpszSender, + lpszToList ); if ( !pEMailObject ) return FALSE; diff --git a/src/Utils/HwSMTP.h b/src/Utils/HwSMTP.h index a3e1ea1..87d0f23 100644 --- a/src/Utils/HwSMTP.h +++ b/src/Utils/HwSMTP.h @@ -58,21 +58,37 @@ public: BOOL bMustAuth, LPCTSTR lpszAddrFrom, LPCTSTR lpszAddrTo, - LPCTSTR lpszSenderName, - LPCTSTR lpszReceiverName, LPCTSTR lpszSubject, LPCTSTR lpszBody, LPCTSTR lpszCharSet, // ×Ö·û¼¯ÀàÐÍ£¬ÀýÈ磺·±ÌåÖÐÎÄÕâÀïÓ¦ÊäÈë"big5"£¬¼òÌåÖÐÎÄʱÊäÈë"gb2312" CStringArray *pStrAryAttach=NULL, - CStringArray *pStrAryCC=NULL, - UINT nSmtpSrvPort=25 + LPCTSTR pStrAryCC=NULL, + UINT nSmtpSrvPort=25, + LPCTSTR pSend = NULL, + LPCTSTR pToList = NULL + ); + BOOL SendSpeedEmail + ( + LPCTSTR lpszAddrFrom, + LPCTSTR lpszAddrTo, + LPCTSTR lpszSubject, + LPCTSTR lpszBody, + LPCTSTR lpszCharSet, // ×Ö·û¼¯ÀàÐÍ£¬ÀýÈ磺·±ÌåÖÐÎÄÕâÀïÓ¦ÊäÈë"big5"£¬¼òÌåÖÐÎÄʱÊäÈë"gb2312" + CStringArray *pStrAryAttach=NULL, + LPCTSTR pStrAryCC=NULL, + UINT nSmtpSrvPort=25, + LPCTSTR pSend = NULL ); CHwSMTP(); virtual ~CHwSMTP(); +protected: + CString GetServerAddress(CString &email); + void GetNameAddress(CString &in, CString &name,CString &address); + private: BOOL SendSubject(); - CStringArray m_StrAryCC; + CString m_StrCC; BOOL SendHead(); BOOL auth(); BOOL SendEmail(); @@ -87,10 +103,13 @@ private: CString m_csPasswd; CString m_csAddrFrom; CString m_csAddrTo; - CString m_csSenderName; + CString m_csFromName; CString m_csReceiverName; CString m_csSubject; CString m_csBody; + CString m_csSender; + CString m_csToList; + private: BOOL m_bMustAuth; UINT m_nSmtpSrvPort; @@ -114,15 +133,19 @@ BOOL SendEmail ( BOOL bMustAuth, // SMTP ·þÎñÆ÷ÐèÒªÉí·ÝÑéÖ¤ LPCTSTR lpszAddrFrom, // ·¢ËÍÕß E-Mail µØÖ· LPCTSTR lpszAddrTo, // ½ÓÊÕÕßµÄ E-Mail µØÖ· - LPCTSTR lpszSenderName, // ·¢ËÍÕßµÄÃû×Ö£¬ÀýÈ磺лºìΰ + LPCTSTR lpszFromName, // ·¢ËÍÕßµÄÃû×Ö£¬ÀýÈ磺лºìΰ LPCTSTR lpszReceiverName, // ½ÓÊÕÕßµÄÃû×Ö£¬ÀýÈ磺ÕÅ·É LPCTSTR lpszSubject, // ÓʼþÖ÷Ìâ LPCTSTR lpszBody, // ÓʼþÄÚÈÝ LPCTSTR lpszCharSet=NULL, // ×Ö·û¼¯ÀàÐÍ£¬ÀýÈ磺·±ÌåÖÐÎÄÕâÀïÓ¦ÊäÈë"big5"£¬¼òÌåÖÐÎÄʱÊäÈë"gb2312" CStringArray *pStrAryAttach=NULL, // ¸½¼þÎļþ·¾¶£¬¿ÉÒÔ¶à¸ö - CStringArray *pStrAryCC=NULL, // ³­ËÍ E-Mail µØÖ·£¬¿ÉÒÔ¶à¸ö - UINT nSmtpSrvPort=25 // SMTP ·þÎñÆ÷µÄ TCP ¶Ë¿ÚºÅ + LPCTSTR pStrAryCC=NULL, // ³­ËÍ E-Mail µØÖ·£¬¿ÉÒÔ¶à¸ö + UINT nSmtpSrvPort=25, // SMTP ·þÎñÆ÷µÄ TCP ¶Ë¿ÚºÅ + LPCTSTR pSend = NULL, + LPCTSTR ToList = NULL ); + + void EndOfSMTP (); #endif // !defined(AFX_HwSMTP_H__633A52B7_1CBE_41D7_BDA3_188D98D692AF__INCLUDED_) diff --git a/src/Utils/NetAdapterInfo.cpp b/src/Utils/NetAdapterInfo.cpp deleted file mode 100644 index d993a90..0000000 --- a/src/Utils/NetAdapterInfo.cpp +++ /dev/null @@ -1,581 +0,0 @@ -// OneNetAdapterInfo.cpp: implementation of the COneNetAdapterInfo class. -// -////////////////////////////////////////////////////////////////////// - -#include "stdafx.h" -#include "SpeedPostEmail.h" -#include "NetAdapterInfo.h" -#include "Iphlpapi.h" -#include "IpTypes.h" - -#ifdef _DEBUG -#undef THIS_FILE -static char THIS_FILE[]=__FILE__; -#define new DEBUG_NEW -#endif - -#define MALLOC( bytes ) ::HeapAlloc( ::GetProcessHeap(), HEAP_ZERO_MEMORY, (bytes) ) -#define FREE( ptr ) if( ptr ) ::HeapFree( ::GetProcessHeap(), 0, ptr ) -#define REMALLOC( ptr, bytes ) ::HeapReAlloc( ::GetProcessHeap(), HEAP_ZERO_MEMORY, ptr, bytes ) - -#pragma comment ( lib, "iphlpapi.lib" ) - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// -COneNetAdapterInfo::COneNetAdapterInfo ( IP_ADAPTER_INFO *pAdptInfo ) -{ - m_bInitOk = FALSE; - memset ( &m_PhysicalAddress, 0, sizeof(m_PhysicalAddress) ); - m_nPhysicalAddressLength = 0; - ASSERT ( pAdptInfo ); - memcpy ( &m_AdptInfo, pAdptInfo, sizeof(IP_ADAPTER_INFO) ); - if ( !Init() ) - { - TRACE ( _T("[%s - %s] initialize failed."), Get_Name(), Get_Desc() ); - } -} - -COneNetAdapterInfo::~COneNetAdapterInfo() -{ - -} - -// -// ¸ù¾Ý´«ÈëµÄ pAdptInfo ÐÅÏ¢À´»ñÈ¡Ö¸¶¨Íø¿¨µÄ»ù±¾ÐÅÏ¢ -// -BOOL COneNetAdapterInfo::Init () -{ - IP_ADDR_STRING* pNext = NULL; - IP_PER_ADAPTER_INFO* pPerAdapt = NULL; - ULONG ulLen = 0; - DWORD dwErr = ERROR_SUCCESS; - ASSERT ( m_AdptInfo.AddressLength > 0 ); - t_IPINFO iphold; - - // ½«±äÁ¿Çå¿Õ - m_bInitOk = FALSE; - m_csName.Empty (); - m_csDesc.Empty (); - m_CurIPInfo.csIP.Empty (); - m_CurIPInfo.csSubnet.Empty (); - m_Ary_IP.RemoveAll (); - m_Ary_DNS.RemoveAll (); - m_Ary_Gateway.RemoveAll (); - -#ifndef _UNICODE - m_csName = m_AdptInfo.AdapterName; - m_csDesc = m_AdptInfo.Description; -#else - USES_CONVERSION; - m_csName = A2W ( m_AdptInfo.AdapterName ); - m_csDesc = A2W ( m_AdptInfo.Description ); -#endif - - // »ñÈ¡µ±Ç°ÕýÔÚʹÓõÄIPµØÖ· - if ( m_AdptInfo.CurrentIpAddress ) - { - m_CurIPInfo.csIP = m_AdptInfo.CurrentIpAddress->IpAddress.String; - m_CurIPInfo.csSubnet = m_AdptInfo.CurrentIpAddress->IpMask.String; - } - else - { - m_CurIPInfo.csIP = _T("0.0.0.0"); - m_CurIPInfo.csSubnet = _T("0.0.0.0"); - } - - // »ñÈ¡±¾Íø¿¨ÖÐËùÓеÄIPµØÖ· - pNext = &( m_AdptInfo.IpAddressList ); - while ( pNext ) - { - iphold.csIP = pNext->IpAddress.String; - iphold.csSubnet = pNext->IpMask.String; - m_Ary_IP.Add ( iphold ); - pNext = pNext->Next; - } - - // »ñÈ¡±¾Íø¿¨ÖÐËùÓеÄÍø¹ØÐÅÏ¢ - pNext = &( m_AdptInfo.GatewayList ); - while ( pNext ) - { - m_Ary_Gateway.Add ( A2W( pNext->IpAddress.String )); - pNext = pNext->Next; - } - - // »ñÈ¡±¾Íø¿¨ÖÐËùÓÐµÄ DNS - dwErr = ::GetPerAdapterInfo ( m_AdptInfo.Index, pPerAdapt, &ulLen ); - if( dwErr == ERROR_BUFFER_OVERFLOW ) - { - pPerAdapt = ( IP_PER_ADAPTER_INFO* ) MALLOC( ulLen ); - dwErr = ::GetPerAdapterInfo( m_AdptInfo.Index, pPerAdapt, &ulLen ); - - // if we succeed than we need to drop into our loop - // and fill the dns array will all available IP - // addresses. - if( dwErr == ERROR_SUCCESS ) - { - pNext = &( pPerAdapt->DnsServerList ); - while( pNext ) - { - m_Ary_DNS.Add( A2W( pNext->IpAddress.String ) ); - pNext = pNext->Next; - } - m_bInitOk = TRUE; - } - - // this is done outside the dwErr == ERROR_SUCCES just in case. the macro - // uses NULL pointer checking so it is ok if pPerAdapt was never allocated. - FREE( pPerAdapt ); - } - - return m_bInitOk; -} - -// -// ÊÍ·Å»òˢб¾Íø¿¨µÄIPµØÖ· -// -BOOL COneNetAdapterInfo::RenewReleaseIP( Func_OperateIP func ) -{ - IP_INTERFACE_INFO* pInfo = NULL; - BOOL bDidIt = FALSE; - ULONG ulLen = 0; - int nNumInterfaces = 0; - int nCnt = 0; - DWORD dwErr = ERROR_SUCCESS; - - dwErr = ::GetInterfaceInfo ( pInfo, &ulLen ); - if( dwErr == ERROR_INSUFFICIENT_BUFFER ) - { - pInfo = ( IP_INTERFACE_INFO* ) MALLOC( ulLen ); - dwErr = ::GetInterfaceInfo ( pInfo, &ulLen ); - - if( dwErr != ERROR_SUCCESS ) - { - return FALSE; - } - } - - // we can assume from here out that we have a valid array - // of IP_INTERFACE_INFO structures due to the error - // checking one above. - nNumInterfaces = ulLen / sizeof( IP_INTERFACE_INFO ); - for( nCnt = 0; nCnt < nNumInterfaces; nCnt++ ) - { - if( pInfo[ nCnt ].Adapter[ 0 ].Index == m_AdptInfo.Index ) - { - dwErr = func( &pInfo[ nCnt ].Adapter[ 0 ] ); - - // free all used memory since we don't need it any more. - FREE( pInfo ); - - bDidIt = ( dwErr == NO_ERROR ); - if( ! bDidIt ) { - return FALSE; - } - - break; - } - } - - return bDidIt; -} - -//////////////////////////////////////////////////////////// -// Desc: -// Releases the addresses held by this adapter. -//////////////////////////////////////////////////////////// -BOOL COneNetAdapterInfo::ReleaseIP() -{ - return RenewReleaseIP ( ::IpReleaseAddress ); -} - -//////////////////////////////////////////////////////////// -// Desc: -// Renews the address being held by this adapter. -//////////////////////////////////////////////////////////// -BOOL COneNetAdapterInfo::RenewIP() -{ - return RenewReleaseIP ( ::IpRenewAddress ); -} - -CString COneNetAdapterInfo::GetAdapterTypeString () -{ - UINT nType = m_AdptInfo.Type; - CString csType = _T(""); - switch( nType ) - { - case MIB_IF_TYPE_OTHER: csType = _T("Other"); break; - case MIB_IF_TYPE_ETHERNET: csType = _T("Ethernet"); break; - case MIB_IF_TYPE_TOKENRING: csType = _T("Token Ring"); break; - case MIB_IF_TYPE_FDDI: csType = _T("FDDI"); break; - case MIB_IF_TYPE_PPP: csType = _T("PPP"); break; - case MIB_IF_TYPE_LOOPBACK: csType = _T("Loopback"); break; - case MIB_IF_TYPE_SLIP: csType = _T("SLIP"); break; - default: csType = _T("Invalid Adapter Type"); break; - }; - - return csType; -} - -time_t COneNetAdapterInfo::Get_LeaseObtained() const { return m_AdptInfo.LeaseObtained; } -time_t COneNetAdapterInfo::Get_LeaseExpired() const { return m_AdptInfo.LeaseExpires; } -int COneNetAdapterInfo::Get_IPCount() const { return (int)m_Ary_IP.GetSize(); } -int COneNetAdapterInfo::Get_DNSCount() const { return (int)m_Ary_DNS.GetSize(); } -CString COneNetAdapterInfo::Get_CurrentIP() const { return m_CurIPInfo.csIP; } -BOOL COneNetAdapterInfo::Is_DHCP_Used() const { return m_AdptInfo.DhcpEnabled; } -CString COneNetAdapterInfo::Get_DHCPAddr() const { return m_AdptInfo.DhcpServer.IpAddress.String; } -BOOL COneNetAdapterInfo::Is_Wins_Used() const { return m_AdptInfo.HaveWins; } -CString COneNetAdapterInfo::Get_PrimaryWinsServer() const { return m_AdptInfo.PrimaryWinsServer.IpAddress.String; } -CString COneNetAdapterInfo::Get_SecondaryWinsServer() const { return m_AdptInfo.SecondaryWinsServer.IpAddress.String; } -int COneNetAdapterInfo::Get_GatewayCount() const { return m_Ary_Gateway.GetSize(); } -DWORD COneNetAdapterInfo::Get_AdapterIndex() const { return m_AdptInfo.Index; } -UINT COneNetAdapterInfo::Get_AdapterType() const { return m_AdptInfo.Type; } - -CString COneNetAdapterInfo::Get_IPAddr ( int nIndex ) const -{ - CString csAddr = _T(""); - if ( nIndex >= 0 && nIndex < m_Ary_IP.GetSize() ) - { - csAddr = m_Ary_IP.GetAt(nIndex).csIP; - } - - return csAddr; -} - -CString COneNetAdapterInfo::Get_Subnet ( int nIndex ) const -{ - CString csAddr = _T(""); - if ( nIndex >= 0 && nIndex < m_Ary_IP.GetSize() ) - { - csAddr = m_Ary_IP.GetAt(nIndex).csSubnet; - } - - return csAddr; -} - -CString COneNetAdapterInfo::Get_DNSAddr ( int nIndex ) const -{ - CString csAddr = _T(""); - if ( nIndex >= 0 && nIndex < m_Ary_DNS.GetSize() ) - { - csAddr = m_Ary_DNS.GetAt(nIndex); - } - - return csAddr; -} - -CString COneNetAdapterInfo::Get_GatewayAddr ( int nIndex ) const -{ - CString csAddr = _T(""); - if ( nIndex >= 0 && nIndex < m_Ary_Gateway.GetSize() ) - { - csAddr = m_Ary_Gateway.GetAt(nIndex); - } - - return csAddr; -} - -void COneNetAdapterInfo::Set_PhysicalAddress ( int nPhysicalAddressLength, BYTE *pPhysicalAddress ) -{ - if ( !pPhysicalAddress ) return; - m_nPhysicalAddressLength = __min(nPhysicalAddressLength,sizeof(m_PhysicalAddress)); - memcpy ( m_PhysicalAddress, pPhysicalAddress, m_nPhysicalAddressLength ); -} - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -CNetAdapterInfo::CNetAdapterInfo () -{ -} - -CNetAdapterInfo::~CNetAdapterInfo() -{ - DeleteAllNetAdapterInfo (); -} - -void CNetAdapterInfo::DeleteAllNetAdapterInfo() -{ - for ( int i=0; i=0 - ÍøÂçÊÊÅäÆ÷ÊýÁ¿ -// -int CNetAdapterInfo::EnumNetworkAdapters () -{ - DeleteAllNetAdapterInfo (); - - IP_ADAPTER_INFO* pAdptInfo = NULL; - IP_ADAPTER_INFO* pNextAd = NULL; - ULONG ulLen = 0; - int nCnt = 0; - - DWORD dwError = ::GetAdaptersInfo ( pAdptInfo, &ulLen ); - if( dwError != ERROR_BUFFER_OVERFLOW ) return -1; - pAdptInfo = ( IP_ADAPTER_INFO* )MALLOC ( ulLen ); - dwError = ::GetAdaptersInfo( pAdptInfo, &ulLen ); - if ( dwError != ERROR_SUCCESS ) return -1; - - pNextAd = pAdptInfo; - while( pNextAd ) - { - COneNetAdapterInfo *pOneNetAdapterInfo = new COneNetAdapterInfo ( pNextAd ); - if ( pOneNetAdapterInfo ) - { - m_Ary_NetAdapterInfo.Add ( pOneNetAdapterInfo ); - } - nCnt ++; - pNextAd = pNextAd->Next; - } - - // free any memory we allocated from the heap before - // exit. we wouldn't wanna leave memory leaks now would we? ;p - FREE( pAdptInfo ); - - return nCnt; -} - -COneNetAdapterInfo* CNetAdapterInfo::Get_OneNetAdapterInfo ( int nIndex ) -{ - if ( nIndex < 0 || nIndex >= m_Ary_NetAdapterInfo.GetSize() ) - { - ASSERT ( FALSE ); - return NULL; - } - - return (COneNetAdapterInfo*)m_Ary_NetAdapterInfo.GetAt(nIndex); -} - -COneNetAdapterInfo* CNetAdapterInfo::Get_OneNetAdapterInfo ( DWORD dwIndex ) -{ - for ( int i=0; iGet_AdapterIndex() == dwIndex ) - return pOneNetAdapterInfo; - } - - return NULL; -} - -void CNetAdapterInfo::Refresh () -{ - DeleteAllNetAdapterInfo (); - EnumNetworkAdapters (); - GetAdapterAddress (); -} - -// -// »ñÈ¡Íø¿¨µÄµØÖ·ÐÅÏ¢£¬Ö÷ÒªÊÇMACµØÖ· -// -BOOL CNetAdapterInfo::GetAdapterAddress () -{ - DWORD dwSize = 0; - DWORD dwRetVal = 0; - BOOL bRet = FALSE; - - int i = 0; - - // Set the flags to pass to GetAdaptersAddresses - ULONG flags = GAA_FLAG_INCLUDE_PREFIX; - - // default to unspecified address family (both) - // AF_INET for IPv4, AF_INET6 for IPv6 - ULONG family = AF_UNSPEC; - - LPVOID lpMsgBuf = NULL; - - PIP_ADAPTER_ADDRESSES pAddresses = NULL; - ULONG outBufLen = 0; - - PIP_ADAPTER_ADDRESSES pCurrAddresses = NULL; - PIP_ADAPTER_UNICAST_ADDRESS pUnicast = NULL; - PIP_ADAPTER_ANYCAST_ADDRESS pAnycast = NULL; - PIP_ADAPTER_MULTICAST_ADDRESS pMulticast = NULL; - IP_ADAPTER_DNS_SERVER_ADDRESS *pDnServer = NULL; - IP_ADAPTER_PREFIX *pPrefix = NULL; - - outBufLen = sizeof (IP_ADAPTER_ADDRESSES); - pAddresses = (IP_ADAPTER_ADDRESSES *) MALLOC(outBufLen); - if (pAddresses == NULL) return FALSE; - - // Make an initial call to GetAdaptersAddresses to get the - // size needed into the outBufLen variable - if ( ::GetAdaptersAddresses ( family, flags, NULL, pAddresses, &outBufLen ) == ERROR_BUFFER_OVERFLOW ) - { - FREE(pAddresses); - pAddresses = (IP_ADAPTER_ADDRESSES *) MALLOC(outBufLen); - } - if (pAddresses == NULL) return FALSE; - - // Make a second call to GetAdapters Addresses to get the - // actual data we want -#ifdef _DEBUG - TRACE ( _T("Memory allocated for GetAdapterAddresses = %d bytes\n"), outBufLen); - TRACE ( _T("Calling GetAdaptersAddresses function with family = " ) ); - if (family == AF_INET) - TRACE(_T("AF_INET\n")); - if (family == AF_INET6) - TRACE(_T("AF_INET6\n")); - if (family == AF_UNSPEC) - TRACE(_T("AF_UNSPEC\n\n")); -#endif - dwRetVal = GetAdaptersAddresses ( family, flags, NULL, pAddresses, &outBufLen ); - - if ( dwRetVal == NO_ERROR ) - { - // If successful, output some information from the data we received - pCurrAddresses = pAddresses; - while (pCurrAddresses) - { - TRACE(_T("\tLength of the IP_ADAPTER_ADDRESS struct: %ld\n"), - pCurrAddresses->Length); - TRACE(_T("\tIfIndex (IPv4 interface): %u\n"), pCurrAddresses->IfIndex); - TRACE(_T("\tAdapter name: %s\n"), pCurrAddresses->AdapterName); - - pUnicast = pCurrAddresses->FirstUnicastAddress; - if (pUnicast != NULL) - { - for (i = 0; pUnicast != NULL; i++) - pUnicast = pUnicast->Next; - TRACE(_T("\tNumber of Unicast Addresses: %d\n"), i); - } - else - { - TRACE(_T("\tNo Unicast Addresses\n")); - } - - pAnycast = pCurrAddresses->FirstAnycastAddress; - if (pAnycast) - { - for (i = 0; pAnycast != NULL; i++) - pAnycast = pAnycast->Next; - TRACE(_T("\tNumber of Anycast Addresses: %d\n"), i); - } - else - { - TRACE(_T("\tNo Anycast Addresses\n")); - } - - pMulticast = pCurrAddresses->FirstMulticastAddress; - if (pMulticast) - { - for (i = 0; pMulticast != NULL; i++) - pMulticast = pMulticast->Next; - TRACE(_T("\tNumber of Multicast Addresses: %d\n"), i); - } - else - { - TRACE(_T("\tNo Multicast Addresses\n")); - } - - pDnServer = pCurrAddresses->FirstDnsServerAddress; - if (pDnServer) - { - for (i = 0; pDnServer != NULL; i++) - pDnServer = pDnServer->Next; - TRACE(_T("\tNumber of DNS Server Addresses: %d\n"), i); - } - else - { - TRACE(_T("\tNo DNS Server Addresses\n")); - } - - TRACE(_T("\tDNS Suffix: %wS\n"), pCurrAddresses->DnsSuffix); - TRACE(_T("\tDescription: %wS\n"), pCurrAddresses->Description); - TRACE(_T("\tFriendly name: %wS\n"), pCurrAddresses->FriendlyName); - - if (pCurrAddresses->PhysicalAddressLength != 0) - { - TRACE(_T("\tPhysical address: ")); - for (i = 0; i < (int) pCurrAddresses->PhysicalAddressLength; i++) - { - if ( i == (int)(pCurrAddresses->PhysicalAddressLength - 1)) - TRACE(_T("%.2X\n"), (int) pCurrAddresses->PhysicalAddress[i]); - else - TRACE(_T("%.2X-"), (int) pCurrAddresses->PhysicalAddress[i]); - } - - COneNetAdapterInfo* pNetAdapterInfo = Get_OneNetAdapterInfo ( pCurrAddresses->IfIndex ); - if ( pNetAdapterInfo ) - { - pNetAdapterInfo->Set_PhysicalAddress ( pCurrAddresses->PhysicalAddressLength, pCurrAddresses->PhysicalAddress ); - } - } - TRACE(_T("\tFlags: %ld\n"), pCurrAddresses->Flags); - TRACE(_T("\tMtu: %lu\n"), pCurrAddresses->Mtu); - TRACE(_T("\tIfType: %ld\n"), pCurrAddresses->IfType); - TRACE(_T("\tOperStatus: %ld\n"), pCurrAddresses->OperStatus); - TRACE(_T("\tIpv6IfIndex (IPv6 interface): %u\n"), - pCurrAddresses->Ipv6IfIndex); - TRACE(_T("\tZoneIndices (hex): ")); - for (i = 0; i < 16; i++) - TRACE(_T("%lx "), pCurrAddresses->ZoneIndices[i]); - TRACE(_T("\n")); - - pPrefix = pCurrAddresses->FirstPrefix; - if (pPrefix) - { - for (i = 0; pPrefix != NULL; i++) - pPrefix = pPrefix->Next; - TRACE(_T("\tNumber of IP Adapter Prefix entries: %d\n"), i); - } - else - { - TRACE(_T("\tNumber of IP Adapter Prefix entries: 0\n")); - } - - TRACE(_T("\n")); - - pCurrAddresses = pCurrAddresses->Next; - bRet = TRUE; - } - } - else - { - TRACE(_T("Call to GetAdaptersAddresses failed with error: %d\n"), dwRetVal ); - if (dwRetVal == ERROR_NO_DATA) - { - TRACE(_T("\tNo addresses were found for the requested parameters\n")); - } - else - { - if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwRetVal, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) & lpMsgBuf, 0, NULL)) - { - TRACE(_T("\tError: %s"), lpMsgBuf); - LocalFree(lpMsgBuf); - FREE(pAddresses); - } - } - bRet = FALSE; - } - FREE(pAddresses); - - return bRet; -} - -CString MacAddress2String ( int nPhysicalAddressLength, BYTE *pPhysicalAddress ) -{ - ASSERT ( nPhysicalAddressLength >= 6 ); - AfxIsValidAddress(pPhysicalAddress,nPhysicalAddressLength,TRUE); - CString csMacAddress, csOneCell; - for ( int i=0; i 1000 -#pragma once -#endif // _MSC_VER > 1000 - -/* - ˵Ã÷ - »ñÈ¡Íø¿¨ÐÅÏ¢£¬°üÀ¨IPµØÖ·¡¢DNS¡¢Íø¹Ø¡¢ÊÇ·ñΪ¶¯Ì¬IP¡¢DHCPµÈ£¬¸ÃÀ಻ÓöÁȡע²á±í¼´¿É»ñÈ¡×îеÄÍø¿¨ÐÅÏ¢ -ÁíÍ⻹¿ÉÒÔÊÍ·ÅÍø¿¨µØÖ·²¢ÖØÐÂˢеØÖ· -*/ - -#include -#include -#include - -typedef struct _IPINFO -{ - CString csIP; - CString csSubnet; -} t_IPINFO; -typedef CArray t_Ary_IPINFO; - -typedef DWORD ( __stdcall *Func_OperateIP)( PIP_ADAPTER_INDEX_MAP AdapterInfo ); -CString MacAddress2String ( int nPhysicalAddressLength, BYTE *pPhysicalAddress ); - -class COneNetAdapterInfo -{ -public: - COneNetAdapterInfo ( IP_ADAPTER_INFO *pAdptInfo ); - virtual ~COneNetAdapterInfo(); - CString Get_Name() { return m_csName; } - CString Get_Desc() { return m_csDesc; } - BOOL ReleaseIP(); - BOOL RenewIP(); - CString GetAdapterTypeString (); - - time_t Get_LeaseObtained() const; - time_t Get_LeaseExpired() const; - int Get_IPCount() const; - int Get_DNSCount() const; - CString Get_CurrentIP() const; - BOOL Is_DHCP_Used() const; - CString Get_DHCPAddr() const; - BOOL Is_Wins_Used() const; - CString Get_PrimaryWinsServer() const; - CString Get_SecondaryWinsServer() const; - int Get_GatewayCount() const; - DWORD Get_AdapterIndex() const; - UINT Get_AdapterType() const; - CString Get_IPAddr ( int nIndex ) const; - CString Get_Subnet ( int nIndex ) const; - CString Get_DNSAddr ( int nIndex ) const; - CString Get_GatewayAddr ( int nIndex ) const; - void Set_PhysicalAddress ( int nPhysicalAddressLength, BYTE *pPhysicalAddress ); - CString Get_PhysicalAddressStr () { return MacAddress2String ( m_nPhysicalAddressLength, m_PhysicalAddress ); } - -private: - BOOL Init (); - BOOL RenewReleaseIP( Func_OperateIP func ); - -public: - BOOL m_bInitOk; -private: - IP_ADAPTER_INFO m_AdptInfo; - CString m_csName; - CString m_csDesc; - t_IPINFO m_CurIPInfo; // this is also in the ip address list but this is the address currently active. - t_Ary_IPINFO m_Ary_IP; - CStringArray m_Ary_DNS; - CStringArray m_Ary_Gateway; - BYTE m_PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH]; - int m_nPhysicalAddressLength; -}; - -class CNetAdapterInfo -{ -public: - CNetAdapterInfo (); - ~CNetAdapterInfo(); - int GetNetCardCount () { return m_Ary_NetAdapterInfo.GetSize(); } - COneNetAdapterInfo* Get_OneNetAdapterInfo ( int nIndex ); - COneNetAdapterInfo* CNetAdapterInfo::Get_OneNetAdapterInfo ( DWORD dwIndex ); - void Refresh (); - -private: - int EnumNetworkAdapters (); - void DeleteAllNetAdapterInfo(); - BOOL GetAdapterAddress (); - -private: - CPtrArray m_Ary_NetAdapterInfo; -}; - -#endif // !defined(AFX_OneNetAdapterInfo_H__A899410F_5CFF_4958_80C4_D1AC693F62E3__INCLUDED_) -- 2.11.0