Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend dbus-announce plugin #3532

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions plugins/dbus_announce.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -115,13 +171,16 @@ static rpmRC send_ts_message(rpmPlugin plugin,
dbus_connection_flush(state->bus);
dbcookie = _free(dbcookie);

free_array(array);

return RPMRC_OK;

err:
rpmlog(RPMLOG_WARNING,
"dbus_announce plugin: Error sending message (%s)\n",
name);
dbcookie = _free(dbcookie);
free_array(array);
return RPMRC_OK;
}

Expand Down