From 48540940b6c28bb4378abfeb500ec45a625b37b6 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Tue, 15 May 2012 10:38:20 +0000 Subject: initial commit git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/jabber_ws.cpp | 94 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 protocols/JabberG/jabber_ws.cpp (limited to 'protocols/JabberG/jabber_ws.cpp') diff --git a/protocols/JabberG/jabber_ws.cpp b/protocols/JabberG/jabber_ws.cpp new file mode 100644 index 0000000000..1a0b423f7d --- /dev/null +++ b/protocols/JabberG/jabber_ws.cpp @@ -0,0 +1,94 @@ +/* + +Jabber Protocol Plugin for Miranda IM +Copyright ( C ) 2002-04 Santithorn Bunchua +Copyright ( C ) 2005-11 George Hazan + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or ( at your option ) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +Revision : $Revision: 13452 $ +Last change on : $Date: 2011-03-17 21:12:56 +0200 (Чт, 17 мар 2011) $ +Last change by : $Author: george.hazan $ + +*/ + +#include "jabber.h" + +BOOL CJabberProto::WsInit( void ) +{ + m_lastTicks = ::GetTickCount(); + + TCHAR name[128]; + mir_sntprintf( name, SIZEOF(name), TranslateT("%s connection"), m_tszUserName); + + NETLIBUSER nlu = {0}; + nlu.cbSize = sizeof( nlu ); + nlu.flags = NUF_OUTGOING | NUF_INCOMING | NUF_HTTPCONNS | NUF_TCHAR; // | NUF_HTTPGATEWAY; + nlu.ptszDescriptiveName = name; + nlu.szSettingsModule = m_szModuleName; + //nlu.szHttpGatewayHello = "http://http.proxy.icq.com/hello"; + //nlu.szHttpGatewayUserAgent = "Mozilla/4.08 [en] ( WinNT; U ;Nav )"; + //nlu.pfnHttpGatewayInit = JabberHttpGatewayInit; + //nlu.pfnHttpGatewayBegin = JabberHttpGatewayBegin; + //nlu.pfnHttpGatewayWrapSend = JabberHttpGatewayWrapSend; + //nlu.pfnHttpGatewayUnwrapRecv = JabberHttpGatewayUnwrapRecv; + m_hNetlibUser = ( HANDLE ) JCallService( MS_NETLIB_REGISTERUSER, 0, ( LPARAM )&nlu ); + + return m_hNetlibUser != NULL; +} + +void CJabberProto::WsUninit( void ) +{ + Netlib_CloseHandle( m_hNetlibUser ); + m_hNetlibUser = NULL; +} + +JABBER_SOCKET CJabberProto::WsConnect( char* host, WORD port ) +{ + NETLIBOPENCONNECTION nloc = { 0 }; + nloc.cbSize = sizeof( nloc ); + nloc.szHost = host; + nloc.wPort = port; + nloc.timeout = 6; + return ( HANDLE )JCallService( MS_NETLIB_OPENCONNECTION, ( WPARAM ) m_hNetlibUser, ( LPARAM )&nloc ); +} + +int CJabberProto::WsSend( JABBER_SOCKET hConn, char* data, int datalen, int flags ) +{ + m_lastTicks = ::GetTickCount(); + int len; + + if (( len = Netlib_Send( hConn, data, datalen, flags )) == SOCKET_ERROR || len != datalen ) { + Log( "Netlib_Send() failed, error=%d", WSAGetLastError()); + return SOCKET_ERROR; + } + return len; +} + +int CJabberProto::WsRecv( JABBER_SOCKET hConn, char* data, long datalen, int flags ) +{ + int ret; + + ret = Netlib_Recv( hConn, data, datalen, flags ); + if ( ret == SOCKET_ERROR ) { + Log( "Netlib_Recv() failed, error=%d", WSAGetLastError()); + return 0; + } + if ( ret == 0 ) { + Log( "Connection closed gracefully" ); + return 0; + } + return ret; +} -- cgit v1.2.3