int icq_httpGatewayWrapSend(HANDLE hConn, PBYTE buf, int len, int flags, MIRANDASERVICE pfnNetlibSend) { PBYTE sendBuf = buf; int sendLen = len; int sendResult = 0; while (sendLen > 0) { // imitate polite behaviour of icq5.1 and split large packets icq_packet packet; WORD curLen; int curResult; if (sendLen > 512) curLen = 512; else curLen = (WORD)sendLen; // send wrapped data packet.wLen = curLen; write_httphdr(&packet, HTTP_PACKETTYPE_FLAP, GetGatewayIndex(hConn)); packBuffer(&packet, sendBuf, (WORD)curLen); NETLIBBUFFER nlb={ (char*)packet.pData, packet.wLen, flags }; curResult = pfnNetlibSend((WPARAM)hConn, (LPARAM)&nlb); SAFE_FREE((void**)&packet.pData); // sending failed, end loop if (curResult <= 0) return curResult; // calculare real number of data bytes sent if (curResult > 14) sendResult += curResult - 14; // move on sendLen -= curLen; sendBuf += curLen; } return sendResult; }
int icq_httpGatewayWalkTo(HANDLE hConn, NETLIBOPENCONNECTION* nloc) { // this is bad simplification - for avatars to work we need to handle // two "virtual connections" at the same time icq_packet packet; DWORD dwGatewaySeq = GetGatewayIndex(hConn); packet.wLen = 0; write_httphdr(&packet, HTTP_PACKETTYPE_CLOSE, dwGatewaySeq); Netlib_Send(hConn, (char*)packet.pData, packet.wLen, MSG_DUMPPROXY|MSG_NOHTTPGATEWAYWRAP); // we closed virtual connection, open new one dwGatewaySeq++; SetGatewayIndex(hConn, dwGatewaySeq); return icq_httpGatewayBegin(hConn, nloc); }
int icq_httpGatewayWrapSend( HANDLE hConn, PBYTE buf, int len, int flags, MIRANDASERVICE pfnNetlibSend ) { icq_packet packet; int sendResult; packet.wLen = len; write_httphdr( &packet, HTTP_PACKETTYPE_FLAP ); packString( &packet, buf, ( WORD )len ); sendResult = Netlib_Send( hConn, packet.pData, packet.wLen, flags ); mir_free( packet.pData ); if( sendResult <= 0 ) return sendResult; if( sendResult < 14 ) return 0; return sendResult - 14; }
int icq_httpGatewayBegin(HANDLE hConn, NETLIBOPENCONNECTION* nloc) { // open our "virual data connection" icq_packet packet; size_t serverNameLen; serverNameLen = strlennull(nloc->szHost); packet.wLen = (WORD)(serverNameLen + 4); write_httphdr(&packet, HTTP_PACKETTYPE_LOGIN, GetGatewayIndex(hConn)); packWord(&packet, (WORD)serverNameLen); packBuffer(&packet, (LPBYTE)nloc->szHost, (WORD)serverNameLen); packWord(&packet, nloc->wPort); INT_PTR res = Netlib_Send(hConn, (char*)packet.pData, packet.wLen, MSG_DUMPPROXY|MSG_NOHTTPGATEWAYWRAP); SAFE_FREE((void**)&packet.pData); return res != SOCKET_ERROR; }