// GET Query Arguments
char** queries;
- // POST MIME Object
- curl_mime* mime;
-
// POST Payload
char* payload;
curl_easy_cleanup(xfer->handle);
if (xfer->headers)
curl_slist_free_all(xfer->headers);
- if (xfer->mime)
- curl_mime_free(xfer->mime);
if (xfer->fullurl)
curl_url_cleanup(xfer->fullurl);
return r;
}
-int pakfire_xfer_add_param(struct pakfire_xfer* xfer,
- const char* key, const char* format, ...) {
- curl_mimepart* part = NULL;
- char* buffer = NULL;
- va_list args;
- int r;
-
- // Allocate the MIME object if not done, yet
- if (!xfer->mime) {
- xfer->mime = curl_mime_init(xfer->handle);
-
- if (!xfer->mime) {
- ERROR(xfer->ctx, "Could not allocate the MIME object: %s\n",
- strerror(errno));
- r = -errno;
- goto ERROR;
- }
- }
-
- // Format value
- va_start(args, format);
- r = vasprintf(&buffer, format, args);
- va_end(args);
-
- // Abort if we could not format the value
- if (r < 0)
- goto ERROR;
-
- // Allocate another MIME part
- part = curl_mime_addpart(xfer->mime);
- if (!part) {
- ERROR(xfer->ctx, "Could not allocate MIME part: %s\n",
- strerror(errno));
- r = errno;
- goto ERROR;
- }
-
- // Set the key
- r = curl_mime_name(part, key);
- if (r) {
- ERROR(xfer->ctx, "Could not set parameter key (%s): %s\n",
- key, curl_easy_strerror(r));
- goto ERROR;
- }
-
- // Set the data
- r = curl_mime_data(part, buffer, CURL_ZERO_TERMINATED);
- if (r) {
- ERROR(xfer->ctx, "Could not set parameter data (%s): %s\n",
- key, curl_easy_strerror(r));
- goto ERROR;
- }
-
-ERROR:
- if (buffer)
- free(buffer);
-
- return r;
-}
-
int pakfire_xfer_set_payload(struct pakfire_xfer* self, const char* payload) {
if (self->payload) {
free(self->payload);
}
}
- // Add any payload
- if (xfer->mime) {
- r = curl_easy_setopt(xfer->handle, CURLOPT_MIMEPOST, xfer->mime);
- if (r) {
- ERROR(xfer->ctx, "Could not set POST payload: %s\n", curl_easy_strerror(r));
- return r;
- }
- }
-
// Add any payload
if (xfer->payload) {
r = curl_easy_setopt(xfer->handle, CURLOPT_POSTFIELDS, xfer->payload);
__attribute__((format(printf, 2, 3)));
int pakfire_xfer_add_query(struct pakfire_xfer* xfer,
const char* key, const char* format, ...) __attribute__((format(printf, 3, 4)));
-int pakfire_xfer_add_param(struct pakfire_xfer* xfer,
- const char* key, const char* format, ...) __attribute__((format(printf, 3, 4)));
// Payload
int pakfire_xfer_set_payload(struct pakfire_xfer* self, const char* payload);