• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ curl_easy_cleanup函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test

int test(char *URL)
{
  CURL *c;
  CURLM *m;
  int res = 0;
  int running;
  char done = FALSE;
  struct timeval ml_start;
  struct timeval mp_start;
  char ml_timedout = FALSE;
  char mp_timedout = FALSE;

  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
    fprintf(stderr, "curl_global_init() failed\n");
    return TEST_ERR_MAJOR_BAD;
  }

  if ((c = curl_easy_init()) == NULL) {
    fprintf(stderr, "curl_easy_init() failed\n");
    curl_global_cleanup();
    return TEST_ERR_MAJOR_BAD;
  }

  curl_easy_setopt(c, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
  curl_easy_setopt(c, CURLOPT_URL, URL);
  curl_easy_setopt(c, CURLOPT_USERPWD, "test:ing");
  curl_easy_setopt(c, CURLOPT_PROXYUSERPWD, "test:ing");
  curl_easy_setopt(c, CURLOPT_HTTPPROXYTUNNEL, 1L);
  curl_easy_setopt(c, CURLOPT_HEADER, 1L);

  if ((m = curl_multi_init()) == NULL) {
    fprintf(stderr, "curl_multi_init() failed\n");
    curl_easy_cleanup(c);
    curl_global_cleanup();
    return TEST_ERR_MAJOR_BAD;
  }

  if ((res = (int)curl_multi_add_handle(m, c)) != CURLM_OK) {
    fprintf(stderr, "curl_multi_add_handle() failed, "
            "with code %d\n", res);
    curl_multi_cleanup(m);
    curl_easy_cleanup(c);
    curl_global_cleanup();
    return TEST_ERR_MAJOR_BAD;
  }

  ml_timedout = FALSE;
  ml_start = tutil_tvnow();

  while(!done) {
    fd_set rd, wr, exc;
    int max_fd;
    struct timeval interval;

    interval.tv_sec = 1;
    interval.tv_usec = 0;

    if (tutil_tvdiff(tutil_tvnow(), ml_start) >
        MAIN_LOOP_HANG_TIMEOUT) {
      ml_timedout = TRUE;
      break;
    }
    mp_timedout = FALSE;
    mp_start = tutil_tvnow();

    while (res == CURLM_CALL_MULTI_PERFORM) {
      res = (int)curl_multi_perform(m, &running);
      if (tutil_tvdiff(tutil_tvnow(), mp_start) >
          MULTI_PERFORM_HANG_TIMEOUT) {
        mp_timedout = TRUE;
        break;
      }
      if (running <= 0) {
        done = TRUE;
        break;
      }
    }
    if (mp_timedout || done)
      break;

    if (res != CURLM_OK) {
      fprintf(stderr, "not okay???\n");
      break;
    }

    FD_ZERO(&rd);
    FD_ZERO(&wr);
    FD_ZERO(&exc);
    max_fd = 0;

    if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
      fprintf(stderr, "unexpected failured of fdset.\n");
      res = 89;
      break;
    }

    if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) {
      fprintf(stderr, "bad select??\n");
      res = 95;
      break;
//.........这里部分代码省略.........
开发者ID:JulianSpillane,项目名称:moai-dev,代码行数:101,代码来源:lib503.c


示例2: testMultithreadedPoolPut

static int
testMultithreadedPoolPut ()
{
    struct MHD_Daemon *d;
    CURL *c;
    struct CBC cbc;
    unsigned int pos = 0;
    int done_flag = 0;
    CURLcode errornum;
    char buf[2048];

    cbc.buf = buf;
    cbc.size = 2048;
    cbc.pos = 0;
    d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG,
                          1081,
                          NULL, NULL, &ahc_echo, &done_flag,
                          MHD_OPTION_THREAD_POOL_SIZE, 4,
                          MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (1024*1024),
                          MHD_OPTION_END);
    if (d == NULL)
        return 16;
    c = curl_easy_init ();
    curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world");
    curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
    curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
    curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer);
    curl_easy_setopt (c, CURLOPT_READDATA, &pos);
    curl_easy_setopt (c, CURLOPT_UPLOAD, 1L);
    curl_easy_setopt (c, CURLOPT_INFILESIZE, (long) PUT_SIZE);
    curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
    curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
    if (oneone)
        curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    else
        curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L);
    // NOTE: use of CONNECTTIMEOUT without also
    //   setting NOSIGNAL results in really weird
    //   crashes on my system!
    curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
    if (CURLE_OK != (errornum = curl_easy_perform (c)))
    {
        fprintf (stderr,
                 "curl_easy_perform failed: `%s'\n",
                 curl_easy_strerror (errornum));
        curl_easy_cleanup (c);
        MHD_stop_daemon (d);
        return 32;
    }
    curl_easy_cleanup (c);
    MHD_stop_daemon (d);
    if (cbc.pos != strlen ("/hello_world"))
    {
        fprintf (stderr, "Got invalid response `%.*s'\n", (int)cbc.pos, cbc.buf);
        return 64;
    }
    if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
        return 128;
    return 0;
}
开发者ID:dcolish,项目名称:restpose,代码行数:61,代码来源:daemontest_large_put.c


示例3: test

int test(char *URL)
{
  int res;
  CURL *curl;
  int counter=0;
  CURLM *m = NULL;
  int running=1;
  struct timeval mp_start;
  char mp_timedout = FALSE;

  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
    fprintf(stderr, "curl_global_init() failed\n");
    return TEST_ERR_MAJOR_BAD;
  }

  if ((curl = curl_easy_init()) == NULL) {
    fprintf(stderr, "curl_easy_init() failed\n");
    curl_global_cleanup();
    return TEST_ERR_MAJOR_BAD;
  }

  test_setopt(curl, CURLOPT_URL, URL);
  test_setopt(curl, CURLOPT_VERBOSE, 1L);
  test_setopt(curl, CURLOPT_HEADER, 1L);

  /* read the POST data from a callback */
  test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
  test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
  test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
  test_setopt(curl, CURLOPT_READDATA, &counter);
  /* We CANNOT do the POST fine without setting the size (or choose chunked)! */
  test_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));

  test_setopt(curl, CURLOPT_POST, 1L);
#ifdef CURL_DOES_CONVERSIONS
  /* Convert the POST data to ASCII. */
  test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
#endif
  test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
  test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
  test_setopt(curl, CURLOPT_PROXYAUTH,
                   (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );

  if ((m = curl_multi_init()) == NULL) {
    fprintf(stderr, "curl_multi_init() failed\n");
    curl_easy_cleanup(curl);
    curl_global_cleanup();
    return TEST_ERR_MAJOR_BAD;
  }

  if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) {
    fprintf(stderr, "curl_multi_add_handle() failed, "
            "with code %d\n", res);
    curl_multi_cleanup(m);
    curl_easy_cleanup(curl);
    curl_global_cleanup();
    return TEST_ERR_MAJOR_BAD;
  }

  mp_timedout = FALSE;
  mp_start = tutil_tvnow();

  while (running) {
    res = (int)curl_multi_perform(m, &running);
    if (tutil_tvdiff(tutil_tvnow(), mp_start) >
        MULTI_PERFORM_HANG_TIMEOUT) {
      mp_timedout = TRUE;
      break;
    }
#ifdef TPF
    sleep(1); /* avoid ctl-10 dump */
#endif
    if (running <= 0) {
      fprintf(stderr, "nothing left running.\n");
      break;
    }
  }

  if (mp_timedout) {
    if (mp_timedout) fprintf(stderr, "mp_timedout\n");
    fprintf(stderr, "ABORTING TEST, since it seems "
            "that it would have run forever.\n");
    res = TEST_ERR_RUNS_FOREVER;
  }

test_cleanup:

  if(m) {
    curl_multi_remove_handle(m, curl);
    curl_multi_cleanup(m);
  }
  curl_easy_cleanup(curl);
  curl_global_cleanup();

  return res;
}
开发者ID:bagobor,项目名称:vs-curl-test,代码行数:96,代码来源:lib555.c


示例4: processPostTask

// Process POST Request
KDint processPostTask ( CCHttpRequest* pRequest, write_callback pCallback, KDvoid* pStream, KDint* pResponseCode )
{
    CURLcode  eCode = CURL_LAST;
    CURL*     pCurl = curl_easy_init ( );
    
    do 
	{
        if ( !configureCURL ( pCurl ) )
		{
            break;
        }
        
        // handle custom header data 
        // create curl linked list 
        struct curl_slist*  pHeaders = KD_NULL;
        // get custom header data (if set) 
  		std::vector<std::string>  aHeaders = pRequest->getHeaders ( );
  		if ( !aHeaders.empty ( ) )
  		{      			
    		for ( std::vector<std::string>::iterator it = aHeaders.begin ( ); it != aHeaders.end ( ); it++ )
    		{
				// append custom headers one by one 
      			pHeaders = curl_slist_append ( pHeaders, it->c_str ( ) );
    		}
			
			// set custom headers for curl 
    		eCode = curl_easy_setopt ( pCurl, CURLOPT_HTTPHEADER, pHeaders );
    		if ( eCode != CURLE_OK )
			{
      			break;
    		}
  		}
              
        eCode = curl_easy_setopt ( pCurl, CURLOPT_URL, pRequest->getUrl ( ) );
        if ( eCode != CURLE_OK ) 
		{
            break;
        }

        eCode = curl_easy_setopt ( pCurl, CURLOPT_WRITEFUNCTION, pCallback );
        if ( eCode != CURLE_OK ) 
		{
            break;
        }

        eCode = curl_easy_setopt ( pCurl, CURLOPT_WRITEDATA, pStream );
        if ( eCode != CURLE_OK ) 
		{
            break;
        }

        eCode = curl_easy_setopt ( pCurl, CURLOPT_POST, 1 );
        if ( eCode != CURLE_OK ) 
		{
            break;
        }

        eCode = curl_easy_setopt ( pCurl, CURLOPT_POSTFIELDS, pRequest->getRequestData ( ) );
        if ( eCode != CURLE_OK ) 
		{
            break;
        }

        eCode = curl_easy_setopt ( pCurl, CURLOPT_POSTFIELDSIZE, pRequest->getRequestDataSize ( ) );
        if ( eCode != CURLE_OK ) 
		{
            break;
        }

        eCode = curl_easy_perform ( pCurl );
        if ( eCode != CURLE_OK ) 
		{
            break;
        }
        
        // free the linked list for header data 
        curl_slist_free_all ( pHeaders );

        eCode = curl_easy_getinfo ( pCurl, CURLINFO_RESPONSE_CODE, pResponseCode ); 
        if ( eCode != CURLE_OK || *pResponseCode != 200 ) 
		{
            eCode = CURLE_HTTP_RETURNED_ERROR;
        }

    } while ( 0 );

    if ( pCurl )
	{
        curl_easy_cleanup ( pCurl );
    }
    
    return ( eCode == CURLE_OK ? 0 : 1 );    
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:94,代码来源:HttpClient.cpp


示例5: test

int test(char *URL)
{
  CURL *curl;
  CURLcode res = CURLE_OK;
  FILE *hd_src ;
  int hd ;
  struct_stat file_info;
  struct curl_slist *hl;
  int error;

  struct curl_slist *headerlist=NULL;
  const char *buf_1 = "RNFR 505";
  const char *buf_2 = "RNTO 505-forreal";

  if (!libtest_arg2) {
    fprintf(stderr, "Usage: <url> <file-to-upload>\n");
    return -1;
  }

  hd_src = fopen(libtest_arg2, "rb");
  if(NULL == hd_src) {
    error = ERRNO;
    fprintf(stderr, "fopen() failed with error: %d %s\n",
            error, strerror(error));
    fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
    return -2; /* if this happens things are major weird */
  }

  /* get the file size of the local file */
  hd = fstat(fileno(hd_src), &file_info);
  if(hd == -1) {
    /* can't open file, bail out */
    error = ERRNO;
    fprintf(stderr, "fstat() failed with error: %d %s\n",
            error, strerror(error));
    fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2);
    fclose(hd_src);
    return -1;
  }

  if(! file_info.st_size) {
    fprintf(stderr, "ERROR: file %s has zero size!\n", libtest_arg2);
    fclose(hd_src);
    return -4;
  }

  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
    fprintf(stderr, "curl_global_init() failed\n");
    fclose(hd_src);
    return TEST_ERR_MAJOR_BAD;
  }

  /* get a curl handle */
  if ((curl = curl_easy_init()) == NULL) {
    fprintf(stderr, "curl_easy_init() failed\n");
    curl_global_cleanup();
    fclose(hd_src);
    return TEST_ERR_MAJOR_BAD;
  }

  /* build a list of commands to pass to libcurl */

  if ((hl = curl_slist_append(headerlist, buf_1)) == NULL) {
    fprintf(stderr, "curl_slist_append() failed\n");
    curl_easy_cleanup(curl);
    curl_global_cleanup();
    fclose(hd_src);
    return TEST_ERR_MAJOR_BAD;
  }
  if ((headerlist = curl_slist_append(hl, buf_2)) == NULL) {
    fprintf(stderr, "curl_slist_append() failed\n");
    curl_slist_free_all(hl);
    curl_easy_cleanup(curl);
    curl_global_cleanup();
    fclose(hd_src);
    return TEST_ERR_MAJOR_BAD;
  }
  headerlist = hl;

  /* enable uploading */
  test_setopt(curl, CURLOPT_UPLOAD, 1L);

  /* enable verbose */
  test_setopt(curl, CURLOPT_VERBOSE, 1L);

  /* specify target */
  test_setopt(curl,CURLOPT_URL, URL);

  /* pass in that last of FTP commands to run after the transfer */
  test_setopt(curl, CURLOPT_POSTQUOTE, headerlist);

  /* now specify which file to upload */
  test_setopt(curl, CURLOPT_INFILE, hd_src);

  /* and give the size of the upload (optional) */
  test_setopt(curl, CURLOPT_INFILESIZE_LARGE,
                   (curl_off_t)file_info.st_size);

  /* Now run off and do what you've been told! */
  res = curl_easy_perform(curl);
//.........这里部分代码省略.........
开发者ID:1498636925,项目名称:curl,代码行数:101,代码来源:lib505.c


示例6: send_ez_texting


//.........这里部分代码省略.........
	zbx_snprintf(postfields, sizeof(postfields), "user=%s&pass=%s&phonenumber=%s&subject=&message=%s",
			username_esc, password_esc, sendto_esc, message_esc);

	if (CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_USERAGENT, "Zabbix " ZABBIX_VERSION)) ||
			CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_FOLLOWLOCATION, 1L)) ||
			CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_WRITEFUNCTION, WRITEFUNCTION2)) ||
			CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_HEADERFUNCTION, HEADERFUNCTION2)) ||
			CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_SSL_VERIFYPEER, 1L)) ||
			CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_SSL_VERIFYHOST, 2L)) ||
			CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_POSTFIELDS, postfields)) ||
			CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_POST, 1L)) ||
			CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_URL, EZ_TEXTING_API_URL)) ||
			CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_TIMEOUT, (long)EZ_TEXTING_TIMEOUT)))
	{
		zbx_snprintf(error, max_error_len, "Could not set cURL option %d: [%s]", opt, curl_easy_strerror(err));
		goto clean;
	}

	if (NULL != CONFIG_SOURCE_IP)
	{
		if (CURLE_OK != (err = curl_easy_setopt(easy_handle, opt = CURLOPT_INTERFACE, CONFIG_SOURCE_IP)))
		{
			zbx_snprintf(error, max_error_len, "Could not set cURL option %d: [%s]",
					opt, curl_easy_strerror(err));
			goto clean;
		}
	}

	if (CURLE_OK != (err = curl_easy_perform(easy_handle)))
	{
		zbx_snprintf(error, max_error_len, "Error doing curl_easy_perform(): [%s]", curl_easy_strerror(err));
		goto clean;
	}

	/* parse the response */

	if (NULL == page.data || FAIL == is_int_prefix(page.data))
	{
		zbx_snprintf(error, max_error_len, "Did not receive a proper response: [%s]", ZBX_NULL2STR(page.data));
		goto clean;
	}

	switch (atoi(page.data))
	{
		case 1:
			ret = SUCCEED;
			break;
		case -1:
			zbx_snprintf(error, max_error_len, "Invalid user and/or password or API is not allowed");
			break;
		case -2:
			zbx_snprintf(error, max_error_len, "Credit limit reached");
			break;
		case -5:
			zbx_snprintf(error, max_error_len, "Locally opted out phone number");
			break;
		case -7:
			zbx_snprintf(error, max_error_len, "Message too long or contains invalid characters");
			break;
		case -104:
			zbx_snprintf(error, max_error_len, "Globally opted out phone number");
			break;
		case -106:
			zbx_snprintf(error, max_error_len, "Incorrectly formatted phone number");
			break;
		case -10:
			zbx_snprintf(error, max_error_len, "Unknown error (please contact Ez Texting)");
			break;
		default:
			zbx_snprintf(error, max_error_len, "Unknown return value: [%s]", page.data);
			break;
	}
clean:
	if (NULL != message_ascii)
		zbx_free(message_ascii);
	if (NULL != sendto_digits)
		zbx_free(sendto_digits);
	if (NULL != username_esc)
		zbx_free(username_esc);
	if (NULL != password_esc)
		zbx_free(password_esc);
	if (NULL != sendto_esc)
		zbx_free(sendto_esc);
	if (NULL != message_esc)
		zbx_free(message_esc);
	if (NULL != page.data)
		zbx_free(page.data);
	if (NULL != easy_handle)
		curl_easy_cleanup(easy_handle);

	zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret));

	return ret;

#else
	zbx_snprintf(error, max_error_len, "cURL library is required for Ez Texting support");
	return FAIL;

#endif	/* HAVE_LIBCURL */
}
开发者ID:HenryGeek,项目名称:auto_deploy,代码行数:101,代码来源:eztexting.c


示例7: curl_slist_append

bool SMTPClient::SendEmail()
{
	if (m_From.size()==0)
		return false;
	if (m_Recipients.size()==0)
		return false;
	if (m_Server.size()==0)
		return false;

	const std::string rmessage=MakeMessage();

	CURLcode ret;
	struct curl_slist *slist1;

	smtp_upload_status smtp_ctx;
	smtp_ctx.bytes_read=0;

	slist1 = NULL;


	std::vector<std::string>::const_iterator itt;
	for (itt=m_Recipients.begin(); itt!=m_Recipients.end(); ++itt)
	{
		slist1 = curl_slist_append(slist1, (*itt).c_str());
	}

	std::stringstream sstr;
	sstr << "smtp://" << m_Server << ":" << m_Port;
	std::string szURL=sstr.str();//"smtp://"+MailServer;

	try
	{
		CURL *curl;
		curl = curl_easy_init();

		curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);

		curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)177);
		curl_easy_setopt(curl, CURLOPT_URL, szURL.c_str());
		curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
		if (m_Username!="")
		{
			//std::string szUserPassword=MailUsername+":"+MailPassword;
			//curl_easy_setopt(curl, CURLOPT_USERPWD, szUserPassword.c_str());
			curl_easy_setopt(curl, CURLOPT_USERNAME, m_Username.c_str());
			curl_easy_setopt(curl, CURLOPT_PASSWORD, m_Password.c_str());
		}
		curl_easy_setopt(curl, CURLOPT_USERAGENT, "domoticz/7.26.0");
		curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
		curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_TRY);//CURLUSESSL_ALL);
		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
		curl_easy_setopt(curl, CURLOPT_SSLVERSION, 0L);
		curl_easy_setopt(curl, CURLOPT_SSL_SESSIONID_CACHE, 0L);
		curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);

		//curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
		curl_easy_setopt(curl, CURLOPT_MAIL_FROM, m_From.c_str());
		curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, slist1);

		smtp_ctx.pDataBytes=new char[rmessage.size()];
		if (smtp_ctx.pDataBytes==NULL)
		{
			_log.Log(LOG_ERROR,"SMTP Mailer: Out of Memory!");

			curl_easy_cleanup(curl);
			curl_slist_free_all(slist1);
			return false;
		}
		smtp_ctx.sDataLength=rmessage.size();
		memcpy(smtp_ctx.pDataBytes,rmessage.c_str(),smtp_ctx.sDataLength);

		curl_easy_setopt(curl, CURLOPT_READFUNCTION, smtp_payload_reader);
		curl_easy_setopt(curl, CURLOPT_READDATA, &smtp_ctx);

		ret = curl_easy_perform(curl);

		curl_easy_cleanup(curl);
		curl_slist_free_all(slist1);
		delete [] smtp_ctx.pDataBytes;

		if (ret!=CURLE_OK)
		{
			_log.Log(LOG_ERROR,"SMTP Mailer: Error sending Email to: %s !",m_Recipients[0].c_str());
			return false;
		}
	}
	catch (...)
	{
		_log.Log(LOG_ERROR,"SMTP Mailer: Error sending Email to: %s !",m_Recipients[0].c_str());
		return false;
	}
	return true;
}
开发者ID:SjanPjer,项目名称:domoticz,代码行数:94,代码来源:SMTPClient.cpp


示例8: curl_http_head

int curl_http_head(struct response_head *headinfo, const char * remotepath, const char * referer,const char * cookie)
{
	long timeout = 60;
	long connect_timeout = 30;
	headinfo->size = -1;
	headinfo->last_modified = -1;

	CURL *curl = curl_easy_init();
	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // for thread safe
	curl_easy_setopt(curl, CURLOPT_URL, remotepath);
	if(referer) curl_easy_setopt(curl, CURLOPT_REFERER, referer);
	if(cookie)  curl_easy_setopt(curl, CURLOPT_COOKIE, cookie);
	curl_easy_setopt(curl, CURLOPT_USERAGENT, "icache");
	curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, connect_timeout);
	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 10L);
	curl_easy_setopt(curl, CURLOPT_FILETIME, 1);
	curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
	CURLcode rc = curl_easy_perform(curl);
	long response_code;
	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
	if ((rc==CURLE_OK && (response_code==405 || response_code==400 || response_code==403)) || rc==CURLE_GOT_NOTHING || rc==CURLE_OPERATION_TIMEDOUT){
		int last_head = 0;
		curl_easy_cleanup(curl);
        char temp_path[] = "/tmp/tmp_XXXXXX";
        int fd = mkstemp(temp_path);
        if (fd!=-1) close(fd);
		FILE *fp = fopen(temp_path, "w");
		curl = curl_easy_init();
		curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); //for thread safe
		curl_easy_setopt(curl, CURLOPT_URL, remotepath);
		if(referer) curl_easy_setopt(curl, CURLOPT_REFERER, referer);
		if(cookie)  curl_easy_setopt(curl, CURLOPT_COOKIE, cookie);
		curl_easy_setopt(curl, CURLOPT_USERAGENT, "icache");
		curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, connect_timeout);
		curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
		curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
		curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 10L);
		curl_easy_setopt(curl, CURLOPT_FILETIME, 1);
		curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_head);
		curl_easy_setopt(curl, CURLOPT_HEADERDATA, &last_head);
		curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
		rc = curl_easy_perform(curl);
		fclose(fp);
		unlink(temp_path);
		curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
	}
	if ((rc==CURLE_OK || rc==CURLE_WRITE_ERROR) && response_code==200){
		double len;
		curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &len);
		headinfo->size = len;
		curl_easy_getinfo(curl, CURLINFO_FILETIME, &headinfo->last_modified);
	}
	curl_easy_cleanup(curl);
	if (headinfo->last_modified == -1) headinfo->last_modified = 0;
	if (headinfo->size!=-1){
		return 1;
	}else {
		return 0;
	}
}
开发者ID:qqmcc,项目名称:webscan,代码行数:62,代码来源:http.c


示例9: curl_http_header

//int curl_http_header(char *url_live, http_payload_t *http_payload, int *flag)
int curl_http_header(char *url_live, http_payload_t *host_url, http_payload_t *http_payload, int *flag)
{
	CURL *curl_handle;
	
	char *redirect_url;
	//int response_code;
	long response_code;

	//http_payload_t *chunk = http_payload;
	http_payload_t *chunk = host_url;

	/* FIXME  may cause memory lost
	 * if http_payload->memory already has a memory, the free job must 
	 * give to the pointer which it give to */
	chunk->memory = malloc(1);  	/* will be grown as needed by the realloc above */
	chunk->size = 0;    			/* no data at this point */
	
	//hls_dbg("[curl get request]===>%s\n", url_live);

	/* FIXME 
	 * QQTV's source do not support HTTP HEAD/ request, so we must request HTTP GET/
	 * but in curl_http_header(), we do not send http body out */
	//http_payload_t body_duty;
	//body_duty.memory = malloc(1);
	//body_duty.size = 0;
	http_payload_t *chunk1 = http_payload;
	chunk1->memory = malloc(1);
	chunk1->size = 0;	

	//curl_global_init(CURL_GLOBAL_ALL);

	/* init the curl session */
	curl_handle = curl_easy_init();

	/* specify URL to get */
	curl_easy_setopt(curl_handle, CURLOPT_URL, url_live);
	
	/* do not download body */
	//curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
	
	/* FIXME we need get the rederection url, so not do it here */
	//curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);

	/* send all data to this function  */
	curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);

	/* we pass our 'chunk' struct to the callback function */
	//curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&body_duty);
	curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)chunk1);
	
	/* add http GET/ range context */
	curl_easy_setopt(curl_handle, CURLOPT_RANGE,"0-");
	
	/* some servers don't like requests that are made without a user-agent
     * field, so we provide one */
	curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
	
	//curl_easy_setopt(curl_handle, CURLOPT_FORBID_REUSE, 1);

	/* some servers don't like requests that are made without a user-agent
	   field, so we provide one */
	//curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");

	/* this fun will not return until the http payload is all download */
	curl_easy_perform(curl_handle);
	
	/* get http response code */
	curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &response_code);
	//hls_dbg("response_code = %d\n", response_code);
	
	/* for QQTV souct, release the body_duty.memory, do not send data out */
	//free(body_duty.memory);
	
	if (response_code == HLS_REDIRECT) {
		/* get redirect_url 2013-01-19 */
		curl_easy_getinfo(curl_handle, CURLINFO_REDIRECT_URL, &redirect_url);
		hls_dbg("redirect_url >>> %s\n", redirect_url);
		
		chunk->memory = realloc(chunk->memory, strlen(redirect_url) + 1);
		if (chunk->memory == NULL) {
			/* out of memory! */
			hls_err("not enough memory (realloc returned NULL)\n");
			exit(EXIT_FAILURE);
		}

		memcpy(&(chunk->memory[chunk->size]), redirect_url, strlen(redirect_url));
		chunk->size += strlen(redirect_url);
		chunk->memory[chunk->size] = 0;
		
		*flag = HLS_REDIRECT;
	} //else if (response_code != 200)
		//*flag = 0;

	/* cleanup curl stuff */
	curl_easy_cleanup(curl_handle);

	/*
	 * Now, our chunk.memory points to a memory block that is chunk.size
	 * bytes big and contains the remote file.
//.........这里部分代码省略.........
开发者ID:awesomeleo,项目名称:hls_proxy,代码行数:101,代码来源:curl_live.c


示例10: curl_post_form

char* curl_post_form(const char *url,\
	                 const char *postdata,\
	                 const char *proxy,\
	                 const char *cookie,\
	                 int flag_cookie)


{
   long timeout = 10800;
	long connect_timeout = 15;
	long low_speed_limit = 1024;
	long low_speed_time = 60;

	struct mem_node *mem_head = NULL;
	long response_code;
   CURL *curl = curl_easy_init();
   curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // for thread safe
   curl_easy_setopt(curl,CURLOPT_URL,url); //url地址  
   curl_easy_setopt(curl,CURLOPT_POSTFIELDS,postdata); //post参数  
   curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, connect_timeout);
	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
	curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, low_speed_limit);
	curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, low_speed_time);
   curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,&curl_read); //对返回的数据进行操作的函数地址  
   curl_easy_setopt(curl,CURLOPT_WRITEDATA,&mem_head); //这是write_data的第四个参数值  
   curl_easy_setopt(curl,CURLOPT_POST,1); //设置非0表示本次操作为post   
   curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,1); //设置为非0,响应头信息location  
   if(flag_cookie)
   {
    curl_easy_setopt(curl,CURLOPT_COOKIEFILE,"./cookie.txt");
     curl_easy_setopt(curl,CURLOPT_COOKIEJAR,"./cookie.txt");
 }
  // curl_easy_setopt(easy_handle, CURLOPT_PROXY,proxy);
   CURLcode rc = curl_easy_perform(curl); 
  	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
	curl_easy_cleanup(curl);
	if (rc!=CURLE_OK) {
		return NULL;
	}else if (response_code!=200 && response_code!=206){
		struct mem_node *p = mem_head;
		while(p){
			struct mem_node *q = p;
			p = p->next;
			free(q->buffer);
			free(q);
		}
		return NULL;
	}else{
		struct mem_node *p = mem_head;
		size_t size = 0;
		while(p){
			size += p->size;
			p = p->next;
		}
		char *content = (char*)malloc(size+1);
		p = mem_head;
		size = 0;
		while(p){
			memcpy(content+size, p->buffer, p->size);
			size += p->size;
			struct mem_node *q = p;
			p = p->next;
			free(q->buffer);
			free(q);
		}
		content[size] = 0;
		return content;
	}
  
}
开发者ID:qqmcc,项目名称:webscan,代码行数:70,代码来源:http.c


示例11: curl_http_content

char* curl_http_content(const char *uri ,int flag_cookie)
{
	long timeout = 10800;
	long connect_timeout = 15;
	long low_speed_limit = 1024;
	long low_speed_time = 60;

	struct mem_node *mem_head = NULL;
	long response_code;
	CURL *curl = curl_easy_init();
	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // for thread safe
	curl_easy_setopt(curl, CURLOPT_URL, uri);
	curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, connect_timeout);
	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
	curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, low_speed_limit);
	curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, low_speed_time);
	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 10L);
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curl_read);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &mem_head);
	if(flag_cookie)
	{
	 curl_easy_setopt(curl,CURLOPT_COOKIEFILE,"./cookie.txt");
    curl_easy_setopt(curl,CURLOPT_COOKIEJAR,"./cookie.txt");
    }
	CURLcode rc = curl_easy_perform(curl);
	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
	curl_easy_cleanup(curl);

	if (rc!=CURLE_OK) {
		return NULL;
	}else if (response_code!=200 && response_code!=206){
		struct mem_node *p = mem_head;
		while(p){
			struct mem_node *q = p;
			p = p->next;
			free(q->buffer);
			free(q);
		}
		return NULL;
	}else{
		struct mem_node *p = mem_head;
		size_t size = 0;
		while(p){
			size += p->size;
			p = p->next;
		}
		char *content = (char*)malloc(size+1);
		p = mem_head;
		size = 0;
		while(p){
			memcpy(content+size, p->buffer, p->size);
			size += p->size;
			struct mem_node *q = p;
			p = p->next;
			free(q->buffer);
			free(q);
		}
		content[size] = 0;
		return content;
	}
}
开发者ID:qqmcc,项目名称:webscan,代码行数:62,代码来源:http.c


示例12: curl_http_file

int curl_http_file(const char * localpath, const char * remotepath, const char * referer,const char *cookie)
{
	long timeout = 10800;
	long connect_timeout = 30;
	long low_speed_limit = 1024;
	long low_speed_time = 60;

	FILE *fp;
	if (!(fp=fopen(localpath, "wb"))){
		perror(localpath);
		return 0;
	}
	long response_code;
	CURL *curl = curl_easy_init();
	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); //for thread safe
	curl_easy_setopt(curl, CURLOPT_URL, remotepath);
	if(referer) curl_easy_setopt(curl, CURLOPT_REFERER, referer);
	if(cookie)  curl_easy_setopt(curl, CURLOPT_COOKIE, cookie);
	curl_easy_setopt(curl, CURLOPT_USERAGENT, "icache");
	curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, connect_timeout);
	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
	curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, low_speed_limit);
	curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, low_speed_time);
	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 10L);
	curl_easy_setopt(curl, CURLOPT_FILETIME, 1);
	//curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip, deflate");
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
	CURLcode rc = curl_easy_perform(curl);
	curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
	double len = 0;
	long filesize = 0;
	time_t last_modified = 0;
	curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &len);
	filesize = len;
	curl_easy_getinfo(curl, CURLINFO_FILETIME, &last_modified);
	curl_easy_cleanup(curl);
	fclose(fp);

	int success = 1;
	if (rc!=CURLE_OK || response_code!=200) {
		success = 0;
	}else {
		if (filesize!=-1) {
			long localsize = 0;
			struct stat fileinfo;
			if (stat(localpath, &fileinfo) == 0) localsize =  fileinfo.st_size;
			if (filesize!=localsize) success = 0;
		}
	}

	if (success) {
		if (last_modified!=-1){
			struct utimbuf amtime;
			amtime.actime = amtime.modtime = last_modified;
			utime(localpath, &amtime);
		}
		return 1;
	}else{
		unlink(localpath);
		return 0;
	}
}
开发者ID:qqmcc,项目名称:webscan,代码行数:63,代码来源:http.c


示例13: check

CURLcode check(char *response, size_t length, const char *username, const char* password, const char* proxy, int stype) {

	CURL *curl = curl_easy_init();
	if(!curl) {
		fdo_log(GENLOG, "cURL Init Error: (?!)");
		return CURLE_FAILED_INIT; //?!?!?!?!
	}

	struct memstruct CurlStruct;

	CurlStruct.memory = malloc(1);
	*CurlStruct.memory = 0;
	CurlStruct.size = 0;

	//Prepare custom headers.
	char *userenc = curl_easy_escape(curl, username, 0);
	if(!userenc) {
		free(CurlStruct.memory);
		return CURLE_FAILED_INIT;
	}
	char *passenc = curl_easy_escape(curl, password, 0);
	if(!passenc) {
		free(CurlStruct.memory);
		curl_free(passenc); passenc = NULL;
		return CURLE_FAILED_INIT;
	}
	size_t plen = snprintf(NULL, 0, "rem=on&username=%s&password=%s&submit=Log+In&mod=www&ssl=1&dest=account_settings.ws", userenc, passenc);
	plen += 1;
	char *post = malloc(plen);
	if(!post) {
		free(CurlStruct.memory);
		curl_free(userenc); userenc = NULL;
		curl_free(passenc); passenc = NULL;
		return CURLE_FAILED_INIT;
	}
	snprintf(post, plen, "rem=on&username=%s&password=%s&submit=Log+In&mod=www&ssl=1&dest=account_settings.ws", userenc, passenc);

	curl_free(userenc); userenc = NULL;
	curl_free(passenc); passenc = NULL;

	curl_easy_setopt(curl, CURLOPT_URL, "https://secure.runescape.com/m=weblogin/login.ws"); //This may change in the future.
	curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0"); //Possibly change this in the future. They block useragents when they're old(Probably my fault)
	curl_easy_setopt(curl, CURLOPT_REFERER, "https://secure.runescape.com/m=weblogin/loginform.ws?mod=www&ssl=1&reauth=1&dest=account_settings.ws"); //Likewise, may be needed to change.
	curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1); //When followlocation takes place.
	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
	curl_easy_setopt(curl, CURLOPT_HEADER, 0);
	curl_easy_setopt(curl, CURLOPT_ENCODING, "identity");
	curl_easy_setopt(curl, CURLOPT_POST, 1);
	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post);
	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
	curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
	curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
	curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);
	curl_easy_setopt(curl, CURLOPT_PROXYTYPE, stype);
	curl_easy_setopt(curl, CURLOPT_PROXY, proxy);

	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, StoreCurl);
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&CurlStruct);

	CURLcode res = curl_easy_perform(curl);

	if(res != CURLE_OK) {
		fdo_log(DBGLOG, "cURL Error: %s, Proxy: %s.(type: %d)", curl_easy_strerror(res), proxy, stype);
	} else {
		if(CurlStruct.memory != NULL) {
			strncpy(response, CurlStruct.memory, length);
			response[length-1] = '\0';
		} else {
			response = NULL;
		}
	}

	curl_easy_cleanup(curl);
	free(CurlStruct.memory); CurlStruct.memory = NULL;
	free(post); post = NULL;

	return res;
}
开发者ID:MegaManSec,项目名称:RS-Account-Checker,代码行数:80,代码来源:curl.c


示例14: http_query

/* 
 * Performs http_query and saves possible result (first body line of reply)
 * to pvar.
 */
int http_query(struct sip_msg* _m, char* _url, char* _dst, char* _post)
{
    CURL *curl;
    CURLcode res;  
    str value, post_value;
    char *url, *at, *post;
    char* stream;
    long stat;
    pv_spec_t *dst;
    pv_value_t val;
    double download_size;

    if (fixup_get_svalue(_m, (gparam_p)_url, &value) != 0) {
	LM_ERR("cannot get page value\n");
	return -1;
    }

    curl = curl_easy_init();
    if (curl == NULL) {
	LM_ERR("failed to initialize curl\n");
	return -1;
    }

    url = pkg_malloc(value.len + 1);
    if (url == NULL) {
	curl_easy_cleanup(curl);
	LM_ERR("cannot allocate pkg memory for url\n");
	return -1;
    }
    memcpy(url, value.s, value.len);
    *(url + value.len) = (char)0;
    curl_easy_setopt(curl, CURLOPT_URL, url);

    if (_post) {
        /* Now specify we want to POST data */ 
	curl_easy_setopt(curl, CURLOPT_POST, 1L);

    	if (fixup_get_svalue(_m, (gparam_p)_post, &post_value) != 0) {
		LM_ERR("cannot get post value\n");
		pkg_free(url);
		return -1;
    	}
        post = pkg_malloc(post_value.len + 1);
        if (post == NULL) {
		curl_easy_cleanup(curl);
		pkg_free(url);
        	LM_ERR("cannot allocate pkg memory for post\n");
        	return -1;
	}
	memcpy(post, post_value.s, post_value.len);
	*(post + post_value.len) = (char)0;
 	curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post);
    }
       

    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, (long)http_query_timeout);

    stream = NULL;
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);

    res = curl_easy_perform(curl);  
    pkg_free(url);
    if (_post) {
	pkg_free(post);
    }
    curl_easy_cleanup(curl);

    if (res != CURLE_OK) {
	LM_ERR("failed to perform curl\n");
	return -1;
    }

    curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &stat);
    if ((stat >= 200) && (stat < 400)) {
	curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &download_size);
	LM_DBG("http_query download size: %u\n", (unsigned int)download_size);
	/* search for line feed */
	at = memchr(stream, (char)10, download_size);
	if (at == NULL) {
	    /* not found: use whole stream */
	    at = stream + (unsigned int)download_size;
	}
	val.rs.s = stream;
	val.rs.len = at - stream;
	LM_DBG("http)query result: %.*s\n", val.rs.len, val.rs.s);
	val.flags = PV_VAL_STR;
	dst = (pv_spec_t *)_dst;
	dst->setf(_m, &dst->pvp, (int)EQ_T, &val);
    }
	
    return stat;
}
开发者ID:aallamaa,项目名称:kamailio,代码行数:98,代码来源:functions.c


示例15: loginhttp_cookieget

void
loginhttp_cookieget(cearth_logindb *db, const char *user)
{
        int check = logindb_usercheck(db, user); /* You can't trust outside data! */
        switch(check) {
                case 1:
                        break;
                case 0:
                case 2:
                default:
                        return;
        }
        /* Obtain password from stdin */
        char prompt[128] = {0};
        char *password;
        sprintf(prompt, "Password for user '%s': ", user);
        password = getpass("Password: ");
        /* Replace trailing newline with NULL */
        size_t nl = strlen(password) - 1;
        if (password[nl] == '\n')
                password[nl] = '\0';

        CURL *handle = curl_easy_init();

        /* Set up post request */
        char postdata[128] = {0};
        strcat(postdata, "r=/portal/&username=");
        strcat(postdata, user);
        strcat(postdata, "&password=");
        strcat(postdata, password);

        /* Set up HTTP connection */
        char loginurl[LOGIN_URLMAXSIZE] = {0};
        strcat(loginurl, haven_webauth);
        strcat(loginurl, "/portal/sec/login");
        curl_easy_setopt(handle, CURLOPT_URL, loginurl);
        curl_easy_setopt(handle, CURLOPT_POSTFIELDS, postdata);
        curl_easy_setopt(handle, CURLOPT_COOKIEJAR, LOGIN_COOKIEJAR);
        curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
	curl_easy_setopt(handle, CURLOPT_NOBODY, 1);
        curl_easy_setopt(handle, CURLOPT_VERBOSE, 0);
        curl_easy_perform(handle);
        curl_easy_cleanup(handle);

        /* Read cookie if it exists. */
        FILE *fp = fopen(LOGIN_COOKIEJAR, "r");
        if (!fp) {
                perror("cearth_login");
                return;
        }
        char cookie[LOGIN_COOKIESIZE + 1] = {0};
        while(!feof(fp)) {
                char line[LOGINDB_MAXLINE];
                fgets(line, LOGINDB_MAXLINE, fp);
                sscanf(line, "www.havenandhearth.com\tFALSE\t/\tFALSE\t0\thsess\t%s", cookie);
        }

        fclose(fp);
        //remove(LOGIN_COOKIEJAR);

        logindb_cookieset(db, user, cookie);
}
开发者ID:nyanpasu,项目名称:cearth,代码行数:62,代码来源:cearth_login.c


示例16: curl_http_download

/*
 * func for http downloading by libcurl
 */
int curl_http_download(char *url_live, http_payload_t *http_payload)
{
	CURL *curl_handle;
	
	//char *redirect_url;
	//int response_code;

	http_payload_t *chunk = http_payload;

	chunk->memory = malloc(1);  	/* will be grown as needed by the realloc above */
	chunk->size = 0;    			/* no data at this point */

	//curl_global_init(CURL_GLOBAL_ALL);

	/* init the curl session */
	curl_handle = curl_easy_init();

	/* specify URL to get */
	curl_easy_setopt(curl_handle, CURLOPT_URL, url_live);
	
	/* FIXME for LETV's relative url cast 
	 * rederection call curl_http_header(), this fun has rederection inside */
	curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);

	/* send all data to this function  */
	curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);

	/* we pass our 'chunk' struct to the callback function */
	curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)chunk);
	
	/* add http GET/ range context */
	curl_easy_setopt(curl_handle, CURLOPT_RANGE,"0-");
	
	/* some servers don't like requests that are made without a user-agent
     * field, so we provide one */
	curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
	
	//curl_easy_setopt(curl_handle, CURLOPT_FORBID_REUSE, 1);

	/* some servers don't like requests that are made without a user-agent
	   field, so we provide one */
	//curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");

	/* this fun will not return until the http payload is all download */
	curl_easy_perform(curl_handle);

	/* cleanup curl stuff */
	curl_easy_cleanup(curl_handle);

	/*
	 * Now, our chunk.memory points to a memory block that is chunk.size
	 * bytes big and contains the remote file.
	 *
	 * Do something nice with it!
	 *
	 * You should be aware of the fact that at this point we might have an
	 * allocated data block, and nothing has yet deallocated that data. So when
	 * you're done with it, you should free() it as a nice application.
	 */

	//hls_dbg("%lu bytes retrieved\n", (long)chunk->size);

	/* FIXME
	 * modified b 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ curl_easy_escape函数代码示例发布时间:2022-05-30
下一篇:
C++ curcpu函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap