当前位置: 首页>>代码示例>>C++>>正文


C++ curl_easy_getinfo函数代码示例

本文整理汇总了C++中curl_easy_getinfo函数的典型用法代码示例。如果您正苦于以下问题:C++ curl_easy_getinfo函数的具体用法?C++ curl_easy_getinfo怎么用?C++ curl_easy_getinfo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了curl_easy_getinfo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: zxid_http_post_raw

/* Called by:  zxid_soap_call_raw */
struct zx_str* zxid_http_post_raw(zxid_conf* cf, int url_len, const char* url, int len, const char* data, const char* SOAPaction)
{
#ifdef USE_CURL
  struct zx_str* ret;
  CURLcode res;
  struct zxid_curl_ctx rc;
  struct zxid_curl_ctx wc;
  struct curl_slist content_type;
  struct curl_slist SOAPaction_curl;
  char* urli;
  rc.buf = rc.p = ZX_ALLOC(cf->ctx, ZXID_INIT_SOAP_BUF+1);
  rc.lim = rc.buf + ZXID_INIT_SOAP_BUF;
#if 0
  cf->curl = curl_easy_init();
  curl_easy_reset(cf->curl);
  LOCK_INIT(cf->curl_mx);
  LOCK(cf->curl_mx, "curl-soap");
#else
  LOCK(cf->curl_mx, "curl-soap");
  curl_easy_reset(cf->curl);
#endif
  curl_easy_setopt(cf->curl, CURLOPT_WRITEDATA, &rc);
  curl_easy_setopt(cf->curl, CURLOPT_WRITEFUNCTION, zxid_curl_write_data);
  curl_easy_setopt(cf->curl, CURLOPT_NOPROGRESS, 1);
  curl_easy_setopt(cf->curl, CURLOPT_FOLLOWLOCATION, 1);
  curl_easy_setopt(cf->curl, CURLOPT_MAXREDIRS, 110);
  curl_easy_setopt(cf->curl, CURLOPT_SSL_VERIFYPEER, 0);  /* *** arrange verification */
  curl_easy_setopt(cf->curl, CURLOPT_SSL_VERIFYHOST, 0);  /* *** arrange verification */
  //curl_easy_setopt(cf->curl, CURLOPT_CERTINFO, 1);

  if (url_len == -1)
    url_len = strlen(url);
  urli = ZX_ALLOC(cf->ctx, url_len+1);
  memcpy(urli, url, url_len);
  urli[url_len] = 0;
  DD("urli(%s) len=%d", urli, len);
  curl_easy_setopt(cf->curl, CURLOPT_URL, urli);
  
  if (len == -1)
    len = strlen(data);
  wc.buf = wc.p = (char*)data;
  wc.lim = (char*)data + len;
  
  curl_easy_setopt(cf->curl, CURLOPT_POST, 1);
  curl_easy_setopt(cf->curl, CURLOPT_POSTFIELDSIZE, len);
  curl_easy_setopt(cf->curl, CURLOPT_READDATA, &wc);
  curl_easy_setopt(cf->curl, CURLOPT_READFUNCTION, zxid_curl_read_data);

  ZERO(&content_type, sizeof(content_type));
  content_type.data = cf->wsc_soap_content_type; /* SOAP11: "Content-Type: text/xml" */
  if (SOAPaction) {
    ZERO(&SOAPaction_curl, sizeof(SOAPaction_curl));
    SOAPaction_curl.data = (char*)SOAPaction;
    SOAPaction_curl.next = &content_type;    //curl_slist_append(3)
    curl_easy_setopt(cf->curl, CURLOPT_HTTPHEADER, &SOAPaction_curl);
  } else {
    curl_easy_setopt(cf->curl, CURLOPT_HTTPHEADER, &content_type);
  }
  
  INFO("----------- call(%s) -----------", urli);
  DD("SOAP_CALL post(%.*s) len=%d\n", len, data, len);
  D_XML_BLOB(cf, "SOAPCALL POST", len, data);
  res = curl_easy_perform(cf->curl);  /* <========= Actual call, blocks. */
  switch (res) {
  case 0: break;
  case CURLE_SSL_CONNECT_ERROR:
    ERR("Is the URL(%s) really an https url? Check that certificate of the server is valid and that certification authority is known to the client. CURLcode(%d) CURLerr(%s)", urli, res, CURL_EASY_STRERR(res));
    DD("buf(%.*s)", rc.lim-rc.buf, rc.buf);
#if 0
    struct curl_certinfo* ci;
    res = curl_easy_getinfo(cf->curl, CURLINFO_CERTINFO, &ci);  /* CURLINFO_SSL_VERIFYRESULT */
    if (!res && ci) {
      int i;
      struct curl_slist *slist;
      D("%d certs", ci->num_of_certs);
      for (i = 0; i < ci->num_of_certs; ++i)
	for (slist = ci->certinfo[i]; slist; slist = slist->next)
	  D("%d: %s", i, slist->data);
    }
#endif
    break;
  default:
    ERR("Failed post to url(%s) CURLcode(%d) CURLerr(%s)", urli, res, CURL_EASY_STRERR(res));
    DD("buf(%.*s)", rc.lim-rc.buf, rc.buf);
  }

  /*curl_easy_getinfo(cf->curl, CURLINFO_CONTENT_TYPE, char*);*/

  UNLOCK(cf->curl_mx, "curl-soap");
  ZX_FREE(cf->ctx, urli);
  rc.lim = rc.p;
  rc.p[0] = 0;

  DD("SOAP_CALL got(%s)", rc.buf);
  D_XML_BLOB(cf, "SOAPCALL GOT", rc.lim - rc.buf, rc.buf);
  
  ret = zx_ref_len_str(cf->ctx, rc.lim - rc.buf, rc.buf);
  return ret;
#else
//.........这里部分代码省略.........
开发者ID:grubba,项目名称:zxid,代码行数:101,代码来源:zxidcurl.c

示例2: retry

bool CurlHttpClient::execute(const internal::HttpRequest& request, internal::HttpResponse& response) {
  CURLStatus_ = CURLE_FAILED_INIT;
  errorBuf_[0] = '\0';

  bool retry(false);
  unsigned retryCount(0);

  response.clear();

  CURL* curl = curl_easy_init();

  if (NULL == curl) {
    return (internal::HttpResponse::HTTP_OK == response.getHttpStatus());
  }

  std::string URI(getRequestString(request));

  FREDCPP_LOG_DEBUG("CURL:URI:" << URI);

  if (!CACertFile_.empty()) {
    std::ifstream ifs(CACertFile_.c_str());
    FREDCPP_LOG_DEBUG("CURL:CACertFile:" << CACertFile_ << " found:" << ifs.good());
  }

  if (CURLE_OK == (CURLStatus_ = curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent_.c_str()))
      && CURLE_OK == (CURLStatus_ = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeDataCallback_))
      && CURLE_OK == (CURLStatus_ = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L))
      && CURLE_OK == (CURLStatus_ = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L))
      && CURLE_OK == (CURLStatus_ = curl_easy_setopt(curl, CURLOPT_FILE, &response.getContentStream()))
      && CURLE_OK == (CURLStatus_ = curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeoutSecs_))
      && CURLE_OK == (CURLStatus_ = curl_easy_setopt(curl, CURLOPT_URL, URI.c_str()))
      && CURLE_OK == (CURLStatus_ = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuf_))
      && (!request.isHttps()
          || CURLE_OK == (CURLStatus_ = curl_easy_setopt(curl, CURLOPT_CAINFO, CACertFile_.c_str())))
      ) {

    do {
      CURLStatus_ = curl_easy_perform(curl);

      if (CURLE_OK == CURLStatus_) {
        // on successfull call get http-status and content-type

        long code(0L);
        char *strInfo(NULL);
        if (CURLE_OK == curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code)
            && CURLE_OK == curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &strInfo)) {
          response.setHttpStatus(httpStatusFromCode(code));
          response.setContentType(strInfo);
        }

      } else {
        FREDCPP_LOG_DEBUG("CURL:Request failed CURLStatus:" << CURLStatus_
                          << "|" << errorBuf_);
      }

      retry = (CURLE_OPERATION_TIMEDOUT == CURLStatus_
               || CURLE_COULDNT_RESOLVE_HOST == CURLStatus_
               || CURLE_COULDNT_RESOLVE_PROXY == CURLStatus_
               || CURLE_COULDNT_CONNECT == CURLStatus_);

      if (retry) {
        if (retryCount < retryMaxCount_) {
          ++retryCount;
          FREDCPP_LOG_DEBUG("CURL:Waiting " << retryWaitSecs_ << "ms"
                            << " before request retry " << retryCount << " ...");
          internal::sleep(retryWaitSecs_);

        } else {
          retry = false;
          FREDCPP_LOG_DEBUG("CURL:Retry maximum count " << retryMaxCount_ << " reached - giving up.");
        }
      }

    } while (retry);
  }

  if (CURLE_OK == CURLStatus_) {
    FREDCPP_LOG_DEBUG("CURL:http-response:" << response.getHttpStatus()
                      << " " << "content-type:" << response.getContentType());

  }

  curl_easy_cleanup(curl);

  return (internal::HttpResponse::HTTP_OK == response.getHttpStatus());
}
开发者ID:nomadbyte,项目名称:fredcpp,代码行数:86,代码来源:CurlHttpClient.cpp

示例3: curl_easy_getinfo

const char *wswcurl_get_content_type( wswcurl_req *req )
{
	char *content_type = NULL;
	curl_easy_getinfo( req->curl, CURLINFO_CONTENT_TYPE, &content_type );
	return content_type;
}
开发者ID:tenght,项目名称:qfusion,代码行数:6,代码来源:wswcurl.c

示例4: curl_easy_getinfo

///==============================return the current url=============================///
std::string Browser::geturl()
{
    char * current_url;
    curl_easy_getinfo(curl,CURLINFO_EFFECTIVE_URL, &current_url);
    return current_url;
}
开发者ID:venam,项目名称:alpapap,代码行数:7,代码来源:Browser.hpp

示例5: curl_open

static int curl_open(BlockDriverState *bs, QDict *options, int flags,
                     Error **errp)
{
    BDRVCURLState *s = bs->opaque;
    CURLState *state = NULL;
    QemuOpts *opts;
    Error *local_err = NULL;
    const char *file;
    double d;

    static int inited = 0;

    if (flags & BDRV_O_RDWR) {
        qerror_report(ERROR_CLASS_GENERIC_ERROR,
                      "curl block device does not support writes");
        return -EROFS;
    }

    opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
    qemu_opts_absorb_qdict(opts, options, &local_err);
    if (error_is_set(&local_err)) {
        qerror_report_err(local_err);
        error_free(local_err);
        goto out_noclean;
    }

    s->readahead_size = qemu_opt_get_size(opts, "readahead", READ_AHEAD_SIZE);
    if ((s->readahead_size & 0x1ff) != 0) {
        fprintf(stderr, "HTTP_READAHEAD_SIZE %zd is not a multiple of 512\n",
                s->readahead_size);
        goto out_noclean;
    }

    file = qemu_opt_get(opts, "url");
    if (file == NULL) {
        qerror_report(ERROR_CLASS_GENERIC_ERROR, "curl block driver requires "
                      "an 'url' option");
        goto out_noclean;
    }

    if (!inited) {
        curl_global_init(CURL_GLOBAL_ALL);
        inited = 1;
    }

    DPRINTF("CURL: Opening %s\n", file);
    s->url = g_strdup(file);
    state = curl_init_state(s);
    if (!state)
        goto out_noclean;

    // Get file size

    s->accept_range = false;
    curl_easy_setopt(state->curl, CURLOPT_NOBODY, 1);
    curl_easy_setopt(state->curl, CURLOPT_HEADERFUNCTION,
                     curl_header_cb);
    curl_easy_setopt(state->curl, CURLOPT_HEADERDATA, s);
    if (curl_easy_perform(state->curl))
        goto out;
    curl_easy_getinfo(state->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
    if (d)
        s->len = (size_t)d;
    else if(!s->len)
        goto out;
    if ((!strncasecmp(s->url, "http://", strlen("http://"))
        || !strncasecmp(s->url, "https://", strlen("https://")))
        && !s->accept_range) {
        pstrcpy(state->errmsg, CURL_ERROR_SIZE,
                "Server does not support 'range' (byte ranges).");
        goto out;
    }
    DPRINTF("CURL: Size = %zd\n", s->len);

    curl_clean_state(state);
    curl_easy_cleanup(state->curl);
    state->curl = NULL;

    // Now we know the file exists and its size, so let's
    // initialize the multi interface!

    s->multi = curl_multi_init();
    curl_multi_setopt(s->multi, CURLMOPT_SOCKETDATA, s);
    curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);
    curl_multi_do(s);

    qemu_opts_del(opts);
    return 0;

out:
    fprintf(stderr, "CURL: Error opening file: %s\n", state->errmsg);
    curl_easy_cleanup(state->curl);
    state->curl = NULL;
out_noclean:
    g_free(s->url);
    qemu_opts_del(opts);
    return -EINVAL;
}
开发者ID:ISI-apex,项目名称:QEMU-arm,代码行数:98,代码来源:curl.c

示例6: ocfetchurl

int
ocfetchurl(CURL* curl, const char* url, OCbytes* buf, long* filetime,
           struct OCcredentials* creds)
{
    int stat = OC_NOERR;
    CURLcode cstat = CURLE_OK;
    size_t len;
    long httpcode = 0;
    char tbuf[1024];
    /* Set the URL */
    cstat = curl_easy_setopt(curl, CURLOPT_URL, (void*)url);
    if (cstat != CURLE_OK)
        goto fail;

    if(creds != NULL && creds->password != NULL  && creds->username != NULL) {
        /* Set user and password */
#if defined (HAVE_CURLOPT_USERNAME) && defined (HAVE_CURLOPT_PASSWORD)
        cstat = curl_easy_setopt(curl, CURLOPT_USERNAME, creds->username);
        if (cstat != CURLE_OK)
            goto fail;
        cstat = curl_easy_setopt(curl, CURLOPT_PASSWORD, creds->password);
        if (cstat != CURLE_OK)
            goto fail;
#else
        snprintf(tbuf,1023,"%s:%s",creds->username,creds->password);
        cstat = curl_easy_setopt(curl, CURLOPT_USERPWD, tbuf);
        if (cstat != CURLE_OK)
            goto fail;
#endif
    }

    /* send all data to this function  */
    cstat = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
    if (cstat != CURLE_OK)
        goto fail;

    /* we pass our file to the callback function */
    cstat = curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)buf);
    if (cstat != CURLE_OK)
        goto fail;

    /* One last thing; always try to get the last modified time */
    cstat = curl_easy_setopt(curl, CURLOPT_FILETIME, (long)1);

    cstat = curl_easy_perform(curl);

    if(cstat == CURLE_PARTIAL_FILE) {
        /* Log it but otherwise ignore */
        oclog(OCLOGWARN, "curl error: %s; ignored",
              curl_easy_strerror(cstat));
        cstat = CURLE_OK;
    }
    httpcode = ocfetchhttpcode(curl);

    if(cstat != CURLE_OK) goto fail;

    /* Get the last modified time */
    if(filetime != NULL)
        cstat = curl_easy_getinfo(curl,CURLINFO_FILETIME,filetime);
    if(cstat != CURLE_OK) goto fail;

    /* Null terminate the buffer*/
    len = ocbyteslength(buf);
    ocbytesappend(buf, '\0');
    ocbytessetlength(buf, len); /* dont count null in buffer size*/
#ifdef OCDEBUG
    oclog(OCLOGNOTE,"buffersize: %lu bytes",(off_t)ocbyteslength(buf));
#endif

    return OCTHROW(stat);

fail:
    oclog(OCLOGERR, "curl error: %s", curl_easy_strerror(cstat));
    switch (httpcode) {
    case 401:
        stat = OC_EAUTH;
        break;
    case 404:
        stat = OC_ENOFILE;
        break;
    case 500:
        stat = OC_EDAPSVC;
        break;
    case 200:
        break;
    default:
        stat = OC_ECURL;
        break;
    }
    return OCTHROW(stat);
}
开发者ID:rykroon,项目名称:netcdf-c,代码行数:91,代码来源:ochttp.c

示例7: spider


//.........这里部分代码省略.........
		}

		if(timeout) 
			curl_easy_setopt(curl,CURLOPT_TIMEOUT,timeout); 

// load single proxy
		if(arg[17] != NULL)
		{
			curl_easy_setopt(curl, CURLOPT_PROXY, arg[17]);
	//		curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1);
		}

// load random proxy in list 
		if(arg[18] != NULL)
		{
			char *randproxy=Random_linefile(arg[18]);
	//		printf("PROXY LOAD: %s\n",randproxy);
			curl_easy_setopt(curl, CURLOPT_PROXY, randproxy);
	//		curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1);
		}


		if ( arg[9] != NULL ) 
			curl_easy_setopt(curl,CURLOPT_SSLVERSION,(long)atoi(arg[9]));

                curl_easy_setopt(curl,CURLOPT_VERBOSE,0); 
		curl_easy_setopt(curl,CURLOPT_HEADER,1);  
		
		if(arg[21]!=NULL)
		{
			curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
		}
		res=curl_easy_perform(curl);
		curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE,&status);

// custom http request
		if(arg[21]!=NULL)
		{
			curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr); 
			sockfd = sockextr;

			if(!wait_on_socket(sockfd, 0, 60000L))
			{
				DEBUG("error in socket at custom http request");
			}
			res=curl_easy_send(curl, make, strlen(make), &iolen);
// recv data
			while(1)
			{
				wait_on_socket(sockfd, 1, 60000L);
				chunk.memory=xmalloc(sizeof(char)*3024); 
				res = curl_easy_recv(curl, chunk.memory, 3023, &iolen); 
				chunk.size=strlen(chunk.memory);				

				if(strlen(chunk.memory) > 8)
					break;

			        if(CURLE_OK != res)
        				break;

			}

			
			status=(long)parse_http_status(chunk.memory);
//status=404;
		}
开发者ID:borbelyau,项目名称:0d1n,代码行数:67,代码来源:spider.c

示例8: FD_ZERO

void ResourceHandleManager::downloadTimerCallback(Timer<ResourceHandleManager>* timer)
{
    fd_set fdread;
    fd_set fdwrite;
    fd_set fdexcep;
    int maxfd = 0;

    FD_ZERO(&fdread);
    FD_ZERO(&fdwrite);
    FD_ZERO(&fdexcep);
    curl_multi_fdset(m_curlMultiHandle, &fdread, &fdwrite, &fdexcep, &maxfd);

    struct timeval timeout;
    timeout.tv_sec = 0;
    timeout.tv_usec = selectTimeoutMS * 1000;       // select waits microseconds

    int rc = ::select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);

    if (-1 == rc) {
#ifndef NDEBUG
        printf("bad: select() returned -1\n");
#endif
        return;
    }

    int runningHandles = 0;
    CURLMcode curlCode = CURLM_CALL_MULTI_PERFORM;
    while (CURLM_CALL_MULTI_PERFORM == curlCode) {
        curlCode = curl_multi_perform(m_curlMultiHandle, &runningHandles);
    }

    // check the curl messages indicating completed transfers
    // and free their resources
    while (true) {
        int messagesInQueue;
        CURLMsg* msg = curl_multi_info_read(m_curlMultiHandle, &messagesInQueue);
        if (!msg)
            break;

        if (CURLMSG_DONE != msg->msg)
            continue;

        // find the node which has same d->m_handle as completed transfer
        CURL* handle = msg->easy_handle;
        ASSERT(handle);
        ResourceHandle* job;
        curl_easy_getinfo(handle, CURLINFO_PRIVATE, &job);
        ASSERT(job);
        if (!job)
            continue;

        ResourceHandleInternal* d = job->getInternal();
        if (CURLE_OK == msg->data.result) {
            if (d->client())
                d->client()->didFinishLoading(job);
        } else {
#ifndef NDEBUG
            char* url = 0;
            curl_easy_getinfo(d->m_handle, CURLINFO_EFFECTIVE_URL, &url);
            printf("Curl ERROR for url='%s', error: '%s'\n", url, curl_easy_strerror(msg->data.result));
            free(url);
#endif
            if (d->client())
                d->client()->didFail(job, ResourceError());
        }

        removeFromCurl(job);
    }

    if (!m_downloadTimer.isActive() && (runningHandles > 0))
        m_downloadTimer.startOneShot(pollTimeSeconds);
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:72,代码来源:ResourceHandleManager.cpp

示例9: curl_easy_setopt

void CCHttpRequest_impl::onRequest(void)
{
    if (m_postFields.size() > 0)
    {
        curl_easy_setopt(m_curl, CURLOPT_POST, 1L);
        std::stringbuf buf;
        PostFieldsIterator it = m_postFields.begin();
        while (it != m_postFields.end())
        {
            char* part = curl_easy_escape(m_curl, it->first.c_str(), 0);
            buf.sputn(part, strlen(part));
            buf.sputc('=');
            curl_free(part);

            part = curl_easy_escape(m_curl, it->second.c_str(), 0);
            buf.sputn(part, strlen(part));
            curl_free(part);

            ++it;
            if (it != m_postFields.end()) buf.sputc('&');
        }
        curl_easy_setopt(m_curl, CURLOPT_COPYPOSTFIELDS, buf.str().c_str());
    }
    else if (m_postdata.length() > 0)
    {
        curl_easy_setopt(m_curl, CURLOPT_POST, 1L);
        curl_easy_setopt(m_curl, CURLOPT_COPYPOSTFIELDS, m_postdata.c_str());
    }
    else if (m_isPost)
    {
        curl_easy_setopt(m_curl, CURLOPT_COPYPOSTFIELDS, "");
    }

    struct curl_slist* chunk = NULL;
    for (HeadersIterator it = m_headers.begin(); it != m_headers.end(); ++it)
    {
        chunk = curl_slist_append(chunk, (*it).c_str());
    }

    curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, chunk);
	curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, 0);
	curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYHOST, 0);
	curl_easy_setopt(m_curl, CURLOPT_NOSIGNAL, 1);


    CURLcode code = curl_easy_perform(m_curl);
    curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &m_responseCode);
    curl_easy_cleanup(m_curl);
    m_curl = NULL;
    curl_slist_free_all(chunk);

    m_errorCode = (code == CURLE_OK) ? CCHttpRequestErrorNone : CCHttpRequestErrorUnknown;
    m_errorMessage = (code == CURLE_OK) ? "" : curl_easy_strerror(code);
    
    m_responseData = (unsigned char*)malloc(m_rawResponseBuffLength + 1);
    m_responseData[m_rawResponseBuffLength] = '\0';
    m_responseDataLength = 0;
    for (RawResponseDataBuffIterator it = m_rawResponseBuff.begin(); it != m_rawResponseBuff.end(); ++it)
    {
        CCHttpRequest_impl::Chunk* chunk = *it;
        size_t bytes = chunk->getBytes();
        memcpy(m_responseData + m_responseDataLength, chunk->getChunk(), bytes);
        m_responseDataLength += bytes;
    }
    cleanupRawResponseBuff();
    
    m_responseString = std::string(reinterpret_cast<char*>(m_responseData));
    m_state = STATE_COMPLETED;
}
开发者ID:liyonghelpme,项目名称:iosdifferentbranchcode,代码行数:69,代码来源:CCHttpRequest_impl.cpp

示例10: curl_easy_init

void* cURLCamera::thread_func()
{
  long tRet;
  double dSize;

  c = curl_easy_init();
  if(c == NULL) {
    Fatal("Failed getting easy handle from libcurl");
  }

  /* Set URL */
  cRet = curl_easy_setopt(c, CURLOPT_URL, mPath.c_str());
  if(cRet != CURLE_OK)
    Fatal("Failed setting libcurl URL: %s", curl_easy_strerror(cRet));
  
  /* Header callback */
  cRet = curl_easy_setopt(c, CURLOPT_HEADERFUNCTION, &header_callback_dispatcher);
  if(cRet != CURLE_OK)
    Fatal("Failed setting libcurl header callback function: %s", curl_easy_strerror(cRet));
  cRet = curl_easy_setopt(c, CURLOPT_HEADERDATA, this);
  if(cRet != CURLE_OK)
    Fatal("Failed setting libcurl header callback object: %s", curl_easy_strerror(cRet));

  /* Data callback */
  cRet = curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, &data_callback_dispatcher);
  if(cRet != CURLE_OK)
    Fatal("Failed setting libcurl data callback function: %s", curl_easy_strerror(cRet));
  cRet = curl_easy_setopt(c, CURLOPT_WRITEDATA, this);
  if(cRet != CURLE_OK)
    Fatal("Failed setting libcurl data callback object: %s", curl_easy_strerror(cRet));

  /* Progress callback */
  cRet = curl_easy_setopt(c, CURLOPT_NOPROGRESS, 0);
  if(cRet != CURLE_OK)
    Fatal("Failed enabling libcurl progress callback function: %s", curl_easy_strerror(cRet));  
  cRet = curl_easy_setopt(c, CURLOPT_PROGRESSFUNCTION, &progress_callback_dispatcher);
  if(cRet != CURLE_OK)
    Fatal("Failed setting libcurl progress callback function: %s", curl_easy_strerror(cRet));
  cRet = curl_easy_setopt(c, CURLOPT_PROGRESSDATA, this);
  if(cRet != CURLE_OK)
    Fatal("Failed setting libcurl progress callback object: %s", curl_easy_strerror(cRet));

  /* Set username and password */
  if(!mUser.empty()) {
    cRet = curl_easy_setopt(c, CURLOPT_USERNAME, mUser.c_str());
    if(cRet != CURLE_OK)
      Error("Failed setting username: %s", curl_easy_strerror(cRet));
  }
  if(!mPass.empty()) {
    cRet = curl_easy_setopt(c, CURLOPT_PASSWORD, mPass.c_str());
    if(cRet != CURLE_OK)
      Error("Failed setting password: %s", curl_easy_strerror(cRet));
  }

  /* Authenication preference */
  cRet = curl_easy_setopt(c, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  if(cRet != CURLE_OK)
    Warning("Failed setting libcurl acceptable http authenication methods: %s", curl_easy_strerror(cRet));


  /* Work loop */
  for(int attempt=1;attempt<=CURL_MAXRETRY;attempt++) {
    tRet = 0;
    while(!bTerminate) {
      /* Do the work */
      cRet = curl_easy_perform(c);

      if(mode == MODE_SINGLE) {
        if(cRet != CURLE_OK) {
          break;
        }
        /* Attempt to get the size of the file */
        cRet = curl_easy_getinfo(c, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &dSize);
        if(cRet != CURLE_OK) {
          break;
        }
        /* We need to lock for the offsets array and the condition variable */
        lock();
        /* Push the size into our offsets array */
        if(dSize > 0) {
          single_offsets.push_back(dSize);
        } else {
          Fatal("Unable to get the size of the image");
        }
        /* Signal the request complete condition variable */
        tRet = pthread_cond_signal(&request_complete_cond);
        if(tRet != 0) {
          Error("Failed signaling request completed condition variable: %s",strerror(tRet));
        }
        /* Unlock */
        unlock();

      } else if (mode == MODE_STREAM) {
        break;
      }
    }

    /* Return value checking */
    if(cRet == CURLE_ABORTED_BY_CALLBACK || bTerminate) {
      /* Aborted */
//.........这里部分代码省略.........
开发者ID:josh4trunks,项目名称:ZoneMinder,代码行数:101,代码来源:zm_curl_camera.cpp

示例11: curl_global_init

char *request(const char *url)
{
	CURL *curl = NULL;
	CURLcode status;
	struct curl_slist *headers = NULL;
	char *data = NULL;
	long code;

	curl_global_init(CURL_GLOBAL_ALL);
	curl = curl_easy_init();
	if(!curl)
		goto error;

	data = malloc(BUFFER_SIZE);
	if(!data)
		goto error;

	struct write_result write_result = {
		.data = data,
		.pos = 0
	};

	curl_easy_setopt(curl, CURLOPT_URL, url);

	headers = curl_slist_append(headers, "User-Agent: sea/0.1");
	headers = curl_slist_append(headers, "Content-Type: application/json");

	size_t token_size = 255;
	char *token = (char *)calloc(sizeof(char), token_size);
	get_auth_token(token, token_size);
	headers = curl_slist_append(headers, token);
	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

	// headers = curl_slist_append(headers, sprintf("Authorization: Bearer %s", token));
	// curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_response);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &write_result);

	status = curl_easy_perform(curl);
	if(status != 0)
	{
		fprintf(stderr, "error: unable to request data from %s:\n", url);
		fprintf(stderr, "%s\n", curl_easy_strerror(status));
		goto error;
	}

	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
	if(code != 200)
	{
		fprintf(stderr, "error: server responded with code %ld\n", code);
		goto error;
	}

	curl_easy_cleanup(curl);
	curl_slist_free_all(headers);
	curl_global_cleanup();

	/* zero-terminate the result */
	data[write_result.pos] = '\0';

	return data;

error:
	if(data)
		free(data);
	if(curl)
		curl_easy_cleanup(curl);
	if(headers)
		curl_slist_free_all(headers);
	if(token)
		free(token);
	curl_global_cleanup();
	return NULL;
}
开发者ID:cagedmantis,项目名称:sea,代码行数:75,代码来源:request.c

示例12: st_http_record_sync_info

static int
st_http_record_sync_info(u1db_sync_target *st,
        const char *source_replica_uid, int source_gen, const char *trans_id)
{
    struct _http_state *state;
    struct _http_request req = {0};
    char *url = NULL;
    int status;
    long http_code;
    json_object *json = NULL;
    const char *raw_body = NULL;
    int raw_len;
    struct curl_slist *headers = NULL;

    if (st == NULL || source_replica_uid == NULL || st->implementation == NULL)
    {
        return U1DB_INVALID_PARAMETER;
    }
    status = impl_as_http_state(st->implementation, &state);
    if (status != U1DB_OK) {
        return status;
    }

    status = u1db__format_sync_url(st, source_replica_uid, &url);
    if (status != U1DB_OK) { goto finish; }
    json = json_object_new_object();
    if (json == NULL) {
        status = U1DB_NOMEM;
        goto finish;
    }
    json_object_object_add(json, "generation", json_object_new_int(source_gen));
    json_object_object_add(json, "transaction_id",
                           json_object_new_string(trans_id));
    raw_body = json_object_to_json_string(json);
    raw_len = strlen(raw_body);
    req.state = state;
    req.put_buffer = raw_body;
    req.num_put_bytes = raw_len;

    headers = curl_slist_append(headers, "Content-Type: application/json");
    // We know the message is going to be short, no reason to wait for server
    // confirmation of the post.
    headers = curl_slist_append(headers, "Expect:");

    status = curl_easy_setopt(state->curl, CURLOPT_URL, url);
    if (status != CURLE_OK) { goto finish; }
    status = curl_easy_setopt(state->curl, CURLOPT_HTTPHEADER, headers);
    if (status != CURLE_OK) { goto finish; }
    status = curl_easy_setopt(state->curl, CURLOPT_UPLOAD, 1L);
    if (status != CURLE_OK) { goto finish; }
    status = curl_easy_setopt(state->curl, CURLOPT_PUT, 1L);
    if (status != CURLE_OK) { goto finish; }
    status = simple_set_curl_data(state->curl, &req, &req, &req);
    if (status != CURLE_OK) { goto finish; }
    status = curl_easy_setopt(state->curl, CURLOPT_INFILESIZE_LARGE,
                              (curl_off_t)req.num_put_bytes);
    if (status != CURLE_OK) { goto finish; }
    status = maybe_sign_url(st, "PUT", url, &headers);
    if (status != U1DB_OK) { goto finish; }

    // Now actually send the data
    status = curl_easy_perform(state->curl);
    if (status != CURLE_OK) { goto finish; }
    status = curl_easy_getinfo(state->curl, CURLINFO_RESPONSE_CODE, &http_code);
    if (status != CURLE_OK) { goto finish; }
    if (http_code != 200 && http_code != 201) {
        status = http_code;
        goto finish;
    }
finish:
    if (req.header_buffer != NULL) {
        free(req.header_buffer);
    }
    if (req.body_buffer != NULL) {
        free(req.body_buffer);
    }
    if (json != NULL) {
        json_object_put(json);
    }
    if (url != NULL) {
        free(url);
    }
    if (headers != NULL) {
        curl_slist_free_all(headers);
    }
    return status;
}
开发者ID:Kazade,项目名称:Tasks,代码行数:87,代码来源:u1db_http_sync_target.c

示例13: st_http_get_sync_info

static int
st_http_get_sync_info(u1db_sync_target *st,
        const char *source_replica_uid,
        const char **st_replica_uid, int *st_gen, int *source_gen,
        char **trans_id)
{
    struct _http_state *state;
    struct _http_request req = {0};
    char *url = NULL;
    const char *tmp = NULL;
    int status;
    long http_code;
    struct curl_slist *headers = NULL;

    json_object *json = NULL, *obj = NULL;

    if (st == NULL || source_replica_uid == NULL || st_replica_uid == NULL
            || st_gen == NULL || source_gen == NULL
            || st->implementation == NULL)
    {
        return U1DB_INVALID_PARAMETER;
    }
    status = impl_as_http_state(st->implementation, &state);
    if (status != U1DB_OK) {
        return status;
    }

    headers = curl_slist_append(NULL, "Content-Type: application/json");
    if (headers == NULL) {
        status = U1DB_NOMEM;
        goto finish;
    }
    req.state = state;
    status = u1db__format_sync_url(st, source_replica_uid, &url);
    if (status != U1DB_OK) { goto finish; }
    status = curl_easy_setopt(state->curl, CURLOPT_HTTPGET, 1L);
    if (status != CURLE_OK) { goto finish; }
    // status = curl_easy_setopt(state->curl, CURLOPT_USERAGENT, "...");
    status = curl_easy_setopt(state->curl, CURLOPT_URL, url);
    if (status != CURLE_OK) { goto finish; }
    req.body_buffer = req.header_buffer = NULL;
    status = simple_set_curl_data(state->curl, &req, &req, NULL);
    if (status != CURLE_OK) { goto finish; }
    status = maybe_sign_url(st, "GET", url, &headers);
    if (status != U1DB_OK) { goto finish; }
    status = curl_easy_setopt(state->curl, CURLOPT_HTTPHEADER, headers);
    if (status != CURLE_OK) { goto finish; }
    // Now do the GET
    status = curl_easy_perform(state->curl);
    if (status != CURLE_OK) { goto finish; }
    status = curl_easy_getinfo(state->curl, CURLINFO_RESPONSE_CODE, &http_code);
    if (status != CURLE_OK) { goto finish; }
    if (http_code != 200) { // 201 for created? shouldn't happen on GET
        status = http_code;
        goto finish;
    }
    if (req.body_buffer == NULL) {
        status = U1DB_INVALID_HTTP_RESPONSE;
        goto finish;
    }
    json = json_tokener_parse(req.body_buffer);
    if (json == NULL) {
        status = U1DB_NOMEM;
        goto finish;
    }
    obj = json_object_object_get(json, "target_replica_uid");
    if (obj == NULL) {
        status = U1DB_INVALID_HTTP_RESPONSE;
        goto finish;
    }
    if (state->replica_uid == NULL) {
        // we cache this on the state object, because the api for get_sync_info
        // asserts that callers do not have to free the returned string.
        // This isn't a functional problem, because if the sync target ever
        // changed its replica uid we'd be seriously broken anyway.
        state->replica_uid = strdup(json_object_get_string(obj));
    } else {
        if (strcmp(state->replica_uid, json_object_get_string(obj)) != 0) {
            // Our http target changed replica_uid, this would be a really
            // strange bug
            status = U1DB_INVALID_HTTP_RESPONSE;
            goto finish;
        }
    }
    *st_replica_uid = state->replica_uid;
    if (*st_replica_uid == NULL) {
        status = U1DB_NOMEM;
        goto finish;
    }
    obj = json_object_object_get(json, "target_replica_generation");
    if (obj == NULL) {
        status = U1DB_INVALID_HTTP_RESPONSE;
        goto finish;
    }
    *st_gen = json_object_get_int(obj);
    obj = json_object_object_get(json, "source_replica_generation");
    if (obj == NULL) {
        status = U1DB_INVALID_HTTP_RESPONSE;
        goto finish;
    }
//.........这里部分代码省略.........
开发者ID:Kazade,项目名称:Tasks,代码行数:101,代码来源:u1db_http_sync_target.c

示例14: zxid_get_last_content_type

const char* zxid_get_last_content_type(zxid_conf* cf)
{
  char* ct;
  curl_easy_getinfo(cf->curl, CURLINFO_CONTENT_TYPE, &ct);
  return ct;
}
开发者ID:grubba,项目名称:zxid,代码行数:6,代码来源:zxidcurl.c

示例15: GTHTTP_sendRequest

int GTHTTP_sendRequest(const char *url,
                       const unsigned char *request, size_t request_length,
                       unsigned char **response, size_t *response_length,
                       char **error)
{
    int res = GT_UNKNOWN_ERROR;
    CURL *curl = NULL;
    char *err = NULL;
    internal_curl_receive_buffer receive_buffer = { NULL, 0 };
    long http_res;

    if (url == NULL || response == NULL || response_length == NULL) {
        res = GT_INVALID_ARGUMENT;
        goto cleanup;
    }

    curl = curl_easy_init();
    if (curl == NULL) {
        res = map_impl(CURLE_FAILED_INIT);
        goto cleanup;
    }

    if (error != NULL) {
        err = GT_malloc(CURL_ERROR_SIZE + 1);
        if (err == NULL) {
            res = GT_OUT_OF_MEMORY;
            goto cleanup;
        }
    }

    curl_easy_setopt(curl, CURLOPT_USERAGENT, agent);
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
    if (request != NULL) {
        curl_easy_setopt(curl, CURLOPT_POST, 1);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (const void *) request);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, request_length);
    }
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, receiveDataFromLibCurl);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &receive_buffer);
    if (connect_timeout >= 0) {
        curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, connect_timeout);
    }
    if (response_timeout >= 0) {
        curl_easy_setopt(curl, CURLOPT_TIMEOUT, response_timeout);
    }
    curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
    if (err != NULL) {
        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err);
    }

    res = curl_easy_perform(curl);

    if (res != CURLE_OK && error != NULL) {
        // we had some error and client code wanted the message
        *error = err;
        err = NULL;
    }

    if (res == CURLE_HTTP_RETURNED_ERROR) {
        if (curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &http_res) == CURLE_OK) {
            // now we have the actual HTTP response code, so we replace
            // the generic 'HTTP error' with the more accurate one
            res = map_http(http_res);
            goto cleanup;
        }
    }

    res = map_impl(res);
    if (res != GT_OK) {
        goto cleanup;
    }

    *response = receive_buffer.buffer;
    receive_buffer.buffer = NULL;
    *response_length = receive_buffer.buf_sz;

cleanup:

    curl_easy_cleanup(curl);
    GT_free(receive_buffer.buffer);
    GT_free(err);

    return res;
}
开发者ID:node-migrator-bot,项目名称:node-guardtime,代码行数:85,代码来源:gt_http.c


注:本文中的curl_easy_getinfo函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。