예제 #1
0
JNL_HTTPGet::JNL_HTTPGet(JNL_AsyncDNS *dns, int recvbufsize, char *proxy)
{
    m_recvbufsize=recvbufsize;
    m_dns=dns;
    m_con=NULL;
    m_http_proxylpinfo=0;
    m_http_proxyhost=0;
    m_http_proxyport=0;
    m_boy_george = 0;
    if (proxy && *proxy)
    {
        char *p=(char*)malloc(strlen(proxy)+1);
        if (p)
        {
            char *r=NULL;
            strcpy(p,proxy);
            do_parse_url(p,&m_http_proxyhost,&m_http_proxyport,&r,&m_http_proxylpinfo);
            free(r);
            free(p);
        }
    }
    m_sendheaders=NULL;
    m_http_redir_url=0;
    reinit();
}
예제 #2
0
void JNL_HTTPGet::connect(const char *url, int ver, char *requestmethod)
{
  deinit();
  m_http_url=(char*)malloc(strlen(url)+1);
  strcpy(m_http_url,url);
  do_parse_url(m_http_url,&m_http_host,&m_http_port,&m_http_request, &m_http_lpinfo);
  strcpy(m_http_url,url);
  if (!m_http_host || !m_http_host[0] || !m_http_port)
  {
    m_http_state=-1;
    seterrstr("invalid URL");
    return;
  }

  int sendbufferlen=0;

  if (!m_http_proxyhost || !m_http_proxyhost[0])
  {
    sendbufferlen += strlen(requestmethod)+1 /* GET */ + strlen(m_http_request) + 9 /* HTTP/1.0 */ + 2;
  }
  else
  {
    sendbufferlen += strlen(requestmethod)+1 /* GET */ + strlen(m_http_url) + 9 /* HTTP/1.0 */ + 2;
    if (m_http_proxylpinfo&&m_http_proxylpinfo[0])
    {
      sendbufferlen+=58+strlen(m_http_proxylpinfo)*2; // being safe here
    }
  }
  sendbufferlen += 5 /* Host: */ + strlen(m_http_host) + 2;

  if (m_http_lpinfo&&m_http_lpinfo[0])
  {
    sendbufferlen+=46+strlen(m_http_lpinfo)*2; // being safe here
  }

  if (m_sendheaders) sendbufferlen+=strlen(m_sendheaders);

  char *str=(char*)malloc(sendbufferlen+1024);
  if (!str)
  {
    seterrstr("error allocating memory");
    m_http_state=-1;    
  }

  if (!m_http_proxyhost || !m_http_proxyhost[0])
  {
    wsprintf(str,"%s %s HTTP/1.%d\r\n",requestmethod,m_http_request,ver%10);
  }
  else
  {
    wsprintf(str,"%s %s HTTP/1.%d\r\n",requestmethod, m_http_url,ver%10);
  }

  wsprintf(str+strlen(str),"Host:%s\r\n",m_http_host);

  if (m_http_lpinfo&&m_http_lpinfo[0])
  {
    strcat(str,"Authorization: Basic ");
    do_encode_mimestr(m_http_lpinfo,str+strlen(str));
    strcat(str,"\r\n");
  }
  if (m_http_proxylpinfo&&m_http_proxylpinfo[0])
  {
    strcat(str,"Proxy-Authorization: Basic ");
    do_encode_mimestr(m_http_proxylpinfo,str+strlen(str));
    strcat(str,"\r\n");
  }

  if (m_sendheaders) strcat(str,m_sendheaders);
  strcat(str,"\r\n");

  int a=m_recvbufsize;
  if (a < 4096) a=4096;
  m_con=new JNL_Connection(m_dns,strlen(str)+4,a);
  if (m_con)
  {
    if (!m_http_proxyhost || !m_http_proxyhost[0])
    {
      m_con->connect(m_http_host,m_http_port);
    }
    else
    {
      m_con->connect(m_http_proxyhost,m_http_proxyport);
    }
    m_con->send_string(str);
  }
  else
  {
    m_http_state=-1;
    seterrstr("could not create connection object");
  }
  free(str);

}
예제 #3
0
void JNL_HTTPGet::connect(const char *url, int ver, char *requestmethod)
{
    deinit();
    m_http_url=(char*)malloc(strlen(url)+1);
    strcpy(m_http_url,url);
    do_parse_url(m_http_url,&m_http_host,&m_http_port,&m_http_request, &m_http_lpinfo);
    strcpy(m_http_url,url);
    if (!m_http_host || !m_http_host[0] || !m_http_port)
    {
        m_boy_george=0;
        m_http_state=-1;
        seterrstr("invalid URL");
        return;
    }

    int sendbufferlen=0;

    if (!m_http_proxyhost || !m_http_proxyhost[0])
    {
        sendbufferlen += strlen(requestmethod)+1 /* GET */ + strlen(m_http_request) + 9 /* HTTP/1.0 */ + 2;
    }
    else
    {
        sendbufferlen += strlen(requestmethod)+1 /* GET */ + strlen(m_http_url) + 9 /* HTTP/1.0 */ + 2;
        if (m_http_proxylpinfo&&m_http_proxylpinfo[0])
        {
            sendbufferlen+=58+strlen(m_http_proxylpinfo)*2; // being safe here
        }
    }
    sendbufferlen += 5 /* Host: */ + strlen(m_http_host) + 2;

    if (m_http_lpinfo&&m_http_lpinfo[0])
    {
        sendbufferlen+=46+strlen(m_http_lpinfo)*2; // being safe here
    }

    if (m_sendheaders) sendbufferlen+=strlen(m_sendheaders);

    char *str=(char*)malloc(sendbufferlen+1024);
    if (!str)
    {
        seterrstr("error allocating memory");
        m_http_state=-1;
        m_boy_george = 0;
    }

    if (!m_http_proxyhost || !m_http_proxyhost[0])
    {
        wsprintf(str,"%s %s HTTP/1.%d\r\n",requestmethod,m_http_request,ver%10);
    }
    else
    {
        wsprintf(str,"%s %s HTTP/1.%d\r\n",requestmethod, m_http_url,ver%10);
    }

    wsprintf(str+strlen(str),"Host:%s\r\n",m_http_host);

    if (m_http_lpinfo&&m_http_lpinfo[0])
    {
        strcat(str,"Authorization: Basic ");
        do_encode_mimestr(m_http_lpinfo,str+strlen(str));
        strcat(str,"\r\n");
    }
    if (m_http_proxylpinfo&&m_http_proxylpinfo[0])
    {
        strcat(str,"Proxy-Authorization: Basic ");
        do_encode_mimestr(m_http_proxylpinfo,str+strlen(str));
        strcat(str,"\r\n");
    }

    if (m_sendheaders) strcat(str,m_sendheaders);
    strcat(str,"\r\n");

    int a=m_recvbufsize;
    if (a < 4096) a=4096;
    //m_con=new JNL_Connection(m_dns,strlen(str)+4,a);
    /*
    **  Joshua Teitelbaum delta 1/15/2006
    */
#ifdef _JNETLIB_SSL_
    /*
    **  Joshua Teitelbaum 1/27/2006
    **  Check for secure
    */
    if(!strnicmp(m_http_url,"https:",strlen("https:")))
    {
        m_con=new JNL_SSL_Connection(NULL,m_dns,8192,a);
    }
    else
    {
        m_con=new JNL_Connection(m_dns,8192,a);
    }
#else
    m_con=new JNL_Connection(m_dns,8192,a);
#endif

    if (m_con)
    {
        if (!m_http_proxyhost || !m_http_proxyhost[0])
        {
            m_con->connect(m_http_host,m_http_port);
        }
        else
        {
            m_con->connect(m_http_proxyhost,m_http_proxyport);
        }
        m_con->send_string(str);
    }
    else
    {
        m_http_state=-1;
        m_boy_george = 0;
        seterrstr("could not create connection object");
    }
    free(str);

}