2011-11-24 15:53:08 +05:30
|
|
|
/*-
|
2020-04-24 15:14:19 +05:30
|
|
|
* Licensed under the SPDX BSD-2-Clause identifier.
|
|
|
|
* Use is subject to license terms, as specified in the LICENSE file.
|
2011-11-24 15:53:08 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_VASPRINTF
|
|
|
|
# define _GNU_SOURCE /* for vasprintf(3) */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
2013-01-04 15:05:00 +05:30
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
|
|
|
#endif
|
|
|
|
|
2011-11-24 15:53:08 +05:30
|
|
|
void HIDDEN
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_fetch(struct xbps_handle *xhp,
|
|
|
|
off_t file_size,
|
2011-11-24 15:53:08 +05:30
|
|
|
off_t file_offset,
|
|
|
|
off_t file_dloaded,
|
|
|
|
const char *file_name,
|
|
|
|
bool cb_start,
|
|
|
|
bool cb_update,
|
|
|
|
bool cb_end)
|
|
|
|
{
|
2012-01-20 16:59:14 +05:30
|
|
|
struct xbps_fetch_cb_data xfcd;
|
2011-11-24 15:53:08 +05:30
|
|
|
|
|
|
|
if (xhp->fetch_cb == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
xfcd.xhp = xhp;
|
2012-01-20 16:59:14 +05:30
|
|
|
xfcd.file_size = file_size;
|
|
|
|
xfcd.file_offset = file_offset;
|
|
|
|
xfcd.file_dloaded = file_dloaded;
|
|
|
|
xfcd.file_name = file_name;
|
|
|
|
xfcd.cb_start = cb_start;
|
|
|
|
xfcd.cb_update = cb_update;
|
|
|
|
xfcd.cb_end = cb_end;
|
2012-11-30 11:41:51 +05:30
|
|
|
(*xhp->fetch_cb)(&xfcd, xhp->fetch_cb_data);
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
|
|
|
|
2013-10-05 15:08:04 +05:30
|
|
|
int HIDDEN
|
2012-06-14 11:52:11 +05:30
|
|
|
xbps_set_cb_state(struct xbps_handle *xhp,
|
|
|
|
xbps_state_t state,
|
2011-11-24 15:53:08 +05:30
|
|
|
int err,
|
2013-03-05 08:38:42 +05:30
|
|
|
const char *arg,
|
2011-11-24 15:53:08 +05:30
|
|
|
const char *fmt,
|
|
|
|
...)
|
|
|
|
{
|
2012-01-20 16:59:14 +05:30
|
|
|
struct xbps_state_cb_data xscd;
|
2011-11-24 15:53:08 +05:30
|
|
|
char *buf = NULL;
|
|
|
|
va_list va;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (xhp->state_cb == NULL)
|
2013-10-05 15:08:04 +05:30
|
|
|
return 0;
|
2011-11-24 15:53:08 +05:30
|
|
|
|
2012-11-30 11:41:51 +05:30
|
|
|
xscd.xhp = xhp;
|
2012-01-20 16:59:14 +05:30
|
|
|
xscd.state = state;
|
|
|
|
xscd.err = err;
|
2013-03-05 08:38:42 +05:30
|
|
|
xscd.arg = arg;
|
2011-11-24 15:53:08 +05:30
|
|
|
if (fmt != NULL) {
|
|
|
|
va_start(va, fmt);
|
|
|
|
retval = vasprintf(&buf, fmt, va);
|
|
|
|
va_end(va);
|
2011-11-25 12:52:20 +05:30
|
|
|
if (retval <= 0)
|
2012-01-20 16:59:14 +05:30
|
|
|
xscd.desc = NULL;
|
2011-11-24 15:53:08 +05:30
|
|
|
else
|
2012-01-20 16:59:14 +05:30
|
|
|
xscd.desc = buf;
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|
2013-10-05 15:08:04 +05:30
|
|
|
retval = (*xhp->state_cb)(&xscd, xhp->state_cb_data);
|
2011-11-24 15:53:08 +05:30
|
|
|
if (buf != NULL)
|
|
|
|
free(buf);
|
2013-10-05 15:08:04 +05:30
|
|
|
|
|
|
|
return retval;
|
2011-11-24 15:53:08 +05:30
|
|
|
}
|