diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/AimOscar/aim.h | 4 | ||||
-rw-r--r-- | protocols/AimOscar/client.cpp | 14 | ||||
-rw-r--r-- | protocols/AimOscar/direct_connect.cpp | 21 | ||||
-rw-r--r-- | protocols/AimOscar/direct_connect.h | 3 | ||||
-rw-r--r-- | protocols/AimOscar/file.cpp | 41 | ||||
-rw-r--r-- | protocols/AimOscar/file.h | 13 | ||||
-rw-r--r-- | protocols/AimOscar/proto.cpp | 5 | ||||
-rw-r--r-- | protocols/AimOscar/thread.cpp | 9 | ||||
-rw-r--r-- | protocols/AimOscar/utility.cpp | 6 |
9 files changed, 59 insertions, 57 deletions
diff --git a/protocols/AimOscar/aim.h b/protocols/AimOscar/aim.h index a6d7e737e7..fb6d1071ee 100644 --- a/protocols/AimOscar/aim.h +++ b/protocols/AimOscar/aim.h @@ -1,6 +1,6 @@ /*
Plugin of Miranda IM for communicating with users of the AIM protocol.
-Copyright (c) 2008-2011 Boris Krasnovskiy
+Copyright (c) 2008-2012 Boris Krasnovskiy
Copyright (C) 2005-2006 Aaron Myles Landwehr
This program is free software; you can redistribute it and/or
@@ -86,9 +86,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "packets.h"
#include "proxy.h"
#include "resource.h"
+#include "proto.h"
#include "theme.h"
#include "ui.h"
-#include "proto.h"
// Protocol limits
#define MAX_SCREEN_NAME_LENGTH 97
diff --git a/protocols/AimOscar/client.cpp b/protocols/AimOscar/client.cpp index 2fc4333728..2e0e5c94bf 100644 --- a/protocols/AimOscar/client.cpp +++ b/protocols/AimOscar/client.cpp @@ -251,19 +251,7 @@ int CAimProto::aim_set_profile(HANDLE hServerConn,unsigned short &seqno, char* a int CAimProto::aim_client_ready(HANDLE hServerConn,unsigned short &seqno)
{
- unsigned short offset=0;
- NETLIBBIND nlb = {0};
- nlb.cbSize = sizeof(nlb);
- nlb.pfnNewConnectionV2 = (NETLIBNEWCONNECTIONPROC_V2)aim_direct_connection_initiated;
- nlb.pExtra = this;
- hDirectBoundPort = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)hNetlibPeer, (LPARAM)&nlb);
- if (hDirectBoundPort == NULL)
- {
- ShowPopup(LPGEN("Aim was unable to bind to a port. File transfers may not succeed in some cases."), ERROR_POPUP);
- local_port = 0;
- }
- else
- local_port = nlb.wPort;
+ unsigned short offset = 0;
NETLIBCONNINFO connInfo = { sizeof(connInfo) };
CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hServerConn, (LPARAM)&connInfo);
diff --git a/protocols/AimOscar/direct_connect.cpp b/protocols/AimOscar/direct_connect.cpp index e6b2996ffb..4552b461cf 100644 --- a/protocols/AimOscar/direct_connect.cpp +++ b/protocols/AimOscar/direct_connect.cpp @@ -1,6 +1,6 @@ /*
Plugin of Miranda IM for communicating with users of the AIM protocol.
-Copyright (c) 2008-2009 Boris Krasnovskiy
+Copyright (c) 2008-2012 Boris Krasnovskiy
Copyright (C) 2005-2006 Aaron Myles Landwehr
This program is free software; you can redistribute it and/or
@@ -66,23 +66,18 @@ void __cdecl CAimProto::aim_dc_helper(void* param) //only called when we are ini ft_list.remove_by_ft(ft);
}
-void aim_direct_connection_initiated(HANDLE hNewConnection, DWORD dwRemoteIP, CAimProto* ppro)//for receiving stuff via dc
+void aim_direct_connection_initiated(HANDLE hNewConnection, DWORD, void* extra)//for receiving stuff via dc
{
+ CAimProto* ppro = (CAimProto*)extra;
file_transfer *ft;
- char cip[20];
- ppro->LOG("Buddy connected from IP: %s", long_ip_to_char_ip(dwRemoteIP, cip));
+ NETLIBCONNINFO connInfo = { sizeof(connInfo) };
+ CallService(MS_NETLIB_GETCONNECTIONINFO, (WPARAM)hNewConnection, (LPARAM)&connInfo);
- //okay someone connected to us or we initiated the connection- we need to figure out who they are and if they belong
- for (int i=21; --i; )
- {
- ft = ppro->ft_list.find_by_ip(dwRemoteIP);
-
- if (ft == NULL) ft = ppro->ft_list.find_suitable();
- if (ft || Miranda_Terminated()) break;
- Sleep(100);
- }
+ ppro->LOG("Buddy connected: %s", connInfo.szIpPort);
+ // okay someone connected to us or we initiated the connection- we need to figure out who they are and if they belong
+ ft = ppro->ft_list.find_by_port(connInfo.wPort);
if (ft)
{
ft->hConn = hNewConnection;
diff --git a/protocols/AimOscar/direct_connect.h b/protocols/AimOscar/direct_connect.h index 38caeb33ef..4b164f9181 100644 --- a/protocols/AimOscar/direct_connect.h +++ b/protocols/AimOscar/direct_connect.h @@ -1,5 +1,6 @@ /*
Plugin of Miranda IM for communicating with users of the AIM protocol.
+Copyright (c) 2008-2012 Boris Krasnovskiy
Copyright (C) 2005-2006 Aaron Myles Landwehr
This program is free software; you can redistribute it and/or
@@ -18,6 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef DIRECT_CONNECT_H
#define DIRECT_CONNECT_H
-void aim_direct_connection_initiated(HANDLE hNewConnection, DWORD dwRemoteIP, struct CAimProto*);
+void aim_direct_connection_initiated(HANDLE hNewConnection, DWORD dwRemoteIP, void* extra);
#endif
diff --git a/protocols/AimOscar/file.cpp b/protocols/AimOscar/file.cpp index e1cba43c40..7af67727e8 100644 --- a/protocols/AimOscar/file.cpp +++ b/protocols/AimOscar/file.cpp @@ -1,6 +1,6 @@ /*
Plugin of Miranda IM for communicating with users of the AIM protocol.
-Copyright (c) 2008-2009 Boris Krasnovskiy
+Copyright (c) 2008-2012 Boris Krasnovskiy
Copyright (C) 2005-2006 Aaron Myles Landwehr
This program is free software; you can redistribute it and/or
@@ -496,23 +496,12 @@ file_transfer* ft_list_type::find_by_cookie(char* cookie, HANDLE hContact) return NULL;
}
-file_transfer* ft_list_type::find_by_ip(unsigned long ip)
+file_transfer* ft_list_type::find_by_port(unsigned short port)
{
for (int i = getCount(); i--; )
{
file_transfer *ft = items[i];
- if (ft->accepted && ft->requester && (ft->local_ip == ip || ft->verified_ip == ip))
- return ft;
- }
- return NULL;
-}
-
-file_transfer* ft_list_type::find_suitable(void)
-{
- for (int i = getCount(); i--; )
- {
- file_transfer *ft = items[i];
- if (ft->accepted && ft->requester)
+ if (ft->requester && ft->local_port == port)
return ft;
}
return NULL;
@@ -561,6 +550,8 @@ file_transfer::file_transfer(HANDLE hCont, char* nick, char* cookie) file_transfer::~file_transfer()
{
+ stop_listen();
+
mir_free(file);
mir_free(message);
mir_free(sn);
@@ -577,3 +568,25 @@ file_transfer::~file_transfer() }
CloseHandle(hResumeEvent);
}
+
+void file_transfer::listen(CAimProto* ppro)
+{
+ if (hDirectBoundPort) return;
+
+ NETLIBBIND nlb = {0};
+ nlb.cbSize = sizeof(nlb);
+ nlb.pfnNewConnectionV2 = aim_direct_connection_initiated;
+ nlb.pExtra = ppro;
+ hDirectBoundPort = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)ppro->hNetlibPeer, (LPARAM)&nlb);
+ local_port = hDirectBoundPort ? nlb.wPort : 0;
+}
+
+void file_transfer::stop_listen(void)
+{
+ if (hDirectBoundPort)
+ {
+ Netlib_CloseHandle(hDirectBoundPort);
+ hDirectBoundPort = NULL;
+ local_port = 0;
+ }
+}
diff --git a/protocols/AimOscar/file.h b/protocols/AimOscar/file.h index 29083d2947..591e86b75b 100644 --- a/protocols/AimOscar/file.h +++ b/protocols/AimOscar/file.h @@ -1,6 +1,6 @@ /*
Plugin of Miranda IM for communicating with users of the AIM protocol.
-Copyright (c) 2008-2009 Boris Krasnovskiy
+Copyright (c) 2008-2012 Boris Krasnovskiy
Copyright (C) 2005-2006 Aaron Myles Landwehr
This program is free software; you can redistribute it and/or
@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef FILE_H
#define FILE_H
+struct CAimProto;
+
struct file_transfer
{
HANDLE hContact;
@@ -28,6 +30,7 @@ struct file_transfer HANDLE hConn;
HANDLE hResumeEvent;
+ HANDLE hDirectBoundPort;
char* file;
char* message;
@@ -44,6 +47,7 @@ struct file_transfer unsigned short max_ver;
unsigned short req_num;
+ unsigned short local_port;
bool peer_force_proxy;
bool me_force_proxy;
@@ -54,6 +58,10 @@ struct file_transfer file_transfer(HANDLE hCont, char* nick, char* cookie);
~file_transfer();
+
+ void listen(CAimProto* ppro);
+ void stop_listen(void);
+
};
struct ft_list_type : OBJLIST <file_transfer>
@@ -62,8 +70,7 @@ struct ft_list_type : OBJLIST <file_transfer> file_transfer* find_by_handle(HANDLE hContact);
file_transfer* find_by_cookie(char* cookie, HANDLE hContact);
- file_transfer* find_by_ip(unsigned long ip);
- file_transfer* find_suitable(void);
+ file_transfer* find_by_port(unsigned short port);
bool find_by_ft(file_transfer *ft);
diff --git a/protocols/AimOscar/proto.cpp b/protocols/AimOscar/proto.cpp index c8ea97f3d7..b79f95927c 100644 --- a/protocols/AimOscar/proto.cpp +++ b/protocols/AimOscar/proto.cpp @@ -81,8 +81,6 @@ CAimProto::~CAimProto() RemoveMainMenus();
RemoveContactMenus();
- if(hDirectBoundPort)
- Netlib_CloseHandle(hDirectBoundPort);
if(hServerConn)
Netlib_CloseHandle(hServerConn);
if(hAvatarConn && hAvatarConn != (HANDLE)1)
@@ -571,7 +569,8 @@ HANDLE __cdecl CAimProto::SendFile(HANDLE hContact, const PROTOCHAR* szDescripti }
else
{
- aim_send_file(hServerConn, seqno, detected_ip, local_port, false, ft);
+ ft->listen(this);
+ aim_send_file(hServerConn, seqno, detected_ip, ft->local_port, false, ft);
}
DBFreeVariant(&dbv);
diff --git a/protocols/AimOscar/thread.cpp b/protocols/AimOscar/thread.cpp index 724b6ae2aa..e8044f90d2 100644 --- a/protocols/AimOscar/thread.cpp +++ b/protocols/AimOscar/thread.cpp @@ -1,6 +1,6 @@ /*
Plugin of Miranda IM for communicating with users of the AIM protocol.
-Copyright (c) 2008-2009 Boris Krasnovskiy
+Copyright (c) 2008-2012 Boris Krasnovskiy
Copyright (C) 2005-2006 Aaron Myles Landwehr
This program is free software; you can redistribute it and/or
@@ -31,6 +31,7 @@ void __cdecl CAimProto::accept_file_thread(void* param)//buddy sending file LOG("Connected to proxy ip that buddy specified.");
ft->hConn = hConn;
ForkThread(&CAimProto::aim_proxy_helper, ft);
+ ft->stop_listen();
}
}
else if (ft->me_force_proxy) //we are forcing proxy
@@ -42,6 +43,7 @@ void __cdecl CAimProto::accept_file_thread(void* param)//buddy sending file ft->requester = true;
ft->hConn = hConn;
ForkThread(&CAimProto::aim_proxy_helper, ft);
+ ft->stop_listen();
}
}
else
@@ -55,6 +57,7 @@ void __cdecl CAimProto::accept_file_thread(void* param)//buddy sending file ft->hConn = hConn;
aim_file_ad(hServerConn, seqno, ft->sn, ft->icbm_cookie, false, ft->max_ver);
ForkThread(&CAimProto::aim_dc_helper, ft);
+ ft->stop_listen();
}
else if (ft->sending)
{
@@ -64,13 +67,15 @@ void __cdecl CAimProto::accept_file_thread(void* param)//buddy sending file ft->hConn = hConn;
ft->requester = true;
ForkThread(&CAimProto::aim_proxy_helper, ft);
+ ft->stop_listen();
}
}
else
{
LOG("Failed to connect to buddy- asking buddy to connect to us.");
+ ft->listen(this);
ft->requester = true;
- aim_send_file(hServerConn, seqno, detected_ip, local_port, false, ft);
+ aim_send_file(hServerConn, seqno, detected_ip, ft->local_port, false, ft);
return;
}
}
diff --git a/protocols/AimOscar/utility.cpp b/protocols/AimOscar/utility.cpp index dfa18843ad..b1a2709d74 100644 --- a/protocols/AimOscar/utility.cpp +++ b/protocols/AimOscar/utility.cpp @@ -36,12 +36,6 @@ void CAimProto::broadcast_status(int status) Netlib_Shutdown(hServerConn);
}
- if (hDirectBoundPort)
- {
- Netlib_CloseHandle(hDirectBoundPort);
- hDirectBoundPort=NULL;
- }
-
if (hMailConn && hMailConn != (HANDLE)1)
{
aim_sendflap(hMailConn,0x04,0,NULL,mail_seqno);
|