libxbps: some tweaks for struct xbps_state_cb_data.

- Renamed args pkgname/version to arg0/arg1 to make them generic.
- Update bins with this and make some tweaks in state_cb.

Bumped API version.
This commit is contained in:
Juan RP 2012-11-07 10:11:06 +01:00
parent 89d892d98f
commit ca095df52f
5 changed files with 35 additions and 40 deletions

View File

@ -61,36 +61,35 @@ state_cb(struct xbps_handle *xhp,
printf("[*] Configuring unpacked packages\n"); printf("[*] Configuring unpacked packages\n");
break; break;
case XBPS_STATE_REPOSYNC: case XBPS_STATE_REPOSYNC:
case XBPS_STATE_DOWNLOAD: printf("[*] Updating `%s/%s' ...\n",
xscd->arg0, xscd->arg1);
break;
case XBPS_STATE_VERIFY: case XBPS_STATE_VERIFY:
case XBPS_STATE_CONFIG_FILE: case XBPS_STATE_CONFIG_FILE:
if (xscd->desc != NULL) if (xscd->desc != NULL)
printf("%s\n", xscd->desc); printf("%s\n", xscd->desc);
break; break;
case XBPS_STATE_REMOVE: case XBPS_STATE_REMOVE:
printf("Removing `%s-%s' ...\n", xscd->pkgname, xscd->version); printf("Removing `%s-%s' ...\n", xscd->arg0, xscd->arg1);
break; break;
case XBPS_STATE_CONFIGURE: case XBPS_STATE_CONFIGURE:
printf("Configuring `%s-%s' ...\n", xscd->pkgname, printf("Configuring `%s-%s' ...\n", xscd->arg0, xscd->arg1);
xscd->version);
break; break;
case XBPS_STATE_REGISTER: case XBPS_STATE_REGISTER:
case XBPS_STATE_UNREGISTER: case XBPS_STATE_UNREGISTER:
/* empty */ /* empty */
break; break;
case XBPS_STATE_UNPACK: case XBPS_STATE_UNPACK:
printf("Unpacking `%s-%s' ...\n", xscd->pkgname, xscd->version); printf("Unpacking `%s-%s' ...\n", xscd->arg0, xscd->arg1);
break; break;
case XBPS_STATE_INSTALL: case XBPS_STATE_INSTALL:
printf("Installing `%s-%s' ...\n", printf("Installing `%s-%s' ...\n", xscd->arg0, xscd->arg1);
xscd->pkgname, xscd->version);
break; break;
case XBPS_STATE_UPDATE: case XBPS_STATE_UPDATE:
pkgd = xbps_find_pkg_dict_installed(xhp, pkgd = xbps_find_pkg_dict_installed(xhp, xscd->arg0, false);
xscd->pkgname, false);
prop_dictionary_get_cstring_nocopy(pkgd, "version", &version); prop_dictionary_get_cstring_nocopy(pkgd, "version", &version);
printf("Updating `%s' (`%s' to `%s') ...\n", xscd->pkgname, printf("Updating `%s' (`%s' to `%s') ...\n", xscd->arg0,
version, xscd->version); version, xscd->arg1);
break; break;
/* success */ /* success */
case XBPS_STATE_REMOVE_FILE: case XBPS_STATE_REMOVE_FILE:
@ -104,26 +103,26 @@ state_cb(struct xbps_handle *xhp,
break; break;
case XBPS_STATE_INSTALL_DONE: case XBPS_STATE_INSTALL_DONE:
printf("Installed `%s-%s' successfully.\n", printf("Installed `%s-%s' successfully.\n",
xscd->pkgname, xscd->version); xscd->arg0, xscd->arg1);
if (syslog_enabled) if (syslog_enabled)
syslog(LOG_NOTICE, "Installed `%s-%s' successfully " syslog(LOG_NOTICE, "Installed `%s-%s' successfully "
"(rootdir: %s).", xscd->pkgname, xscd->version, "(rootdir: %s).", xscd->arg0, xscd->arg1,
xhp->rootdir); xhp->rootdir);
break; break;
case XBPS_STATE_UPDATE_DONE: case XBPS_STATE_UPDATE_DONE:
printf("Updated `%s' to `%s' successfully.\n", printf("Updated `%s' to `%s' successfully.\n",
xscd->pkgname, xscd->version); xscd->arg0, xscd->arg1);
if (syslog_enabled) if (syslog_enabled)
syslog(LOG_NOTICE, "Updated `%s' to `%s' successfully " syslog(LOG_NOTICE, "Updated `%s' to `%s' successfully "
"(rootdir: %s).", xscd->pkgname, xscd->version, "(rootdir: %s).", xscd->arg0, xscd->arg1,
xhp->rootdir); xhp->rootdir);
break; break;
case XBPS_STATE_REMOVE_DONE: case XBPS_STATE_REMOVE_DONE:
printf("Removed `%s-%s' successfully.\n", printf("Removed `%s-%s' successfully.\n",
xscd->pkgname, xscd->version); xscd->arg0, xscd->arg1);
if (syslog_enabled) if (syslog_enabled)
syslog(LOG_NOTICE, "Removed `%s-%s' successfully " syslog(LOG_NOTICE, "Removed `%s-%s' successfully "
"(rootdir: %s).", xscd->pkgname, xscd->version, "(rootdir: %s).", xscd->arg0, xscd->arg1,
xhp->rootdir); xhp->rootdir);
break; break;
/* errors */ /* errors */

View File

@ -65,8 +65,7 @@ state_cb(struct xbps_handle *xhp, struct xbps_state_cb_data *xscd, void *cbd)
switch (xscd->state) { switch (xscd->state) {
/* notifications */ /* notifications */
case XBPS_STATE_CONFIGURE: case XBPS_STATE_CONFIGURE:
printf("Configuring `%s-%s' ...\n", xscd->pkgname, printf("Configuring `%s-%s' ...\n", xscd->arg0, xscd->arg1);
xscd->version);
break; break;
/* errors */ /* errors */
case XBPS_STATE_CONFIGURE_FAIL: case XBPS_STATE_CONFIGURE_FAIL:

View File

@ -89,7 +89,7 @@ state_cb_rm(struct xbps_handle *xhp,
switch (xscd->state) { switch (xscd->state) {
/* notifications */ /* notifications */
case XBPS_STATE_REMOVE: case XBPS_STATE_REMOVE:
printf("Removing `%s-%s' ...\n", xscd->pkgname, xscd->version); printf("Removing `%s-%s' ...\n", xscd->arg0, xscd->arg1);
break; break;
/* success */ /* success */
case XBPS_STATE_REMOVE_FILE: case XBPS_STATE_REMOVE_FILE:
@ -103,10 +103,10 @@ state_cb_rm(struct xbps_handle *xhp,
break; break;
case XBPS_STATE_REMOVE_DONE: case XBPS_STATE_REMOVE_DONE:
printf("Removed `%s-%s' successfully.\n", printf("Removed `%s-%s' successfully.\n",
xscd->pkgname, xscd->version); xscd->arg0, xscd->arg1);
if (syslog_enabled) if (syslog_enabled)
syslog(LOG_NOTICE, "Removed `%s-%s' successfully " syslog(LOG_NOTICE, "Removed `%s-%s' successfully "
"(rootdir: %s).", xscd->pkgname, xscd->version, "(rootdir: %s).", xscd->arg0, xscd->arg1,
xhp->rootdir); xhp->rootdir);
break; break;
/* errors */ /* errors */

View File

@ -56,7 +56,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.5" #define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20121026" #define XBPS_API_VERSION "20121107"
#ifndef XBPS_VERSION #ifndef XBPS_VERSION
#define XBPS_VERSION "UNSET" #define XBPS_VERSION "UNSET"
@ -298,36 +298,33 @@ typedef enum xbps_state {
/** /**
* @struct xbps_state_cb_data xbps_api.h "xbps_api.h" * @struct xbps_state_cb_data xbps_api.h "xbps_api.h"
* @brief Structure to be passed as argument to the state function callback. * @brief Structure to be passed as argument to the state function callback.
* All members are read-only and set internally by libxbps.
*/ */
struct xbps_state_cb_data { struct xbps_state_cb_data {
/** /**
* @var state * @var state
* *
* Returned xbps state (set internally, read-only). * Current state.
*/ */
xbps_state_t state; xbps_state_t state;
/** /**
* @var desc * @var desc
* *
* XBPS state string description (set internally, read-only). * Current state string description.
*/ */
const char *desc; const char *desc;
/** /**
* @var pkgname * @var arg[0-1]
* *
* Package name string (set internally, read-only). * State string arguments arg[0-1]. Strings set on these
* variables may change depending on \a state.
*/ */
const char *pkgname; const char *arg0;
/** const char *arg1;
* @var version
*
* Package version string (set internally, read-only).
*/
const char *version;
/** /**
* @var err * @var err
* *
* XBPS state error value (set internally, read-only). * Current state error value (set internally, read-only).
*/ */
int err; int err;
}; };

View File

@ -69,8 +69,8 @@ void HIDDEN
xbps_set_cb_state(struct xbps_handle *xhp, xbps_set_cb_state(struct xbps_handle *xhp,
xbps_state_t state, xbps_state_t state,
int err, int err,
const char *pkgname, const char *arg0,
const char *version, const char *arg1,
const char *fmt, const char *fmt,
...) ...)
{ {
@ -84,8 +84,8 @@ xbps_set_cb_state(struct xbps_handle *xhp,
xscd.state = state; xscd.state = state;
xscd.err = err; xscd.err = err;
xscd.pkgname = pkgname; xscd.arg0 = arg0;
xscd.version = version; xscd.arg1 = arg1;
if (fmt != NULL) { if (fmt != NULL) {
va_start(va, fmt); va_start(va, fmt);
retval = vasprintf(&buf, fmt, va); retval = vasprintf(&buf, fmt, va);
@ -95,7 +95,7 @@ xbps_set_cb_state(struct xbps_handle *xhp,
else else
xscd.desc = buf; xscd.desc = buf;
} }
(*xhp->state_cb)(xhp, &xscd, xhp->fetch_cb_data); (*xhp->state_cb)(xhp, &xscd, xhp->state_cb_data);
if (buf != NULL) if (buf != NULL)
free(buf); free(buf);
} }