/* $Header: /CVSROOT/debris/driscurl.h,v 1.3 2005/08/15 01:04:52 tino Exp $ * * DebRIS: DEBian Remote Install Scripter * CURL fetcher * * $Log: driscurl.h,v $ * Revision 1.3 2005/08/15 01:04:52 tino * all functions now have a prefix (dris_) * * Revision 1.2 2005/07/25 03:21:11 tino * don't know * * Revision 1.1 2005/06/01 02:12:34 tino * first version. As SirbeD is missing, this just does nothing yet. * */ #include "diet/curl/curl.h" #include "diet/curl/easy.h" static int dris_curl_inited; static CURL *dris_curl_hndl; static void dris_curl_init(void) { #ifdef CURLVERSION_NOW curl_version_info_data *data; #endif curl_global_init(CURL_GLOBAL_ALL); #ifdef CURLVERSION_NOW data = curl_version_info(CURLVERSION_NOW); dris_info("using CURL age %d\n", data->age); if (data->age>=0) { dris_info(" version %s, host %s, features %x, ssl %s, libz %s\n", data->version, data->host, data->features, data->ssl_version, data->libz_version); } if (data->age>0) { dris_info(" ares %s", data->ares); if (data->age>1) dris_info(", libidn %s", data->libidn); dris_info("\n"); } #else dris_info("old CURL %s\n", curl_version()); #endif dris_curl_hndl = curl_easy_init(); if (!dris_curl_hndl) dris_ex("cannot get a CURL handle"); dris_curl_inited = 1; } static size_t dris_curl_write(void *ptr, size_t size, size_t nmemb, void *data) { size_t n; n = size*nmemb; dris_buf_add(data, ptr, n); return n; } static int dris_curl(struct dris_buf *in, struct dris_buf *out) { struct curl_httppost *post, *last; int ret; #if 0 struct curl_slist *killhead; #endif if (!dris_curl_inited) dris_curl_init(); curl_easy_reset(dris_curl_hndl); if (config.debug) curl_easy_setopt(dris_curl_hndl, CURLOPT_VERBOSE, 1); curl_easy_setopt(dris_curl_hndl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(dris_curl_hndl, CURLOPT_URL, config.url); curl_easy_setopt(dris_curl_hndl, CURLOPT_WRITEFUNCTION, dris_curl_write); curl_easy_setopt(dris_curl_hndl, CURLOPT_WRITEDATA, out); post = 0; last = 0; curl_formadd(&post, &last, CURLFORM_COPYNAME, "data", CURLFORM_BUFFER, "stdout", CURLFORM_BUFFERPTR, in->buf, CURLFORM_BUFFERLENGTH, in->len, CURLFORM_END); curl_easy_setopt(dris_curl_hndl, CURLOPT_HTTPPOST, post); #if 0 curl_easy_setopt(dris_curl_hndl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); /* Well, my (old) proxy does not understand this: */ killhead = curl_slist_append(NULL, "Expect:"); curl_easy_setopt(dris_curl_hndl, CURLOPT_HTTPHEADER, killhead); #endif ret = curl_easy_perform(dris_curl_hndl); DP(("dris_curl ret=%d", ret)); #if 0 curl_slist_free_all(killhead); #endif curl_formfree(post); #if 0 /* There must be an error in the libcurl description * It says (at CURLFORM_BUFFERTR) it must be called, and says simultanously * (curl_easy_cleanup) that you must not call it to keep the connection alive */ curl_easy_cleanup(dris_curl_hndl); #endif return ret; }