2011-11-24 15:53:08 +05:30
|
|
|
/*-
|
2013-03-05 08:38:42 +05:30
|
|
|
* Copyright (c) 2011-2013 Juan Romero Pardines.
|
2011-11-24 15:53:08 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
|
|
|
void 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)
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
}
|
2012-11-30 11:41:51 +05:30
|
|
|
(*xhp->state_cb)(&xscd, xhp->state_cb_data);
|
2011-11-24 15:53:08 +05:30
|
|
|
if (buf != NULL)
|
|
|
|
free(buf);
|
|
|
|
}
|