From 8549e48fbb8520027d4d8ba74b6f12f3042faebc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 27 May 2012 21:30:30 +0000 Subject: ipv6 sync git-svn-id: http://svn.miranda-ng.org/main/trunk@205 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/jabber_byte.cpp | 54 ++++++++++++++----------------------- protocols/JabberG/jabber_file.cpp | 43 +++++++++++------------------ protocols/JabberG/jabber_proto.h | 1 - protocols/JabberG/jabber_thread.cpp | 22 +++------------ 4 files changed, 39 insertions(+), 81 deletions(-) (limited to 'protocols/JabberG') diff --git a/protocols/JabberG/jabber_byte.cpp b/protocols/JabberG/jabber_byte.cpp index 67015b3bcd..aa030aa7e8 100644 --- a/protocols/JabberG/jabber_byte.cpp +++ b/protocols/JabberG/jabber_byte.cpp @@ -85,10 +85,6 @@ void CJabberProto::IqResultProxyDiscovery( HXML iqNode, CJabberIqInfo* pInfo ) void JabberByteSendConnection( HANDLE hConn, DWORD /*dwRemoteIP*/, void* extra ) { CJabberProto* ppro = ( CJabberProto* )extra; - SOCKET s; - SOCKADDR_IN saddr; - int len; - WORD localPort; TCHAR szPort[8]; JABBER_BYTE_TRANSFER *jbt; int recvResult, bytesParsed; @@ -97,20 +93,11 @@ void JabberByteSendConnection( HANDLE hConn, DWORD /*dwRemoteIP*/, void* extra ) char* buffer; int datalen; - localPort = 0; - if (( s = JCallService( MS_NETLIB_GETSOCKET, ( WPARAM ) hConn, 0 )) != INVALID_SOCKET ) { - len = sizeof( saddr ); - if ( getsockname( s, ( SOCKADDR * ) &saddr, &len ) != SOCKET_ERROR ) - localPort = ntohs( saddr.sin_port ); - } - if ( localPort == 0 ) { - ppro->Log( "bytestream_send_connection unable to determine the local port, connection closed." ); - Netlib_CloseHandle( hConn ); - return; - } + NETLIBCONNINFO connInfo = { sizeof(connInfo) }; + CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hConn, (LPARAM)&connInfo); - mir_sntprintf( szPort, SIZEOF( szPort ), _T("%d"), localPort ); - ppro->Log( "bytestream_send_connection incoming connection accepted: local_port=" TCHAR_STR_PARAM, szPort ); + mir_sntprintf( szPort, SIZEOF( szPort ), _T("%u"), connInfo.wPort ); + ppro->Log( "bytestream_send_connection incoming connection accepted: %s", connInfo.szIpPort ); if (( item = ppro->ListGetItemPtr( LIST_BYTE, szPort )) == NULL ) { ppro->Log( "No bytestream session is currently active, connection closed." ); @@ -157,9 +144,7 @@ void JabberByteSendConnection( HANDLE hConn, DWORD /*dwRemoteIP*/, void* extra ) void CJabberProto::ByteSendThread( JABBER_BYTE_TRANSFER *jbt ) { - char* localAddr; - char* localAddrInternal; - struct in_addr in; + char* localAddr = NULL; DBVARIANT dbv; TCHAR szPort[8]; HANDLE hEvent = NULL; @@ -216,12 +201,10 @@ void CJabberProto::ByteSendThread( JABBER_BYTE_TRANSFER *jbt ) HXML query = iq << XQUERY( _T(JABBER_FEAT_BYTESTREAMS)) << XATTR( _T("sid"), jbt->sid ); if ( bDirect ) { - localAddr = NULL; - if ( m_options.BsDirectManual == TRUE ) { - if ( !DBGetContactSettingString( NULL, m_szModuleName, "BsDirectAddr", &dbv )) { - localAddr = NEWSTR_ALLOCA( dbv.pszVal ); - JFreeVariant( &dbv ); - } } + if ( m_options.BsDirectManual ) { + if ( !DBGetContactSettingString( NULL, m_szModuleName, "BsDirectAddr", &dbv )) + localAddr = dbv.pszVal; + } NETLIBBIND nlb = {0}; nlb.cbSize = sizeof( NETLIBBIND ); @@ -234,12 +217,9 @@ void CJabberProto::ByteSendThread( JABBER_BYTE_TRANSFER *jbt ) delete jbt; return; } - if ( localAddr == NULL ) { - in.S_un.S_addr = htonl(nlb.dwExternalIP); - localAddr = NEWSTR_ALLOCA( inet_ntoa( in )); - } - in.S_un.S_addr = htonl(nlb.dwInternalIP); - localAddrInternal = NEWSTR_ALLOCA( inet_ntoa( in )); + + if ( localAddr == NULL ) + localAddr = (char*)CallService( MS_NETLIB_ADDRESSTOSTRING, 1, nlb.dwExternalIP ); mir_sntprintf( szPort, SIZEOF( szPort ), _T("%d"), nlb.wPort ); JABBER_LIST_ITEM *item = ListAdd( LIST_BYTE, szPort ); @@ -248,8 +228,14 @@ void CJabberProto::ByteSendThread( JABBER_BYTE_TRANSFER *jbt ) jbt->hEvent = hEvent; jbt->hSendEvent = CreateEvent( NULL, FALSE, FALSE, NULL ); query << XCHILD( _T("streamhost")) << XATTR( _T("jid"), m_ThreadInfo->fullJID ) << XATTR( _T("host"), _A2T(localAddr)) << XATTRI( _T("port"), nlb.wPort ); - if ( strcmp( localAddr, localAddrInternal )) - query << XCHILD( _T("streamhost")) << XATTR( _T("jid"), m_ThreadInfo->fullJID ) << XATTR( _T("host"), _A2T(localAddrInternal)) << XATTRI( _T("port"), nlb.wPort ); + + NETLIBIPLIST* ihaddr = ( NETLIBIPLIST* )CallService( MS_NETLIB_GETMYIP, 1, 0 ); + for ( unsigned i = 0; i < ihaddr->cbNum; ++i ) + if ( strcmp( localAddr, ihaddr->szIp[i] )) + query << XCHILD( _T("streamhost")) << XATTR( _T("jid"), m_ThreadInfo->fullJID ) << XATTR( _T("host"), _A2T(ihaddr->szIp[i])) << XATTRI( _T("port"), nlb.wPort ); + + mir_free( ihaddr ); + mir_free( localAddr ); } if ( jbt->bProxyDiscovered ) diff --git a/protocols/JabberG/jabber_file.cpp b/protocols/JabberG/jabber_file.cpp index 9577c310e9..3cce546bef 100644 --- a/protocols/JabberG/jabber_file.cpp +++ b/protocols/JabberG/jabber_file.cpp @@ -196,24 +196,13 @@ int CJabberProto::FileReceiveParse( filetransfer* ft, char* buffer, int datalen void JabberFileServerConnection( JABBER_SOCKET hConnection, DWORD /*dwRemoteIP*/, void* extra ) { CJabberProto* ppro = ( CJabberProto* )extra; - WORD localPort = 0; - SOCKET s = JCallService( MS_NETLIB_GETSOCKET, ( WPARAM ) hConnection, 0 ); - if ( s != INVALID_SOCKET ) { - SOCKADDR_IN saddr; - int len = sizeof( saddr ); - if ( getsockname( s, ( SOCKADDR * ) &saddr, &len ) != SOCKET_ERROR ) { - localPort = ntohs( saddr.sin_port ); - } - } - if ( localPort == 0 ) { - ppro->Log( "Unable to determine the local port, file server connection closed." ); - Netlib_CloseHandle( hConnection ); - return; - } - TCHAR szPort[20]; - mir_sntprintf( szPort, SIZEOF( szPort ), _T("%d"), localPort ); - ppro->Log( "File server incoming connection accepted: local_port=" TCHAR_STR_PARAM, szPort ); + NETLIBCONNINFO connInfo = { sizeof(connInfo) }; + CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hConnection, (LPARAM)&connInfo); + + TCHAR szPort[10]; + mir_sntprintf( szPort, SIZEOF( szPort ), _T("%d"), connInfo.wPort ); + ppro->Log( "File server incoming connection accepted: %s", connInfo.szIpPort ); JABBER_LIST_ITEM *item = ppro->ListGetItemPtr( LIST_FILE, szPort ); if ( item == NULL ) { @@ -311,9 +300,6 @@ void __cdecl CJabberProto::FileServerThread( filetransfer* ft ) else p = ft->std.ptszFiles[i]; - in_addr in; - in.S_un.S_addr = m_dwJabberLocalIP; - TCHAR* pFileName = JabberHttpUrlEncode( p ); if ( pFileName != NULL ) { int id = SerialNext(); @@ -321,20 +307,22 @@ void __cdecl CJabberProto::FileServerThread( filetransfer* ft ) ft->iqId = ( TCHAR* )mir_alloc( sizeof(TCHAR)*( strlen( JABBER_IQID )+20 )); wsprintf( ft->iqId, _T(JABBER_IQID)_T("%d"), id ); - char *myAddr; + char *myAddr = NULL; DBVARIANT dbv; if (m_options.BsDirect && m_options.BsDirectManual) { - if ( !DBGetContactSettingString( NULL, m_szModuleName, "BsDirectAddr", &dbv )) { - myAddr = NEWSTR_ALLOCA( dbv.pszVal ); - JFreeVariant( &dbv ); - } - else myAddr = inet_ntoa( in ); + if ( !DBGetContactSettingString( NULL, m_szModuleName, "BsDirectAddr", &dbv )) + myAddr = dbv.pszVal; } - else myAddr = inet_ntoa( in ); + + if ( myAddr == NULL ) + myAddr = (char*)CallService( MS_NETLIB_ADDRESSTOSTRING, 1, nlb.dwExternalIP ); char szAddr[ 256 ]; mir_snprintf( szAddr, sizeof(szAddr), "http://%s:%d/%s", myAddr, nlb.wPort, pFileName ); + mir_free( pFileName ); + mir_free( myAddr ); + int len = lstrlen(ptszResource) + lstrlen(ft->jid) + 2; TCHAR* fulljid = ( TCHAR* )alloca( sizeof( TCHAR )*len ); wsprintf( fulljid, _T("%s/%s"), ft->jid, ptszResource ); @@ -347,7 +335,6 @@ void __cdecl CJabberProto::FileServerThread( filetransfer* ft ) Log( "Waiting for the file to be sent..." ); WaitForSingleObject( hEvent, INFINITE ); - mir_free( pFileName ); } Log( "File sent, advancing to the next file..." ); JSendBroadcast( ft->std.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0 ); diff --git a/protocols/JabberG/jabber_proto.h b/protocols/JabberG/jabber_proto.h index 9947fd155b..663c1d3ecd 100644 --- a/protocols/JabberG/jabber_proto.h +++ b/protocols/JabberG/jabber_proto.h @@ -260,7 +260,6 @@ struct CJabberProto : public PROTO_INTERFACE TCHAR* m_szJabberJID; char* m_szStreamId; - DWORD m_dwJabberLocalIP; BOOL m_bJabberConnected; // TCP connection to jabber server established BOOL m_bJabberOnline; // XMPP connection initialized and we can send XMPP packets int m_nJabberSearchID; diff --git a/protocols/JabberG/jabber_thread.cpp b/protocols/JabberG/jabber_thread.cpp index 68712157ab..3c343600c8 100644 --- a/protocols/JabberG/jabber_thread.cpp +++ b/protocols/JabberG/jabber_thread.cpp @@ -132,7 +132,8 @@ void CJabberProto::OnPingReply( HXML, CJabberIqInfo* pInfo ) return; if ( pInfo->GetIqType() == JABBER_IQ_TYPE_FAIL ) { // disconnect because of timeout - SetStatus(ID_STATUS_OFFLINE); + m_ThreadInfo->send( "" ); + m_ThreadInfo->shutdown(); } } @@ -428,17 +429,6 @@ LBL_FatalError: } // Determine local IP - int socket = JCallService( MS_NETLIB_GETSOCKET, ( WPARAM ) info->s, 0 ); - if ( info->type==JABBER_SESSION_NORMAL && socket!=INVALID_SOCKET ) { - struct sockaddr_in saddr; - int len; - - len = sizeof( saddr ); - getsockname( socket, ( struct sockaddr * ) &saddr, &len ); - m_dwJabberLocalIP = saddr.sin_addr.S_un.S_addr; - Log( "Local IP = %s", inet_ntoa( saddr.sin_addr )); - } - if ( info->useSSL ) { Log( "Intializing SSL connection" ); if (!JCallService( MS_NETLIB_STARTSSL, ( WPARAM )info->s, 0)) { @@ -1012,12 +1002,8 @@ void CJabberProto::OnProcessProceed( HXML node, ThreadData* info ) ssl.host = isHosted ? info->manualHost : info->server; if (!JCallService( MS_NETLIB_STARTSSL, ( WPARAM )info->s, ( LPARAM )&ssl)) { Log( "SSL initialization failed" ); - if (info->type == JABBER_SESSION_REGISTER) { - info->send( "" ); - info->shutdown(); - } - else - SetStatus(ID_STATUS_OFFLINE); + info->send( "" ); + info->shutdown(); } else xmlStreamInitialize( "after successful StartTLS" ); -- cgit v1.2.3