| | 722 | //-----ProtoRequestPicture------------------------------------------------------ |
| | 723 | unsigned 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-------------------------------------------------------- |
| | 751 | void 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 | |
| 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 | { |
| 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: |
| | 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 | |