コード例 #1
0
void JabberClient::connect_ready()
{
    if (!getUseSSL() || m_bSSL){
        connected();
        return;
    }
#ifdef USE_OPENSSL
    m_bSSL = true;
    SSLClient *ssl = new JabberSSL(m_socket->socket());
    m_socket->setSocket(ssl);
    if (!ssl->init()){
        m_socket->error_state("SSL init error");
        return;
    }
    ssl->connect();
    ssl->process();
#endif
}
コード例 #2
0
void HttpRequest::connect_ready()
{
    if (state == WaitConnect){
        state = Connected;
#ifdef USE_OPENSSL
        bool isSecure = m_proxy->isSecure();
        if (isSecure){
            SSLClient *ssl = new SSLClient(m_sock);
            if (!ssl->initHTTPS()){
                delete ssl;
                ssl = NULL;
                error_state(ErrorProxyConnect);
                return;
            }
            ssl->setNotify(this);
            ssl->connect();
            ssl->process();
            m_sock = ssl;
            return;
        }
#endif
    }

    const char *h = host();
    HttpPacket *p = packet();

    Buffer bOut;
    bOut << (p ? "POST" : "GET") << " http://" << h << uri() << " HTTP/1.1\r\n" <<
    "Host: " << h << "\r\n"
    "User-agent: Mozilla/4.08 [en] (WinNT; U ;Nav)\r\n"
    "Cache-control: no-store, no-cache\r\n"
    "Connection: close\r\n"
    "Pragma: no-cache\r\n";

    if (p){
        char b[15];
        snprintf(b, sizeof(b), "%u", p->size + 14);
        bOut << "Content-Length: " << b << "\r\n";
    }

    if (m_proxy->m_user.length()){
        string s;
        s = m_proxy->m_user.c_str();
        s += ":";
        s += m_proxy->m_passwd.c_str();
        s = tobase64(s.c_str());
        bOut << "Proxy-Auth: basic ";
        bOut << s.c_str();
        bOut << "\r\n";
    }
    bOut << "\r\n";
    if (p){
        unsigned short len = p->size + 12;
        bOut
        << len
        << HTTP_PROXY_VERSION
        << p->type
        << 0x00000000L
        << p->nSock;
        if (p->size)
            bOut.pack(p->data, p->size);
        m_proxy->queue.remove(p);
        delete p;
    }
    dumpPacket(bOut, 0, "Proxy write");
    m_sock->write(bOut.Data(0), bOut.size());
    bOut.init(0);
}