diff --git a/plugins/dbus_announce.c b/plugins/dbus_announce.c index 2c01e3f376..532afa1cd4 100644 --- a/plugins/dbus_announce.c +++ b/plugins/dbus_announce.c @@ -83,6 +83,19 @@ static void dbus_announce_cleanup(rpmPlugin plugin) free(state); } +static void free_array(char ** array) +{ + int i; + + if (array == NULL) + return; + + for (i = 0; array[i]; i++) { + free(array[i]); + } + free(array); +} + static rpmRC send_ts_message(rpmPlugin plugin, const char * name, rpmts ts, @@ -91,6 +104,8 @@ static rpmRC send_ts_message(rpmPlugin plugin, struct dbus_announce_data * state = rpmPluginGetData(plugin); DBusMessage* msg; char * dbcookie = NULL; + char ** array = NULL; + int nElems, i; if (!state->bus) return RPMRC_OK; @@ -103,9 +118,50 @@ static rpmRC send_ts_message(rpmPlugin plugin, dbcookie = rpmdbCookie(rpmtsGetRdb(ts)); rpm_tid_t tid = rpmtsGetTid(ts); + nElems = rpmtsNElements(ts); + array = (char **) malloc((nElems + 1 ) * sizeof(char *)); + if (array == NULL) + goto err; + + array[0] = NULL; + for (i = 0; i < nElems; i++) { + rpmte te = rpmtsElement(ts, i); + char *buff; + int buffln; + const char *op = "??"; + const char *nevra = rpmteNEVRA(te); + if (nevra == NULL) + nevra = ""; + switch (rpmteType (te)) { + case TR_ADDED: + op = "added"; + break; + case TR_REMOVED: + op = "removed"; + break; + case TR_RPMDB: + op = "rpmdb"; + break; + case TR_RESTORED: + op = "restored"; + break; + } + buffln = strlen(op) + 1 + strlen(nevra) + 1; + buff = (char *) malloc(sizeof(char) * buffln); + if (buff == NULL) + goto err; + /* encode as "operation SPACE nevra" */ + snprintf(buff, buffln, "%s %s", op, nevra); + array[i] = buff; + } + /* sentinel */ + array[nElems] = NULL; + if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &dbcookie, DBUS_TYPE_UINT32, &tid, + DBUS_TYPE_INT32, &res, + DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, nElems, DBUS_TYPE_INVALID)) goto err; @@ -115,6 +171,8 @@ static rpmRC send_ts_message(rpmPlugin plugin, dbus_connection_flush(state->bus); dbcookie = _free(dbcookie); + free_array(array); + return RPMRC_OK; err: @@ -122,6 +180,7 @@ static rpmRC send_ts_message(rpmPlugin plugin, "dbus_announce plugin: Error sending message (%s)\n", name); dbcookie = _free(dbcookie); + free_array(array); return RPMRC_OK; }