Show
Ignore:
Timestamp:
05/05/08 16:31:53 (7 months ago)
Author:
emostar
Message:

Add the patch by Sergey Kononenko (Message-ID: <20080122012616.48112055@…>)
Included the following additions:

  • Add support for AIM (not all users yet)
  • Fix a few memory leaks
  • Rename SSBI to BART
  • Add constants for BART Types
  • Add support to qt4-gui
  • Use boost in a few cases
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/licq/src/icqd-srv.cpp

    r6180 r6181  
    2121#include <algorithm> 
    2222 
     23#include <boost/scoped_array.hpp> 
     24 
    2325// Localization 
    2426#include "gettext.h" 
     
    2830#include "licq_icqd.h" 
    2931#include "licq_translate.h" 
     32#include "licq_oscarservice.h" 
    3033#include "licq_packets.h" 
    3134#include "licq_socket.h" 
     
    717720} 
    718721 
     722//-----ProtoRequestPicture------------------------------------------------------ 
     723unsigned long CICQDaemon::ProtoRequestPicture(const char *_szId, unsigned long _nPPID) 
     724{ 
     725  unsigned long nRet = 0; 
     726 
     727  if (_nPPID == LICQ_PPID) 
     728  { 
     729    ICQUser *u = gUserManager.FetchUser(_szId, LICQ_PPID, LOCK_R); 
     730    if (u == NULL) return 0; 
     731 
     732    if (UseServerSideBuddyIcons() && strlen(u->BuddyIconHash()) > 0) 
     733    { 
     734      gUserManager.DropUser(u); 
     735      nRet = m_xBARTService->SendEvent(_szId, ICQ_SNACxBART_DOWNLOADxREQUEST, true); 
     736    } 
     737    else 
     738    { 
     739      bool bSendServer = (u->SocketDesc(ICQ_CHNxINFO) < 0); 
     740      gUserManager.DropUser(u); 
     741      nRet = icqRequestPicture(_szId, bSendServer); 
     742    } 
     743  } 
     744  else 
     745    PushProtoSignal(new CRequestPicture(_szId), _nPPID); 
     746   
     747  return nRet; 
     748} 
     749 
     750//-----icqRequestService-------------------------------------------------------- 
     751void CICQDaemon::icqRequestService(unsigned short nFam) 
     752{ 
     753  CPU_CommonFamily *p = new CPU_RequestService(nFam); 
     754  gLog.Info(tr("%sRequesting service socket for FAM 0x%02X (#%hu/#%d)...\n"), 
     755            L_SRVxSTR, nFam, p->Sequence(), p->SubSequence()); 
     756  SendEvent_Server(p); 
     757} 
     758 
    719759//-----icqSetStatus------------------------------------------------------------- 
    720760unsigned long CICQDaemon::ProtoSetStatus(unsigned long _nPPID, 
     
    17371777      case MAKESNAC(ICQ_SNACxFAM_LOCATION, ICQ_SNACxREQUESTxUSERxINFO): 
    17381778      case MAKESNAC(ICQ_SNACxFAM_LOCATION, ICQ_SNACxLOC_INFOxREQ): 
     1779      case MAKESNAC(ICQ_SNACxFAM_BART, ICQ_SNACxBART_DOWNLOADxREQUEST): 
    17391780        PushPluginEvent(e); 
    17401781        break; 
     
    18771918void CICQDaemon::postLogoff(int nSD, ICQEvent *cancelledEvent) 
    18781919{ 
     1920  if (m_xBARTService) 
     1921  { 
     1922    if (m_xBARTService->GetSocketDesc() != -1) 
     1923    { 
     1924      gSocketManager.CloseSocket(m_xBARTService->GetSocketDesc()); 
     1925      m_xBARTService->ResetSocket(); 
     1926      m_xBARTService->ChangeStatus(STATUS_UNINITIALIZED); 
     1927      m_xBARTService->ClearQueue(); 
     1928    } 
     1929  } 
    18791930  pthread_mutex_lock(&mutex_runningevents); 
    18801931  pthread_mutex_lock(&mutex_sendqueue_server); 
     
    20262077      return (-1); 
    20272078    } 
    2028     s->SetProxy(m_xProxy); 
    20292079  } 
    20302080  else if (m_xProxy != NULL) 
     
    20342084  } 
    20352085   
    2036   char ipbuf[32]; 
    2037  
    2038   if (m_xProxy == NULL) 
    2039   { 
    2040     gLog.Info(tr("%sResolving %s port %d...\n"), L_SRVxSTR, server, port); 
    2041     if (!s->SetRemoteAddr(server, port)) { 
    2042       char buf[128]; 
    2043       gLog.Warn(tr("%sUnable to resolve %s:\n%s%s.\n"), L_ERRORxSTR, 
    2044                 server, L_BLANKxSTR, s->ErrorStr(buf, 128)); 
    2045       delete s; 
    2046       return (-1); // no route to host (not connected) 
    2047     } 
    2048     gLog.Info(tr("%sICQ server found at %s:%d.\n"), L_SRVxSTR, 
    2049           s->RemoteIpStr(ipbuf), s->RemotePort()); 
    2050   } 
    2051   else 
    2052   { 
    2053     // It doesn't matter if it resolves or not, the proxy should do it then 
    2054     s->SetRemoteAddr(server, port); 
    2055   } 
    2056  
    2057   if (m_xProxy == NULL) 
    2058     gLog.Info(tr("%sOpening socket to server.\n"), L_SRVxSTR); 
    2059   else 
    2060     gLog.Info("%sOpening socket to server via proxy.\n", L_SRVxSTR); 
    2061   if (!s->OpenConnection()) 
    2062   { 
    2063     char buf[128]; 
    2064     gLog.Warn(tr("%sUnable to connect to %s:%d:\n%s%s.\n"), L_ERRORxSTR, 
    2065               s->RemoteIpStr(ipbuf), s->RemotePort(), L_BLANKxSTR, 
    2066               s->ErrorStr(buf, 128)); 
     2086  if (!s->ConnectTo(server, port, m_xProxy)) 
     2087  { 
    20672088    delete s; 
    20682089    return -1; 
     
    22222243  // each case to do the same thing. However, the individual case's may depend on the tlv 
    22232244  // coming to them, so leave this commented out for now and do some testing 
    2224   /* 
    22252245  if (snacFlags & 0x8000) 
    22262246  { 
    22272247    unsigned short bytes = packet.UnpackUnsignedShortBE(); 
    2228     unsigned short tlvCount = packet.UnpackUnsignedShortBE(); 
    2229     if (!packet.readTLV(tlvCount, bytes)) 
     2248    if (!packet.readTLV(-1, bytes)) 
    22302249    { 
    22312250      gLog.Error(tr("%sError parsing SNAC header\n"), L_SRVxSTR); 
     
    22332252    } 
    22342253  } 
    2235   */ 
    22362254 
    22372255  switch (nSubtype) 
    22382256  { 
    2239   case ICQ_SNACxSUB_READYxSERVER: 
     2257    case ICQ_SNACxSUB_READYxSERVER: 
    22402258    { 
    22412259      CSrvPacketTcp* p; 
     
    22582276    } 
    22592277 
    2260   case ICQ_SNACxSRV_ACKxIMxICQ: 
     2278    case ICQ_SNACxSUB_REDIRECT: 
     2279    { 
     2280      unsigned short nFam = 0; 
     2281 
     2282      if (!packet.readTLV()) 
     2283      { 
     2284        gLog.Warn(tr("%sError during parsing service redirect packet!\n"), L_WARNxSTR); 
     2285        break; 
     2286      } 
     2287      if (packet.getTLVLen(0x000D) == 2) 
     2288        nFam = packet.UnpackUnsignedShortTLV(0x000D); 
     2289 
     2290      gLog.Info(tr("%sRedirect for service 0x%02X received.\n"), L_SRVxSTR, nFam); 
     2291 
     2292      char *szServer = packet.UnpackStringTLV(0x0005); 
     2293      char *szCookie = packet.UnpackStringTLV(0x0006); 
     2294      unsigned short nCookieLen = packet.getTLVLen(0x0006); 
     2295      if (!szServer || !szCookie) 
     2296      { 
     2297        gLog.Warn(tr("%sInvalid servername (%s) or cookie (%s) in service redirect packet!\n"), 
     2298                  L_WARNxSTR, szServer ? szServer : "(null)", szCookie ? szCookie : "(null)"); 
     2299        if (szServer) delete [] szServer; 
     2300        if (szCookie) delete [] szCookie; 
     2301        break; 
     2302      } 
     2303 
     2304      char *szPort = strchr(szServer, ':'); 
     2305      unsigned short nPort; 
     2306      if (szPort) 
     2307      { 
     2308        *szPort++ = '\0'; 
     2309        nPort = atoi(szPort); 
     2310      } 
     2311      else 
     2312      { 
     2313        nPort = m_nICQServerPort; 
     2314      } 
     2315 
     2316      switch (nFam) 
     2317      { 
     2318        case ICQ_SNACxFAM_BART: 
     2319          if (m_xBARTService) 
     2320          { 
     2321            m_xBARTService->SetConnectCredential(szServer, nPort, szCookie, nCookieLen); 
     2322            m_xBARTService->ChangeStatus(STATUS_SERVICE_REQ_ACKED); 
     2323            break; 
     2324          } 
     2325          else 
     2326          { 
     2327            gLog.Warn(tr("%sService redirect packet for unallocated BART service.\n"), 
     2328                      L_WARNxSTR); 
     2329            break; 
     2330          } 
     2331 
     2332        default: 
     2333          gLog.Warn(tr("%sService redirect packet for unhandled service 0x%02X.\n"), 
     2334                    L_WARNxSTR, nFam); 
     2335      } 
     2336 
     2337      delete [] szServer; 
     2338      delete [] szCookie; 
     2339      break; 
     2340    } 
     2341 
     2342    case ICQ_SNACxSRV_ACKxIMxICQ: 
    22612343    { 
    22622344      // ICQOwner *o = gUserManager.FetchOwner(LICQ_PPID, LOCK_R); 
     
    22972379      break; 
    22982380    } 
    2299   case ICQ_SNACxSUB_RATE_INFO: 
    2300   { 
     2381 
     2382    case ICQ_SNACxSUB_RATE_INFO: 
     2383    { 
    23012384      gLog.Info(tr("%sServer sent us rate information.\n"), L_SRVxSTR); 
    23022385      CSrvPacketTcp *p = new CPU_RateAck(); 
     
    23202403  case ICQ_SNACxRCV_NAMExINFO: 
    23212404  { 
    2322     if (snacFlags & 0x8000) 
    2323     { 
    2324       unsigned short bytes = packet.UnpackUnsignedShortBE(); 
    2325       if (!packet.readTLV(-1, bytes)) 
    2326       { 
    2327         gLog.Error(tr("%sError parsing SNAC header\n"), L_SRVxSTR); 
    2328         return; 
    2329       } 
    2330     } 
    2331  
    23322405    unsigned short evil, tlvBlocks; 
    23332406    unsigned long nUin, realIP; 
     
    28692942    } 
    28702943 
     2944    if (packet.hasTLV(0x001d))  // Server-stored buddy icon information 
     2945    { 
     2946      CBuffer BART_info = packet.UnpackTLV(0x001d); 
     2947      unsigned short IconType = BART_info.UnpackUnsignedShortBE(); 
     2948      char HashType = BART_info.UnpackChar(); 
     2949      char HashLength = BART_info.UnpackChar(); 
     2950       
     2951      switch (IconType) 
     2952      { 
     2953        case BART_TYPExBUDDY_ICON_SMALL: 
     2954        case BART_TYPExBUDDY_ICON: 
     2955        { 
     2956          if (HashType == 1 && HashLength > 0 && HashLength <= 16) 
     2957          { 
     2958            boost::scoped_array<char> Hash(new char[HashLength]); 
     2959            boost::scoped_array<char> HashHex(new char[HashLength*2 + 1]); 
     2960             
     2961            BART_info.UnpackBinBlock(Hash.get(), HashLength); 
     2962            u->SetBuddyIconHash(PrintHex(HashHex.get(), Hash.get(), HashLength)); 
     2963            u->SetBuddyIconType(IconType); 
     2964            u->SetBuddyIconHashType(HashType); 
     2965            u->SavePictureInfo(); 
     2966          } 
     2967          break; 
     2968        } 
     2969 
     2970        default:    // Unsupported types of BART 
     2971          gLog.Warn(tr("%sUnsupported type 0x%02X of buddy icon for %s.\n"), 
     2972                    L_WARNxSTR, IconType, u->GetAlias()); 
     2973          break; 
     2974      } 
     2975    } 
     2976     
    28712977    // maybe use this for auto update info later 
    28722978    u->SetClientTimestamp(nInfoTimestamp);