コード例 #1
0
ファイル: lbs.c プロジェクト: AndroidForWave/bada-modemril
void lbs_send_packet(uint32_t type, uint32_t size, uint32_t subType, void* buf)
{	
	struct modem_io pkt;
	struct lbsPacketHeader* hdr;
	void* sendBuf;
	sendBuf = (void*) lbsSendBuf;
	hdr = (struct lbsPacketHeader*) &lbsSendBuf;
	
	/* BIG WTF at the lengths below, shitload of uninitialized, redundant data 
	 * OHAI retarded Samsung devs */
	if(type <= 6 || (type >= 21 && type <= 30)) //common 1
		pkt.datasize = 0x100C;
	else if((type >= 7 && type <= 12) || 
			(type >= 31 && type <= 35)) //supl 2
		pkt.datasize = 0x81C;
	else if((type >= 13 && type <= 14) || 
			(type >= 16 && type <= 18) || 
			(type >= 36 && type <= 39)) //xtra 3
		pkt.datasize = 0x3C;
	else if(type == 15) //large_xtra 5
	{
		sendBuf = malloc(0xA014);
		pkt.datasize = 0xA014;
	}
	else if(type == 19 || type == 20) //baseband 5
		pkt.datasize = 0xDC;
	else
	{
		DEBUG_E("Unknown LBS packet type, abandoning...");
		return;
	}
	if(size > pkt.datasize - sizeof(struct lbsPacketHeader))
	{
		DEBUG_E("Too big LBS packet, type %d, len %d", type, size);
		return;
	}
	
	hdr->type = type;
	hdr->size = size;
	hdr->subType = subType;
	memcpy((char*)(sendBuf) + sizeof(struct lbsPacketHeader), buf, size);
	
	pkt.magic = 0xCAFECAFE;
	pkt.cmd = FIFO_PKT_LBS;
	pkt.data = sendBuf;
	
	ipc_send(&pkt);
	if(type == 15)
		free(sendBuf);
}
コード例 #2
0
ファイル: net_test.cpp プロジェクト: zheng39562/common
	void doPerformance(const string &arg){
		if(arg == ARG_CLIENT){
			bool bRet = net_connect(g_IP, TEST_CONNECT_PORT);
			if(!bRet){ DEBUG_E("client 连接失败。"); }

			PackerPtr pPacker(new Packer(NULL));
			pPacker->setBuffer(g_TestContext_1.c_str(), g_TestContext_1.size());

			long times(PERFROMANCE_TIMES);
			while(times--){
				net_sendAll_C(pPacker);
				usleep(1);
			}

			sleep(100);
		}
		if(arg == ARG_SERVER){
			TimeCounter timeCount;

			bool bRet = net_listen(g_IP, TEST_LISTEN_PORT);
			if(!bRet){ DEBUG_E("server 监听失败。"); }

			PackerPtr pPacker;

			long times(PERFROMANCE_TIMES);

			bool bNotFull(true);

			timeCount.start();
			while(bRet && times>0){
				if(net_recv_S(pPacker)){
					if(g_TestContext_1 == string((char*)pPacker->getBuffer(), pPacker->getBufferSize())){
						cout << --times << endl; 
					}
					else{
						bNotFull = false;
						DEBUG_E("接收数据出错。" << string((char*)pPacker->getBuffer(), pPacker->getBufferSize()));
						break;
					}
					if(!bNotFull){
						cout << "有数据丢失" << endl;
					}
				}
			}
			timeCount.stop();

			cout << "发送[" << PERFROMANCE_TIMES << "] use time [" << timeCount.getSecTimeD() << "]s" << endl;
		}
	}
コード例 #3
0
ファイル: ApiScheme.cpp プロジェクト: acc11311/Telegram
UserStatus *UserStatus::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
    UserStatus *result = nullptr;
    switch (constructor) {
        case 0x8c703f:
            result = new TL_userStatusOffline();
            break;
        case 0x7bf09fc:
            result = new TL_userStatusLastWeek();
            break;
        case 0x9d05049:
            result = new TL_userStatusEmpty();
            break;
        case 0x77ebc742:
            result = new TL_userStatusLastMonth();
            break;
        case 0xedb93949:
            result = new TL_userStatusOnline();
            break;
        case 0xe26f42f1:
            result = new TL_userStatusRecently();
            break;
        default:
            error = true;
            DEBUG_E("can't parse magic %x in UserStatus", constructor);
            return nullptr;
    }
    result->readParams(stream, instanceNum, error);
    return result;
}
コード例 #4
0
ファイル: CameraPose.cpp プロジェクト: josetascon/mop
Eigen::MatrixXd linearCamera( Eigen::MatrixXd &xpt, Eigen::MatrixXd &Xpt)
{
    int n = xpt.cols();
    if (n < 6)
    {
        DEBUG_E( ("Camera Matrix can't be estimated in linearCamera(). Minimun required points are 6") ); 
        exit(-1);
    }
    
    Eigen::MatrixXd A = Eigen::MatrixXd::Zero(2*n,12);
    
    for (register int k = 0; k < n; ++k)
    {
        Eigen::RowVectorXd St(4);
        St << Xpt(0,k), Xpt(1,k), Xpt(2,k), Xpt(3,k);
        A.row(2*k) << Eigen::RowVectorXd::Zero(4), -xpt(2,k)*St, xpt(1,k)*St;
        A.row(2*k+1) << xpt(2,k)*St, Eigen::RowVectorXd::Zero(4), -xpt(0,k)*St;
    }
//     std::cout << "A:\n " << A <<'\n';
    Eigen::JacobiSVD<Eigen::MatrixXd> svd(A, Eigen::ComputeFullV | Eigen::ComputeThinU);
    Eigen::MatrixXd VV = svd.matrixV();
    Eigen::MatrixXd P(3,4);
    P << VV(0,11), VV(1,11), VV(2,11), VV(3,11), 
        VV(4,11), VV(5,11), VV(6,11), VV(7,11), 
        VV(8,11), VV(9,11), VV(10,11), VV(11,11);
    P = P/P(2,3);
    return P;
}
コード例 #5
0
ファイル: ApiScheme.cpp プロジェクト: acc11311/Telegram
TL_cdnPublicKey *TL_cdnPublicKey::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
    if (TL_cdnPublicKey::constructor != constructor) {
        error = true;
        DEBUG_E("can't parse magic %x in TL_cdnPublicKey", constructor);
        return nullptr;
    }
    TL_cdnPublicKey *result = new TL_cdnPublicKey();
    result->readParams(stream, instanceNum, error);
    return result;
}
コード例 #6
0
ファイル: ApiScheme.cpp プロジェクト: acc11311/Telegram
TL_auth_exportedAuthorization *TL_auth_exportedAuthorization::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
    if (TL_auth_exportedAuthorization::constructor != constructor) {
        error = true;
        DEBUG_E("can't parse magic %x in TL_auth_exportedAuthorization", constructor);
        return nullptr;
    }
    TL_auth_exportedAuthorization *result = new TL_auth_exportedAuthorization();
    result->readParams(stream, instanceNum, error);
    return result;
}
コード例 #7
0
void ConnectionSocket::adjustWriteOp() {
    eventMask.events = EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLET;
    if (proxyAuthState == 0 && (outgoingByteStream->hasData() || !onConnectedSent) || proxyAuthState == 1 || proxyAuthState == 3 || proxyAuthState == 5) {
        eventMask.events |= EPOLLOUT;
    }
    eventMask.data.ptr = eventObject;
    if (epoll_ctl(ConnectionsManager::getInstance().epolFd, EPOLL_CTL_MOD, socketFd, &eventMask) != 0) {
        DEBUG_E("connection(%p) epoll_ctl, modify socket failed", this);
        closeSocket(1);
    }
}
コード例 #8
0
bool ConnectionSocket::checkSocketError() {
    if (socketFd < 0) {
        return true;
    }
    int ret;
    int code;
    socklen_t len = sizeof(int);
    ret = getsockopt(socketFd, SOL_SOCKET, SO_ERROR, &code, &len);
    if (ret != 0 || code != 0) {
        DEBUG_E("socket error 0x%x code 0x%x", ret, code);
    }
    return (ret || code) != 0;
}
コード例 #9
0
ファイル: Common.cpp プロジェクト: josetascon/mop
bool verifyFileExtension( const char *file_name, std::string& extension, bool stop_execution )
{
    std::string base = baseFileName(std::string(file_name));
    std::string ext = extensionFileName(base);
    if( ext.compare(extension) == 0 ) return true;
    
    if (stop_execution)
    {
        DEBUG_E( ("Bad file extension. Check your file name") ); 
        exit(-1);
    }
    return false;
}
コード例 #10
0
ファイル: net_test.cpp プロジェクト: zheng39562/common
	void doLink(const string &arg){
		if(arg == ARG_CLIENT){
			bool bRet = net_connect(g_IP, TEST_CONNECT_PORT);
			if(!bRet){ DEBUG_E("client 连接失败。"); }

			DEBUG_D("链接成功,准备发送数据。");
			PackerPtr pPacker(new Packer(NULL));
			pPacker->setBuffer(g_TestContext_1.c_str(), g_TestContext_1.size());

			DEBUG_D("发送数据:" << g_TestContext_1);
			net_sendAll_C(pPacker);

			sleep(10);
		}
		if(arg == ARG_SERVER){
			bool bRet = net_listen(g_IP, TEST_LISTEN_PORT);
			if(!bRet){ DEBUG_E("server 监听失败。"); }

			while(bRet){
				DEBUG_D("开始监听,等待链接和数据。");
				PackerPtr pPacker;
				if(net_recv_S(pPacker)){
					DEBUG_D("成功接收数据。");
					string ret((char*)pPacker->getBuffer(), pPacker->getBufferSize());
					if(g_TestContext_1 == ret){
						DEBUG_D("接收到消息" << ret );
						break;
					}
					else{
						DEBUG_D("接收到的消息和发送消息不一致. " << g_TestContext_1 << " != " << ret);
						break;
					}
				}

				usleep(1000);
			}
		}
	}
コード例 #11
0
ファイル: PoseICP.hpp プロジェクト: josetascon/mop
    void simpleCalibration( double focal = 520.0 )
    {
        if ( !load_images )
        {
	  DEBUG_E( ("Not loaded Images. Use properly the constructor or set parameters manually") ); 
	  exit(-1);
        }
        double wimg = image1->size().width - 1.0;
        double himg = image1->size().height - 1.0;
        Eigen::Matrix3d K;
        K << focal, 0.0, wimg/2, 0.0, focal, himg/2, 0.0, 0.0, 1.0;		// Camera Matrix (intrinsics)
        
        setCalibration( K );
    }
コード例 #12
0
void ConnectionSocket::closeSocket(int reason) {
    lastEventTime = ConnectionsManager::getInstance().getCurrentTimeMonotonicMillis();
    ConnectionsManager::getInstance().detachConnection(this);
    if (socketFd >= 0) {
        epoll_ctl(ConnectionsManager::getInstance().epolFd, EPOLL_CTL_DEL, socketFd, NULL);
        if (close(socketFd) != 0) {
            DEBUG_E("connection(%p) unable to close socket", this);
        }
        socketFd = -1;
    }
    proxyAuthState = 0;
    onConnectedSent = false;
    outgoingByteStream->clean();
    onDisconnected(reason);
}
コード例 #13
0
ファイル: ApiScheme.cpp プロジェクト: acc11311/Telegram
void TL_cdnConfig::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
    int magic = stream->readInt32(&error);
    if (magic != 0x1cb5c415) {
        error = true;
        DEBUG_E("wrong Vector magic, got %x", magic);
        return;
    }
    int count = stream->readInt32(&error);
    for (int32_t a = 0; a < count; a++) {
        TL_cdnPublicKey *object = TL_cdnPublicKey::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error);
        if (object == nullptr) {
            return;
        }
        public_keys.push_back(std::unique_ptr<TL_cdnPublicKey>(object));
    }
}
コード例 #14
0
ファイル: ApiScheme.cpp プロジェクト: acc11311/Telegram
auth_SentCode *auth_SentCode::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
    auth_SentCode *result = nullptr;
    switch (constructor) {
        case 0xe325edcf:
            result = new TL_auth_sentAppCode();
            break;
        case 0xefed51d9:
            result = new TL_auth_sentCode();
            break;
        default:
            error = true;
            DEBUG_E("can't parse magic %x in auth_SentCode", constructor);
            return nullptr;
    }
    result->readParams(stream, instanceNum, error);
    return result;
}
コード例 #15
0
ファイル: ApiScheme.cpp プロジェクト: acc11311/Telegram
UserProfilePhoto *UserProfilePhoto::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
    UserProfilePhoto *result = nullptr;
    switch (constructor) {
        case 0x4f11bae1:
            result = new TL_userProfilePhotoEmpty();
            break;
        case 0xd559d8c8:
            result = new TL_userProfilePhoto();
            break;
        default:
            error = true;
            DEBUG_E("can't parse magic %x in UserProfilePhoto", constructor);
            return nullptr;
    }
    result->readParams(stream, instanceNum, error);
    return result;
}
コード例 #16
0
ファイル: ApiScheme.cpp プロジェクト: acc11311/Telegram
User *User::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
    User *result = nullptr;
    switch (constructor) {
        case 0x200250ba:
            result = new TL_userEmpty();
            break;
        case 0x2e13f4c3:
            result = new TL_user();
            break;
        default:
            error = true;
            DEBUG_E("can't parse magic %x in User", constructor);
            return nullptr;
    }
    result->readParams(stream, instanceNum, error);
    return result;
}
コード例 #17
0
ファイル: ApiScheme.cpp プロジェクト: acc11311/Telegram
Bool *Bool::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
    Bool *result = nullptr;
    switch (constructor) {
        case 0x997275b5:
            result = new TL_boolTrue();
            break;
        case 0xbc799737:
            result = new TL_boolFalse();
            break;
        default:
            error = true;
            DEBUG_E("can't parse magic %x in Bool", constructor);
            return nullptr;
    }
    result->readParams(stream, instanceNum, error);
    return result;
}
コード例 #18
0
ファイル: misc.c プロジェクト: KB-JetDroid/bada-modemril
void ipc_parse_system(struct ipc_client *client, struct modem_io *ipc_frame)
{
	DEBUG_I("received SYSTEM packet with AMSS version, notifying RIL that AMSS has initialized");
	uint32_t desc_size;
	int suffix_size;
	desc_size = strlen((const char*)ipc_frame->data);
	if(desc_size > 32 || desc_size > ipc_frame->datasize)
		DEBUG_E("too big desc_size: %d", desc_size);
	else
		memcpy(cached_sw_version, ipc_frame->data, desc_size);
	cached_sw_version[desc_size] = 0x00;
	suffix_size = ipc_frame->datasize - desc_size - 1;
	if(suffix_size > 0) {
		DEBUG_I("dumping rest of data from IPC_SYSTEM packet");
		ipc_hex_dump(client, ipc_frame->data+desc_size+1, suffix_size);
	}
	ipc_invoke_ril_cb(CP_SYSTEM_START, ipc_frame->data);
}
コード例 #19
0
ファイル: ApiScheme.cpp プロジェクト: acc11311/Telegram
FileLocation *FileLocation::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
    FileLocation *result = nullptr;
    switch (constructor) {
        case 0x53d69076:
            result = new TL_fileLocation();
            break;
        case 0x7c596b46:
            result = new TL_fileLocationUnavailable();
            break;
        case 0x55555554:
            result = new TL_fileEncryptedLocation();
            break;
        default:
            error = true;
            DEBUG_E("can't parse magic %x in FileLocation", constructor);
            return nullptr;
    }
    result->readParams(stream, instanceNum, error);
    return result;
}
コード例 #20
0
ファイル: pdds3c2440_ser.cpp プロジェクト: jiajw0426/vkdriver
CReg2440Uart::CReg2440Uart(PULONG pRegAddr,DWORD childSerialIndex)
:   m_pReg(pRegAddr),m_ChildSerialIndex(childSerialIndex)
{
	 DEBUG_E(TEXT("CReg2440Uart"),TEXT("ICReg2440Uartnit")) 
	
    m_fIsBackedUp = FALSE;
    PROCESSOR_INFO procInfo;
    DWORD dwBytesReturned;
    if (!KernelIoControl(IOCTL_PROCESSOR_INFORMATION, NULL, 0, &procInfo, sizeof(PROCESSOR_INFO), &dwBytesReturned))
    {
        m_s3c2440_pclk = S3C2440A_PCLK;
        RETAILMSG(TRUE, (TEXT("WARNING: CReg2440Uart::CReg2440Uart failed to obtain processor frequency - using default value (%d).\r\n"), m_s3c2440_pclk)); 
    }
    else
    {
        m_s3c2440_pclk = procInfo.dwClockSpeed/PCLKDIV;
        RETAILMSG(TRUE, (TEXT("INFO: CReg2440Uart::CReg2440Uart using processor frequency reported by the OAL (%d).\r\n"), m_s3c2440_pclk)); 
    }
	 DEBUG_L(TEXT("CReg2440Uart"),TEXT("CReg2440Uart")) 

}
コード例 #21
0
void ConnectionSocket::onEvent(uint32_t events) {
    if (events & EPOLLIN) {
        if (checkSocketError()) {
            closeSocket(1);
            return;
        } else {
            ssize_t readCount;
            NativeByteBuffer *buffer = ConnectionsManager::getInstance().networkBuffer;
            while (true) {
                buffer->rewind();
                readCount = recv(socketFd, buffer->bytes(), READ_BUFFER_SIZE, 0);
                if (readCount < 0) {
                    closeSocket(1);
                    DEBUG_E("connection(%p) recv failed", this);
                    return;
                }
                if (readCount > 0) {
                    buffer->limit((uint32_t) readCount);
                    lastEventTime = ConnectionsManager::getInstance().getCurrentTimeMonotonicMillis();
                    if (proxyAuthState == 2) {
                        if (readCount == 2) {
                            uint8_t auth_method = buffer->bytes()[1];
                            if (auth_method == 0xff) {
                                closeSocket(1);
                                DEBUG_E("connection(%p) unsupported proxy auth method", this);
                            } else if (auth_method == 0x02) {
                                DEBUG_D("connection(%p) proxy auth required", this);
                                proxyAuthState = 3;
                            } else if (auth_method == 0x00) {
                                proxyAuthState = 5;
                            }
                            adjustWriteOp();
                        } else {
                            closeSocket(1);
                            DEBUG_E("connection(%p) invalid proxy response on state 2", this);
                        }
                    } else if (proxyAuthState == 4) {
                        if (readCount == 2) {
                            uint8_t auth_method = buffer->bytes()[1];
                            if (auth_method != 0x00) {
                                closeSocket(1);
                                DEBUG_E("connection(%p) auth invalid", this);
                            } else {
                                proxyAuthState = 5;
                            }
                            adjustWriteOp();
                        } else {
                            closeSocket(1);
                            DEBUG_E("connection(%p) invalid proxy response on state 4", this);
                        }
                    } else if (proxyAuthState == 6) {
                        if (readCount > 2) {
                            uint8_t status = buffer->bytes()[1];
                            if (status == 0x00) {
                                DEBUG_D("connection(%p) connected via proxy", this);
                                proxyAuthState = 0;
                                adjustWriteOp();
                            } else {
                                closeSocket(1);
                                DEBUG_E("connection(%p) invalid proxy status on state 6, 0x%x", this, status);
                            }
                        } else {
                            closeSocket(1);
                            DEBUG_E("connection(%p) invalid proxy response on state 6", this);
                        }
                    } else if (proxyAuthState == 0) {
                        if (ConnectionsManager::getInstance().delegate != nullptr) {
                            ConnectionsManager::getInstance().delegate->onBytesReceived(readCount, currentNetworkType);
                        }
                        onReceivedData(buffer);
                    }
                }
                if (readCount != READ_BUFFER_SIZE) {
                    break;
                }
            }
        }
    }
    if (events & EPOLLOUT) {
        if (checkSocketError() != 0) {
            closeSocket(1);
            return;
        } else {
            if (proxyAuthState != 0) {
                static uint8_t buffer[1024];
                if (proxyAuthState == 1) {
                    lastEventTime = ConnectionsManager::getInstance().getCurrentTimeMonotonicMillis();
                    proxyAuthState = 2;
                    buffer[0] = 0x05;
                    buffer[1] = 0x02;
                    buffer[2] = 0x00;
                    buffer[3] = 0x02;
                    if (send(socketFd, buffer, 4, 0) < 0) {
                        DEBUG_E("connection(%p) send failed", this);
                        closeSocket(1);
                        return;
                    }
                    adjustWriteOp();
                } else if (proxyAuthState == 3) {
                    buffer[0] = 0x01;
                    uint8_t len1 = (uint8_t) ConnectionsManager::getInstance().proxyUser.length();
                    uint8_t len2 = (uint8_t) ConnectionsManager::getInstance().proxyPassword.length();
                    buffer[1] = len1;
                    memcpy(&buffer[2], ConnectionsManager::getInstance().proxyUser.c_str(), len1);
                    buffer[2 + len1] = len2;
                    memcpy(&buffer[3 + len1], ConnectionsManager::getInstance().proxyPassword.c_str(), len2);
                    proxyAuthState = 4;
                    if (send(socketFd, buffer, 3 + len1 + len2, 0) < 0) {
                        DEBUG_E("connection(%p) send failed", this);
                        closeSocket(1);
                        return;
                    }
                    adjustWriteOp();
                } else if (proxyAuthState == 5) {
                    buffer[0] = 0x05;
                    buffer[1] = 0x01;
                    buffer[2] = 0x00;
                    buffer[3] = (uint8_t) (isIpv6 ? 0x04 : 0x01);
                    uint16_t networkPort = ntohs(currentPort);
                    inet_pton(isIpv6 ? AF_INET6 : AF_INET, currentAddress.c_str(), &buffer[4]);
                    memcpy(&buffer[4 + (isIpv6 ? 16 : 4)], &networkPort, sizeof(uint16_t));
                    proxyAuthState = 6;
                    if (send(socketFd, buffer, 4 + (isIpv6 ? 16 : 4) + 2, 0) < 0) {
                        DEBUG_E("connection(%p) send failed", this);
                        closeSocket(1);
                        return;
                    }
                    adjustWriteOp();
                }
            } else {
                if (!onConnectedSent) {
                    lastEventTime = ConnectionsManager::getInstance().getCurrentTimeMonotonicMillis();
                    onConnected();
                    onConnectedSent = true;
                }
                NativeByteBuffer *buffer = ConnectionsManager::getInstance().networkBuffer;
                buffer->clear();
                outgoingByteStream->get(buffer);
                buffer->flip();

                uint32_t remaining = buffer->remaining();
                if (remaining) {
                    ssize_t sentLength;
                    if ((sentLength = send(socketFd, buffer->bytes(), remaining, 0)) < 0) {
                        DEBUG_E("connection(%p) send failed", this);
                        closeSocket(1);
                        return;
                    } else {
                        if (ConnectionsManager::getInstance().delegate != nullptr) {
                            ConnectionsManager::getInstance().delegate->onBytesSent(sentLength, currentNetworkType);
                        }
                        outgoingByteStream->discard((uint32_t) sentLength);
                        adjustWriteOp();
                    }
                }
            }
        }
    }
    if ((events & EPOLLRDHUP) || (events & EPOLLHUP)) {
        DEBUG_E("socket event has EPOLLHUP");
        closeSocket(1);
        return;
    }
    if (events & EPOLLERR) {
        DEBUG_E("connection(%p) epoll error", this);
        return;
    }
}
コード例 #22
0
ファイル: ApiScheme.cpp プロジェクト: acc11311/Telegram
void TL_config::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
    flags = stream->readInt32(&error);
    date = stream->readInt32(&error);
    expires = stream->readInt32(&error);
    test_mode = stream->readBool(&error);
    this_dc = stream->readInt32(&error);
    uint32_t magic = stream->readUint32(&error);
    if (magic != 0x1cb5c415) {
        error = true;
        DEBUG_E("wrong Vector magic, got %x", magic);
        return;
    }
    int32_t count = stream->readInt32(&error);
    for (int32_t a = 0; a < count; a++) {
        TL_dcOption *object = TL_dcOption::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error);
        if (object == nullptr) {
            return;
        }
        dc_options.push_back(std::unique_ptr<TL_dcOption>(object));
    }
    dc_txt_domain_name = stream->readString(&error);
    chat_size_max = stream->readInt32(&error);
    megagroup_size_max = stream->readInt32(&error);
    forwarded_count_max = stream->readInt32(&error);
    online_update_period_ms = stream->readInt32(&error);
    offline_blur_timeout_ms = stream->readInt32(&error);
    offline_idle_timeout_ms = stream->readInt32(&error);
    online_cloud_timeout_ms = stream->readInt32(&error);
    notify_cloud_delay_ms = stream->readInt32(&error);
    notify_default_delay_ms = stream->readInt32(&error);
    push_chat_period_ms = stream->readInt32(&error);
    push_chat_limit = stream->readInt32(&error);
    saved_gifs_limit = stream->readInt32(&error);
    edit_time_limit = stream->readInt32(&error);
    revoke_time_limit = stream->readInt32(&error);
    revoke_pm_time_limit = stream->readInt32(&error);
    rating_e_decay = stream->readInt32(&error);
    stickers_recent_limit = stream->readInt32(&error);
    stickers_faved_limit = stream->readInt32(&error);
    channels_read_media_period = stream->readInt32(&error);
    if ((flags & 1) != 0) {
        tmp_sessions = stream->readInt32(&error);
    }
    pinned_dialogs_count_max = stream->readInt32(&error);
    call_receive_timeout_ms = stream->readInt32(&error);
    call_ring_timeout_ms = stream->readInt32(&error);
    call_connect_timeout_ms = stream->readInt32(&error);
    call_packet_timeout_ms = stream->readInt32(&error);
    me_url_prefix = stream->readString(&error);
    if ((flags & 128) != 0) {
        autoupdate_url_prefix = stream->readString(&error);
    }
    if ((flags & 512) != 0) {
        gif_search_username = stream->readString(&error);
    }
    if ((flags & 1024) != 0) {
        venue_search_username = stream->readString(&error);
    }
    if ((flags & 2048) != 0) {
        img_search_username = stream->readString(&error);
    }
    if ((flags & 4096) != 0) {
        static_maps_provider = stream->readString(&error);
    }
    caption_length_max = stream->readInt32(&error);
    message_length_max = stream->readInt32(&error);
    webfile_dc_id = stream->readInt32(&error);
    if ((flags & 4) != 0) {
        suggested_lang_code = stream->readString(&error);
    }
    if ((flags & 4) != 0) {
        lang_pack_version = stream->readInt32(&error);
    }
}
コード例 #23
0
void ConnectionSocket::openConnection(std::string address, uint16_t port, bool ipv6, int32_t networkType) {
    currentNetworkType = networkType;
    isIpv6 = ipv6;
    currentAddress = address;
    currentPort = port;
    int epolFd = ConnectionsManager::getInstance().epolFd;
    ConnectionsManager::getInstance().attachConnection(this);

    memset(&socketAddress, 0, sizeof(sockaddr_in));
    memset(&socketAddress6, 0, sizeof(sockaddr_in6));

    if (!ConnectionsManager::getInstance().proxyAddress.empty()) {
        std::string &proxyAddress = ConnectionsManager::getInstance().proxyAddress;
        if ((socketFd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
            DEBUG_E("connection(%p) can't create proxy socket", this);
            closeSocket(1);
            return;
        }
        proxyAuthState = 1;
        socketAddress.sin_family = AF_INET;
        socketAddress.sin_port = htons(ConnectionsManager::getInstance().proxyPort);
        bool continueCheckAddress;
        if (inet_pton(AF_INET, proxyAddress.c_str(), &socketAddress.sin_addr.s_addr) != 1) {
            continueCheckAddress = true;
            DEBUG_D("connection(%p) not ipv4 address %s", this, proxyAddress.c_str());
        } else {
            continueCheckAddress = false;
        }
        if (continueCheckAddress) {
            if (inet_pton(AF_INET6, proxyAddress.c_str(), &socketAddress.sin_addr.s_addr) != 1) {
                continueCheckAddress = true;
                DEBUG_D("connection(%p) not ipv6 address %s", this, proxyAddress.c_str());
            } else {
                continueCheckAddress = false;
            }
            if (continueCheckAddress) {
                struct hostent *he;
                if ((he = gethostbyname(proxyAddress.c_str())) == nullptr) {
                    DEBUG_E("connection(%p) can't resolve host %s address", this, proxyAddress.c_str());
                    closeSocket(1);
                    return;
                }
                struct in_addr **addr_list = (struct in_addr **) he->h_addr_list;
                if (addr_list[0] != nullptr) {
                    socketAddress.sin_addr.s_addr = addr_list[0]->s_addr;
                    DEBUG_D("connection(%p) resolved host %s address %x", this, proxyAddress.c_str(), addr_list[0]->s_addr);
                } else {
                    DEBUG_E("connection(%p) can't resolve host %s address", this, proxyAddress.c_str());
                    closeSocket(1);
                    return;
                }
            }
        }
    } else {
        proxyAuthState = 0;
        if ((socketFd = socket(ipv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0)) < 0) {
            DEBUG_E("connection(%p) can't create socket", this);
            closeSocket(1);
            return;
        }
        if (ipv6) {
            socketAddress6.sin6_family = AF_INET6;
            socketAddress6.sin6_port = htons(port);
            if (inet_pton(AF_INET6, address.c_str(), &socketAddress6.sin6_addr.s6_addr) != 1) {
                DEBUG_E("connection(%p) bad ipv6 %s", this, address.c_str());
                closeSocket(1);
                return;
            }
        } else {
            socketAddress.sin_family = AF_INET;
            socketAddress.sin_port = htons(port);
            if (inet_pton(AF_INET, address.c_str(), &socketAddress.sin_addr.s_addr) != 1) {
                DEBUG_E("connection(%p) bad ipv4 %s", this, address.c_str());
                closeSocket(1);
                return;
            }
        }
    }

    int yes = 1;
    if (setsockopt(socketFd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(int))) {
        DEBUG_E("connection(%p) set TCP_NODELAY failed", this);
    }

    if (fcntl(socketFd, F_SETFL, O_NONBLOCK) == -1) {
        DEBUG_E("connection(%p) set O_NONBLOCK failed", this);
        closeSocket(1);
        return;
    }

    if (connect(socketFd, (ipv6 ? (sockaddr *) &socketAddress6 : (sockaddr *) &socketAddress), (socklen_t) (ipv6 ? sizeof(sockaddr_in6) : sizeof(sockaddr_in))) == -1 && errno != EINPROGRESS) {
        closeSocket(1);
    } else {
        eventMask.events = EPOLLOUT | EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLET;
        eventMask.data.ptr = eventObject;
        if (epoll_ctl(epolFd, EPOLL_CTL_ADD, socketFd, &eventMask) != 0) {
            DEBUG_E("connection(%p) epoll_ctl, adding socket failed", this);
            closeSocket(1);
        }
    }
}