本文整理汇总了C++中curl_slist_append函数的典型用法代码示例。如果您正苦于以下问题:C++ curl_slist_append函数的具体用法?C++ curl_slist_append怎么用?C++ curl_slist_append使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curl_slist_append函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: scep_http_request
/*
* send a SCEP request via HTTP and wait for a response
*/
bool
scep_http_request(const char *url, chunk_t pkcs7, scep_op_t op
, fetch_request_t req_type, chunk_t *response)
{
#ifdef LIBCURL
char errorbuffer[CURL_ERROR_SIZE] = "";
char *complete_url = NULL;
struct curl_slist *headers = NULL;
CURL *curl;
CURLcode res;
/* initialize response */
*response = empty_chunk;
/* initialize curl context */
curl = curl_easy_init();
if (curl == NULL)
{
plog("could not initialize curl context");
return FALSE;
}
if (op == SCEP_PKI_OPERATION)
{
const char operation[] = "PKIOperation";
if (req_type == FETCH_GET)
{
char *escaped_req = escape_http_request(pkcs7);
/* form complete url */
int len = strlen(url) + 20 + strlen(operation) + strlen(escaped_req) + 1;
complete_url = alloc_bytes(len, "complete url");
snprintf(complete_url, len, "%s?operation=%s&message=%s"
, url, operation, escaped_req);
pfreeany(escaped_req);
curl_easy_setopt(curl, CURLOPT_HTTPGET, TRUE);
headers = curl_slist_append(headers, "Pragma:");
headers = curl_slist_append(headers, "Host:");
headers = curl_slist_append(headers, "Accept:");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
}
else /* HTTP_POST */
{
/* form complete url */
int len = strlen(url) + 11 + strlen(operation) + 1;
complete_url = alloc_bytes(len, "complete url");
snprintf(complete_url, len, "%s?operation=%s", url, operation);
curl_easy_setopt(curl, CURLOPT_HTTPGET, FALSE);
headers = curl_slist_append(headers, "Content-Type:");
headers = curl_slist_append(headers, "Expect:");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, pkcs7.ptr);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, pkcs7.len);
}
}
else /* SCEP_GET_CA_CERT */
{
const char operation[] = "GetCACert";
/* form complete url */
int len = strlen(url) + 32 + strlen(operation) + 1;
complete_url = alloc_bytes(len, "complete url");
snprintf(complete_url, len, "%s?operation=%s&message=CAIdentifier"
, url, operation);
curl_easy_setopt(curl, CURLOPT_HTTPGET, TRUE);
}
curl_easy_setopt(curl, CURLOPT_URL, complete_url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_buffer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)response);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorbuffer);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, TRUE);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, FETCH_CMD_TIMEOUT);
DBG(DBG_CONTROL,
DBG_log("sending scep request to '%s'", url)
)
res = curl_easy_perform(curl);
if (res == CURLE_OK)
{
DBG(DBG_CONTROL,
DBG_log("received scep response")
)
DBG(DBG_RAW,
DBG_dump_chunk("SCEP response:\n", *response)
)
}
else
//.........这里部分代码省略.........
开发者ID:KrisChaplin,项目名称:LRT2x4_v1.0.2.06_GPL_source,代码行数:101,代码来源:scep.c
示例2: osm_traces_upload_file
/*
* Upload a file
* returns a basic status:
* < 0 : curl error
* == 0 : OK
* > 0 : HTTP error
*/
static gint osm_traces_upload_file(const char *user,
const char *password,
const char *file,
const char *filename,
const char *description,
const char *tags,
const OsmTraceVis_t *vistype)
{
CURL *curl;
CURLcode res;
char curl_error_buffer[CURL_ERROR_SIZE];
struct curl_slist *headers = NULL;
struct curl_httppost *post=NULL;
struct curl_httppost *last=NULL;
char *base_url = "http://www.openstreetmap.org/api/0.6/gpx/create";
gchar *user_pass = osm_get_login();
gint result = 0; // Default to it worked!
g_debug("%s: %s %s %s %s %s %s", __FUNCTION__,
user, password, file, filename, description, tags);
/* Init CURL */
curl = curl_easy_init();
/* Filling the form */
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "description",
CURLFORM_COPYCONTENTS, description, CURLFORM_END);
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "tags",
CURLFORM_COPYCONTENTS, tags, CURLFORM_END);
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "visibility",
CURLFORM_COPYCONTENTS, vistype->apistr, CURLFORM_END);
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "file",
CURLFORM_FILE, file,
CURLFORM_FILENAME, filename,
CURLFORM_CONTENTTYPE, "text/xml", CURLFORM_END);
/* Prepare request */
/* As explained in http://wiki.openstreetmap.org/index.php/User:LA2 */
/* Expect: header seems to produce incompatibilites between curl and httpd */
headers = curl_slist_append(headers, "Expect: ");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
curl_easy_setopt(curl, CURLOPT_URL, base_url);
curl_easy_setopt(curl, CURLOPT_USERPWD, user_pass);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer);
if (vik_verbose)
curl_easy_setopt ( curl, CURLOPT_VERBOSE, 1 );
/* Execute request */
res = curl_easy_perform(curl);
if (res == CURLE_OK)
{
long code;
res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code);
if (res == CURLE_OK)
{
g_debug("received valid curl response: %ld", code);
if (code != 200) {
g_warning(_("failed to upload data: HTTP response is %ld"), code);
result = code;
}
}
else {
g_critical(_("curl_easy_getinfo failed: %d"), res);
result = -1;
}
}
else {
g_warning(_("curl request failed: %s"), curl_error_buffer);
result = -2;
}
/* Memory */
g_free(user_pass); user_pass = NULL;
curl_formfree(post);
curl_easy_cleanup(curl);
return result;
}
开发者ID:idaohang,项目名称:viking,代码行数:94,代码来源:osm-traces.c
示例3: curl_slist_append
void LLCurl::Easy::slist_append(const char* str)
{
mHeaders = curl_slist_append(mHeaders, str);
}
开发者ID:OS-Development,项目名称:VW.Zen,代码行数:4,代码来源:llcurl.cpp
示例4: http_network_send_data
static ae_error_t http_network_send_data(CURL *curl, const char *req_msg, uint32_t msg_size, char **resp_msg, uint32_t& resp_size, http_methods_t method, bool is_ocsp)
{
AESM_DBG_TRACE("send data method=%d",method);
struct curl_slist *headers=NULL;
struct curl_slist *tmp=NULL;
ae_error_t ae_ret = AE_SUCCESS;
CURLcode cc=CURLE_OK;
int num_bytes = 0;
if(is_ocsp){
tmp = curl_slist_append(headers, "Accept: application/ocsp-response");
if(tmp==NULL){
AESM_DBG_ERROR("fail in add accept ocsp-response header");
ae_ret = AE_FAILURE;
goto fini;
}
headers = tmp;
tmp = curl_slist_append(headers, "Content-Type: application/ocsp-request");
if(tmp == NULL){
AESM_DBG_ERROR("fail in add content type ocsp-request");
ae_ret = AE_FAILURE;
goto fini;
}
headers=tmp;
AESM_DBG_TRACE("ocsp request");
}
char buf[50];
num_bytes = snprintf(buf,sizeof(buf), "Content-Length: %u", (unsigned int)msg_size);
if(num_bytes<0 || num_bytes>=sizeof(buf)){
AESM_DBG_ERROR("fail to prepare string Content-Length");
ae_ret = AE_FAILURE;
goto fini;
}
tmp = curl_slist_append(headers, buf);
if(tmp == NULL){
AESM_DBG_ERROR("fail to add content-length header");
ae_ret = AE_FAILURE;
goto fini;
}
headers=tmp;
if((cc=curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers))!=CURLE_OK){
AESM_DBG_ERROR("fail to set http header:%d",(int)cc);
ae_ret = AE_FAILURE;
goto fini;
}
if(method == POST){
if((cc=curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req_msg))!=CURLE_OK){
AESM_DBG_ERROR("fail to set POST fields:%d",(int)cc);
ae_ret = AE_FAILURE;
goto fini;
}
if((cc=curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, msg_size))!=CURLE_OK){
AESM_DBG_ERROR("fail to set POST fields size:%d",(int)cc);
ae_ret = AE_FAILURE;
goto fini;
}
}
if((cc=curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback))!=CURLE_OK){
AESM_DBG_ERROR("Fail to set callback function:%d",(int)cc);
ae_ret = AE_FAILURE;
goto fini;
}
network_malloc_info_t malloc_info;
malloc_info.base=NULL;
malloc_info.size = 0;
if((cc=curl_easy_setopt(curl, CURLOPT_WRITEDATA, reinterpret_cast<void *>(&malloc_info)))!=CURLE_OK){
AESM_DBG_ERROR("fail to set write back function parameter:%d",(int)cc);
ae_ret = AE_FAILURE;
goto fini;
}
if((cc=curl_easy_perform(curl))!=CURLE_OK){
if(malloc_info.base){
free(malloc_info.base);
}
AESM_DBG_ERROR("fail in connect:%d",(int)cc);
ae_ret = OAL_NETWORK_UNAVAILABLE_ERROR;
goto fini;
}
*resp_msg = malloc_info.base;
resp_size = malloc_info.size;
AESM_DBG_TRACE("get response size=%d",resp_size);
ae_ret = AE_SUCCESS;
fini:
if(headers!=NULL){
curl_slist_free_all(headers);
}
return ae_ret;
}
开发者ID:andyzyb,项目名称:linux-sgx,代码行数:88,代码来源:aesm_http_msg.cpp
示例5: test
int test(char *URL)
{
CURLcode res;
CURL *curl;
char *newURL;
struct curl_slist *slist;
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;
}
/*
* Begin with cURL set to use a single CWD to the URL's directory.
*/
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD);
res = curl_easy_perform(curl);
/*
* Change the FTP_FILEMETHOD option to use full paths rather than a CWD
* command. Alter the URL's path a bit, appending a "./". Use an innocuous
* QUOTE command, after which cURL will CWD to ftp_conn->entrypath and then
* (on the next call to ftp_statemach_act) find a non-zero ftpconn->dirdepth
* even though no directories are stored in the ftpconn->dirs array (after a
* call to freedirs).
*/
newURL = malloc(strlen(URL) + 3);
if (newURL == NULL) {
curl_easy_cleanup(curl);
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
newURL = strcat(strcpy(newURL, URL), "./");
slist = curl_slist_append (NULL, "SYST");
if (slist == NULL) {
free(newURL);
curl_easy_cleanup(curl);
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
curl_easy_setopt(curl, CURLOPT_URL, newURL);
curl_easy_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD);
curl_easy_setopt(curl, CURLOPT_QUOTE, slist);
res = curl_easy_perform(curl);
curl_slist_free_all(slist);
free(newURL);
curl_easy_cleanup(curl);
curl_global_cleanup();
return (int)res;
}
开发者ID:WiseMan787,项目名称:ralink_sdk,代码行数:64,代码来源:lib539.c
示例6: send_request
static int send_request(char *method, const char *path, FILE *fp, xmlParserCtxtPtr xmlctx, curl_slist *extra_headers)
{
long response = -1;
int tries = 0;
// retry on failures
for (tries = 0; tries < REQUEST_RETRIES; tries++)
{
CURL *curl = get_connection(path);
curl_slist *headers = NULL;
add_header(&headers, "X-Auth-Token", storage_token);
curl_easy_setopt(curl, CURLOPT_VERBOSE, debug);
if (!strcasecmp(method, "MKDIR"))
{
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, 0);
add_header(&headers, "Content-Type", "application/directory");
}
else if (!strcasecmp(method, "PUT") && fp)
{
rewind(fp);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_size(fileno(fp)));
curl_easy_setopt(curl, CURLOPT_READDATA, fp);
}
else if (!strcasecmp(method, "GET"))
{
if (fp)
{
rewind(fp); // make sure the file is ready for a-writin'
fflush(fp);
ftruncate(fileno(fp), 0);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
}
else if (xmlctx)
{
curl_easy_setopt(curl, CURLOPT_WRITEDATA, xmlctx);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &xml_dispatch);
}
}
else
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, method);
/* add the headers from extra_headers if any */
curl_slist *extra;
for (extra = extra_headers; extra; extra = extra->next)
{
debugf("adding header: %s", extra->data);
headers = curl_slist_append(headers, extra->data);
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
curl_slist_free_all(headers);
return_connection(curl);
if (response >= 200 && response < 400)
return response;
sleep(8 << tries); // backoff
if (response == 401 && !cloudfs_connect(0, 0, 0, 0)) // re-authenticate on 401s
return response;
if (xmlctx)
xmlCtxtResetPush(xmlctx, NULL, 0, NULL, NULL);
}
return response;
}
开发者ID:abs0,项目名称:cloudfuse,代码行数:64,代码来源:cloudfsapi.c
示例7: _sendHttpMessage
static void * _sendHttpMessage()
{
pthread_mutex_lock(&mutexHttpSendThreadControl);
while (NULL != _httpMessageBeingSent)
{
// ---------------------------------------------------------------------------
// Set the limit of the message to send
// ---------------------------------------------------------------------------
#ifdef X86
curl_easy_setopt(_sessionHandle, CURLOPT_POSTFIELDSIZE_LARGE, strlen(_httpMessageBeingSent) );
#else
curl_easy_setopt(_sessionHandle, CURLOPT_POSTFIELDSIZE, strlen(_httpMessageBeingSent) );
#endif
// Set the relevant Content-type (No Content-type for 0 size data message)
if(NULL != _slist) {
// Free the list
curl_slist_free_all(_slist); /* free the list - List used to define the HTTP Content Type */
_slist=NULL;
}
if(0 == strlen(_httpMessageBeingSent)) {
DBG("Set empty HTTP Content-type");
_slist = curl_slist_append(_slist, HttpEmptyContentType);
} else {
DBG("Set XML HTTP Content-type");
_slist = curl_slist_append(_slist, HttpXmlContentType);
}
curl_easy_setopt(_sessionHandle, CURLOPT_HTTPHEADER, _slist);
// ---------------------------------------------------------------------------
// Fill the data to send
// ---------------------------------------------------------------------------
curl_easy_setopt( _sessionHandle, CURLOPT_POSTFIELDS, _httpMessageBeingSent );
INFO("HTTP Message to send:\n%s", _httpMessageBeingSent);
pthread_mutex_unlock(&mutexHttpSendThreadControl);
if ( curl_easy_perform( _sessionHandle ) == 0 ) {
INFO("HTTP Message sent");
} else {
WARN("HTTP Message Not Sent");
}
pthread_mutex_lock(&mutexHttpSendThreadControl);
// Free and set to NULL the _httpMessageBeingSent
DM_ENG_FREE(_httpMessageBeingSent);
_httpMessageBeingSent = _getFirstPendingHttpMessage();
} // end if(NULL != _httpMessageBeingSent)
if(_closeHttpSessionExpected)
{
_CloseHttpSession(NORMAL_CLOSE);
}
pthread_mutex_unlock(&mutexHttpSendThreadControl);
// Quit the current thread
pthread_exit(DM_OK);
}
开发者ID:Orange-OpenSource,项目名称:tr069agent,代码行数:64,代码来源:DM_COM_HttpClientInterface.c
示例8: main
int main(void)
{
CURL *curl;
CURLM *mcurl;
int still_running = 1;
struct timeval mp_start;
struct curl_slist *recipients = NULL;
struct upload_status upload_ctx;
upload_ctx.lines_read = 0;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(!curl)
return 1;
mcurl = curl_multi_init();
if(!mcurl)
return 2;
/* This is the URL for your mailserver */
curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com");
/* Note that this option isn't strictly required, omitting it will result in
* libcurl sending the MAIL FROM command with empty sender data. All
* autoresponses should have an empty reverse-path, and should be directed
* to the address in the reverse-path which triggered them. Otherwise, they
* could cause an endless loop. See RFC 5321 Section 4.5.5 for more details.
*/
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);
/* Add two recipients, in this particular case they correspond to the
* To: and Cc: addressees in the header, but they could be any kind of
* recipient. */
recipients = curl_slist_append(recipients, TO);
recipients = curl_slist_append(recipients, CC);
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
/* We're using a callback function to specify the payload (the headers and
* body of the message). You could just use the CURLOPT_READDATA option to
* specify a FILE pointer to read from. */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* Tell the multi stack about our easy handle */
curl_multi_add_handle(mcurl, curl);
/* Record the start time which we can use later */
mp_start = tvnow();
/* We start some action by calling perform right away */
curl_multi_perform(mcurl, &still_running);
while(still_running) {
struct timeval timeout;
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -1;
int rc;
CURLMcode mc; /* curl_multi_fdset() return code */
long curl_timeo = -1;
/* Initialise the file descriptors */
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
/* Set a suitable timeout to play around with */
timeout.tv_sec = 1;
timeout.tv_usec = 0;
curl_multi_timeout(mcurl, &curl_timeo);
if(curl_timeo >= 0) {
timeout.tv_sec = curl_timeo / 1000;
if(timeout.tv_sec > 1)
timeout.tv_sec = 1;
else
timeout.tv_usec = (curl_timeo % 1000) * 1000;
}
/* get file descriptors from the transfers */
mc = curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) {
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break;
}
/* On success the value of maxfd is guaranteed to be >= -1. We call
select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
to sleep 100ms, which is the minimum suggested value in the
curl_multi_fdset() doc. */
if(maxfd == -1) {
#ifdef _WIN32
//.........这里部分代码省略.........
开发者ID:2px,项目名称:curl,代码行数:101,代码来源:smtp-multi.c
示例9: malloc
HttpResponse* HttpClient::post(const wstring& url) {
CURLcode res;
struct MemoryStruct chunk;
chunk.memory = (char*) malloc(1); /* will be grown as needed by the realloc above */
chunk.size = 0; /* no data at this point */
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, wide2char(url.c_str()));
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
/// HEADERS
struct curl_slist *headerList = NULL;
for(std::vector<std::wstring>::iterator it = headers.begin();
it != headers.end();
it++)
{
char* header;
header = wide2char(it->c_str());
headerList = curl_slist_append(headerList, header);
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerList);
/* send all data to this function */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
/* we pass our 'chunk' struct to the callback function */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
/* some servers don't like requests that are made without a user-agent
field, so we provide one */
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
struct curl_httppost* post = NULL;
struct curl_httppost* last = NULL;
wstring params;
for(std::vector<std::pair<std::wstring, std::wstring>>::iterator it = formData.begin();
it != formData.end();
it++) {
//curl_formadd(&post, &last, CURLFORM_COPYNAME, wide2char(it->first.c_str()), CURLFORM_COPYCONTENTS, wide2char(it->second.c_str()), CURLFORM_END);
params += it->first;
params += L"=";
params += it->second;
params += L"&";
}
params = params.substr(0,params.length()-1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, wide2char(params.c_str()));
//curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
} else {
// chunk has data!!
}
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
HttpResponse* response = new HttpResponse();
response->data = chunk;
response->code = res;
return response;
}
开发者ID:ohierro,项目名称:gDrive,代码行数:78,代码来源:HttpClient.cpp
示例10: 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;
}
/* get the file size of the local file */
hd = stat(libtest_arg2, &file_info);
if(hd == -1) {
/* can't open file, bail out */
error = ERRNO;
fprintf(stderr, "stat() failed with error: %d %s\n",
error, strerror(error));
fprintf(stderr, "WARNING: cannot open file %s\n", libtest_arg2);
return -1;
}
if(! file_info.st_size) {
fprintf(stderr, "WARNING: file %s has no size!\n", libtest_arg2);
return -4;
}
/* get a FILE * of the same file, could also be made with
fdopen() from the previous descriptor, but hey this is just
an example! */
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 */
}
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! */
//.........这里部分代码省略.........
开发者ID:499940913,项目名称:moon,代码行数:101,代码来源:lib505.c
示例11: main
int main(void)
{
CURL *curl;
CURLcode res = CURLE_OK;
struct curl_slist *headers = NULL;
struct curl_slist *recipients = NULL;
struct curl_slist *slist = NULL;
curl_mime *mime;
curl_mime *alt;
curl_mimepart *part;
const char **cpp;
curl = curl_easy_init();
if(curl) {
/* This is the URL for your mailserver */
curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com");
/* Note that this option isn't strictly required, omitting it will result
* in libcurl sending the MAIL FROM command with empty sender data. All
* autoresponses should have an empty reverse-path, and should be directed
* to the address in the reverse-path which triggered them. Otherwise,
* they could cause an endless loop. See RFC 5321 Section 4.5.5 for more
* details.
*/
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);
/* Add two recipients, in this particular case they correspond to the
* To: and Cc: addressees in the header, but they could be any kind of
* recipient. */
recipients = curl_slist_append(recipients, TO);
recipients = curl_slist_append(recipients, CC);
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
/* Build and set the message header list. */
for(cpp = headers_text; *cpp; cpp++)
headers = curl_slist_append(headers, *cpp);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
/* Build the mime message. */
mime = curl_mime_init(curl);
/* The inline part is an alternative proposing the html and the text
versions of the e-mail. */
alt = curl_mime_init(curl);
/* HTML message. */
part = curl_mime_addpart(alt);
curl_mime_data(part, inline_html, CURL_ZERO_TERMINATED);
curl_mime_type(part, "text/html");
/* Text message. */
part = curl_mime_addpart(alt);
curl_mime_data(part, inline_text, CURL_ZERO_TERMINATED);
/* Create the inline part. */
part = curl_mime_addpart(mime);
curl_mime_subparts(part, alt);
curl_mime_type(part, "multipart/alternative");
slist = curl_slist_append(NULL, "Content-Disposition: inline");
curl_mime_headers(part, slist, 1);
/* Add the current source program as an attachment. */
part = curl_mime_addpart(mime);
curl_mime_filedata(part, "smtp-mime.c");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
/* Send the message */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* Free lists. */
curl_slist_free_all(recipients);
curl_slist_free_all(headers);
/* curl won't send the QUIT command until you call cleanup, so you should
* be able to re-use this connection for additional messages (setting
* CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT as required, and calling
* curl_easy_perform() again. It may not be a good idea to keep the
* connection open for a very long time though (more than a few minutes
* may result in the server timing out the connection), and you do want to
* clean up in the end.
*/
curl_easy_cleanup(curl);
/* Free multipart message. */
curl_mime_free(mime);
}
return (int)res;
}
开发者ID:Audifire,项目名称:mtasa-blue,代码行数:94,代码来源:smtp-mime.c
示例12: main
int main( int argc, char **argv ) {
CURL *curl;
CURLcode res;
FILE *ftpfile;
FILE * hd_src ;
int hd ;
struct stat file_info;
struct curl_slist *headerlist = NULL;
char buf_1 [] = "RNFR " UPLOAD_FILE_AS;
char buf_2 [] = "RNTO " RENAME_FILE_TO;
/* get the file size of the local file */
hd = open( LOCAL_FILE, O_RDONLY ) ;
fstat( hd, &file_info );
close( hd ) ;
/* get a FILE * of the same file, could also be made with
fdopen() from the previous descriptor, but hey this is just
an example! */
hd_src = fopen( LOCAL_FILE, "rb" );
/* In windows, this will init the winsock stuff */
curl_global_init( CURL_GLOBAL_ALL );
/* get a curl handle */
curl = curl_easy_init();
if ( curl ) {
/* build a list of commands to pass to libcurl */
headerlist = curl_slist_append( headerlist, buf_1 );
headerlist = curl_slist_append( headerlist, buf_2 );
/* enable uploading */
curl_easy_setopt( curl, CURLOPT_UPLOAD, TRUE ) ;
/* specify target */
curl_easy_setopt( curl,CURLOPT_URL, REMOTE_URL );
/* pass in that last of FTP commands to run after the transfer */
curl_easy_setopt( curl, CURLOPT_POSTQUOTE, headerlist );
/* now specify which file to upload */
curl_easy_setopt( curl, CURLOPT_READDATA, hd_src );
/* and give the size of the upload (optional) */
curl_easy_setopt( curl, CURLOPT_INFILESIZE_LARGE, file_info.st_size );
/* Now run off and do what you've been told! */
res = curl_easy_perform( curl );
/* clean up the FTP commands list */
curl_slist_free_all( headerlist );
/* always cleanup */
curl_easy_cleanup( curl );
}
fclose( hd_src ); /* close the local file */
curl_global_cleanup();
return 0;
}
开发者ID:AdrienJaguenet,项目名称:Enemy-Territory,代码行数:61,代码来源:ftpupload.c
示例13: sizeof
void HttpConnection::proxyize(HttpSession *httpSession) {
CurlSession *curlSession;
char fullUrl[2048];
char httpArguments[256];
int *arguments[5];
int *arguments2[5];
int returnCode;
struct timeval sendTimeout;
socklen_t sendTimeoutSize = sizeof(sendTimeout);
int clientSocket;
int httpReturnCode;
char vxferLog[64];
int originServerUrlNumber = 0;
char header = 1;
char data = 0;
struct curl_slist *slist = NULL;
char headerByteRange[64];
char *pChar;
if (httpSession->byteRange.start != -1) {
httpSession->seekPosition = httpSession->byteRange.start;
if (httpSession->byteRange.end != -1)
snprintf(headerByteRange, sizeof(headerByteRange), "Range: bytes=%d-%d", httpSession->byteRange.start, httpSession->byteRange.end);
else
snprintf(headerByteRange, sizeof(headerByteRange), "Range: bytes=%d-", httpSession->byteRange.start);
slist = curl_slist_append(slist, headerByteRange);
}
while (originServerUrlNumber < 16) {
sendTimeout.tv_sec = 30;
sendTimeout.tv_usec = 0;
returnCode = setsockopt(httpSession->httpExchange->getOutput(), SOL_SOCKET, SO_SNDTIMEO, &sendTimeout, sendTimeoutSize);
if (returnCode < 0) {
systemLog->sysLog(ERROR, "cannot setsockopt with SO_SNDTIMEO on socket %d: %s", httpSession->httpExchange->getOutput(), strerror(errno));
clientSocket = httpSession->httpExchange->getOutput();
httpSession->destroy(true);
close(clientSocket);
return;
}
curlSession = curl->createSession();
if (! curlSession) {
clientSocket = httpSession->httpExchange->getOutput();
httpSession->destroy(true);
close(clientSocket);
return;
}
// Add Additional Headers
if (httpSession->byteRange.start != -1)
returnCode = curl->setRequestHeader(curlSession, slist);
// XXX Boundary checking
/*if (httpSession->seekSeconds) {
snprintf(httpArguments, sizeof(httpArguments), "seekseconds=%f", httpSession->seekSeconds);
httpArgumentsPresent = true;
}
if (httpSession->seekPosition) {
snprintf(httpArguments, sizeof(httpArguments), "seek=%d", httpSession->seekPosition);
httpArgumentsPresent = true;
}*/
if (! strstr(httpSession->httpRequest, "getSmil")) {
pChar = strstr(httpSession->httpRequest, "?");
if (pChar) {
snprintf(httpArguments, sizeof(httpArguments), "%s", pChar);
pChar = strstr(httpArguments, " ");
if (pChar)
*pChar = '\0';
snprintf(fullUrl, sizeof(fullUrl), "%s%s%s", configuration->originServerUrl[originServerUrlNumber], httpSession->videoName, httpArguments);
}
else
snprintf(fullUrl, sizeof(fullUrl), "%s%s", configuration->originServerUrl[originServerUrlNumber], httpSession->videoName);
}
else
snprintf(fullUrl, sizeof(fullUrl), "%s", httpSession->httpFullRequest);
arguments[0] = (int *)httpSession;
arguments[1] = (int *)this;
arguments[2] = (int *)curl;
arguments[3] = (int *)curlSession;
arguments[4] = (int *)&data;
arguments2[0] = (int *)httpSession;
arguments2[1] = (int *)this;
arguments2[2] = (int *)curl;
arguments2[3] = (int *)curlSession;
arguments2[4] = (int *)&header;
returnCode = curl->fetchHttpUrlWithCallback(curlSession, (void *)callbackFunctionProxy, (void *)arguments, (void *)callbackFunctionProxy, (void *)arguments2, fullUrl);
if (returnCode < 0) {
curl->deleteSession(curlSession);
delete curlSession;
httpSession->destroy(true);
close(clientSocket);
return;
}
httpReturnCode = curl->getHttpCode(curlSession);
if (httpReturnCode == 200) {
if (httpSession->multicastData) {
unsigned int position;
bool mustLog = false;
//.........这里部分代码省略.........
开发者ID:spebsd,项目名称:numb,代码行数:101,代码来源:httpconnection.cpp
示例14: pool
//.........这里部分代码省略.........
// Set static cURL options
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 1);
std::string bind_address = g_settings->get("bind_address");
if (!bind_address.empty()) {
curl_easy_setopt(curl, CURLOPT_INTERFACE, bind_address.c_str());
}
#if LIBCURL_VERSION_NUM >= 0x071304
// Restrict protocols so that curl vulnerabilities in
// other protocols don't affect us.
// These settings were introduced in curl 7.19.4.
long protocols =
CURLPROTO_HTTP |
CURLPROTO_HTTPS |
CURLPROTO_FTP |
CURLPROTO_FTPS;
curl_easy_setopt(curl, CURLOPT_PROTOCOLS, protocols);
curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS, protocols);
#endif
// Set cURL options based on HTTPFetchRequest
curl_easy_setopt(curl, CURLOPT_URL,
request.url.c_str());
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS,
request.timeout);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS,
request.connect_timeout);
if (request.useragent != "")
curl_easy_setopt(curl, CURLOPT_USERAGENT, request.useragent.c_str());
// Set up a write callback that writes to the
// ostringstream ongoing->oss, unless the data
// is to be discarded
if (request.caller == HTTPFETCH_DISCARD) {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
httpfetch_discardfunction);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL);
} else {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
httpfetch_writefunction);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &oss);
}
// Set POST (or GET) data
if (request.post_fields.empty()) {
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
} else if (request.multipart) {
curl_httppost *last = NULL;
for (StringMap::iterator it = request.post_fields.begin();
it != request.post_fields.end(); ++it) {
curl_formadd(&post, &last,
CURLFORM_NAMELENGTH, it->first.size(),
CURLFORM_PTRNAME, it->first.c_str(),
CURLFORM_CONTENTSLENGTH, it->second.size(),
CURLFORM_PTRCONTENTS, it->second.c_str(),
CURLFORM_END);
}
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
// request.post_fields must now *never* be
// modified until CURLOPT_HTTPPOST is cleared
} else if (request.post_data.empty()) {
curl_easy_setopt(curl, CURLOPT_POST, 1);
std::string str;
for (StringMap::iterator it = request.post_fields.begin();
it != request.post_fields.end(); ++it) {
if (str != "")
str += "&";
str += urlencode(it->first);
str += "=";
str += urlencode(it->second);
}
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,
str.size());
curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS,
str.c_str());
} else {
curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE,
request.post_data.size());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS,
request.post_data.c_str());
// request.post_data must now *never* be
// modified until CURLOPT_POSTFIELDS is cleared
}
// Set additional HTTP headers
for (std::vector<std::string>::iterator it = request.extra_headers.begin();
it != request.extra_headers.end(); ++it) {
http_header = curl_slist_append(http_header, it->c_str());
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, http_header);
if (!g_settings->getBool("curl_verify_cert")) {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
}
}
开发者ID:nikkuang,项目名称:minetest,代码行数:101,代码来源:httpfetch.cpp
示例15: ocs_message_manager_distributor
/**
* @brief [brief description]
* @details [long description]
*/
void* ocs_message_manager_distributor(void* do_not_use)
{
while(1)
{
pthread_mutex_lock(&message_queue_mutex);
while ((ocs_queue_count(message_queue.queue) == 0) && (message_queue.terminate == 0))
{
/* No messages so wait for one. */
pthread_cond_wait(&message_queue.cond, &message_queue_mutex);
}
/* About terminating? */
if (message_queue.terminate != 0)
{
/* About therminating so unlock the mutex and get out of here. */
pthread_mutex_unlock(&message_queue_mutex);
break;
}
if (ocs_queue_count(message_queue.queue) > 0)
{
/* Retrieve one message from the queue. */
char* message = ocs_queue_dequeue(message_queue.queue);
printf("dequeue %s\n", message);
printf("posting %s ...\n", message);
CURL *curl;
CURLcode res;
/* In windows, this will init the winsock stuff */
res = curl_global_init(CURL_GLOBAL_DEFAULT);
/* Check for errors */
if(res != CURLE_OK)
{
fprintf(stderr, "curl_global_init() failed: %s\n", curl_easy_strerror(res));
return(NULL);
}
/* get a curl handle */
curl = curl_easy_init();
if(curl != NULL)
{
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "charsets: utf-8");
/* First set the URL that is about to receive our POST. This URL can
just as well be a https:// URL if that is what should receive the
data. */
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8080");
curl_easy_setopt(curl, CURLOPT_PORT, 80);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POSTT"); /* !!! */
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, message); /* data goes here */
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
}
curl_slist_free_all(headers);
/* always cleanup */
curl_easy_cleanup(curl);
}
curl_global_cleanup();
/* jansson.h library requires the return value of json_dumps to be freed. */
printf("free message (posting thread)\n"); fflush(stdout);
free(message);
/* Finished with lock. */
pthread_mutex_unlock(&message_queue_mutex);
}
else
{
/* Nothing to do so we're finished with the lock. */
pthread_mutex_unlock(&message_queue_mutex);
}
}
pthread_exit(NULL);
}
开发者ID:vialette,项目名称:ocs-c,代码行数:93,代码来源:ocs_message_manager.c
示例16: reset
bool Curl::doPost(const string& url, const rcp::Collection& params, bool multiPart) {
CURLcode r;
struct curl_slist* curl_header = NULL;
struct curl_httppost* post_curr = NULL;
struct curl_httppost* post_last = NULL;
string use_url = url; // @todo make url not const!s
// Make sure userpass/callback is set.
reset();
// Remove the Expect: from header, can give problems... (when you get a 417 error)
static const char buf[] = "Expect:";
curl_header = curl_slist_append(curl_header,buf);
// Add fields to post.
// ------------------------------------------------------
if(!multiPart) {
const list<rcp::Parameter*>& pars = params.getParameters();
string data_str = createQueryString(pars);
r = curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1);
CHECK_CURL_ERROR(r);
r = curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, data_str.c_str());
CHECK_CURL_ERROR(r);
}
else {
// handling a multi part post.
const list<rcp::Parameter*>& post_params = params.getParameters();
list<rcp::Parameter*>::const_iterator it = post_params.begin();
while(it != post_params.end()) {
switch((*it)->type) {
case rcp::Parameter::PARAM_STRING: {
curl_formadd(
&post_curr
,&post_last
,CURLFORM_COPYNAME
,(*it)->getName().c_str()
,CURLFORM_COPYCONTENTS
,(*it)->getStringValue().c_str()
,CURLFORM_END
);
break;
}
case rcp::Parameter::PARAM_FILE: {
curl_formadd(
&post_curr
,&post_last
,CURLFORM_COPYNAME
,(*it)->getName().c_str()
,CURLFORM_FILE
,(*it)->getStringValue().c_str()
,CURLFORM_END
);
break;
}
default: {
printf("error type not handled: %d\n", (*it)->type);
break;
}
}
++it;
}
r = curl_easy_setopt(curl, CURLOPT_HTTPPOST, p
|
请发表评论