XBPS Library API 20240111
The X Binary Package System
package_msg.c
1/*-
2 * Copyright (c) 2014 Juan Romero Pardines.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <errno.h>
30
31#include "xbps_api_impl.h"
32
33int HIDDEN
34xbps_cb_message(struct xbps_handle *xhp, xbps_dictionary_t pkgd, const char *key)
35{
36 xbps_data_t msg;
37 const void *data;
38 const char *pkgver = NULL;
39 size_t len;
40 char *buf = NULL;
41 int rv = 0;
42
43 assert(xhp);
44 assert(pkgd);
45 assert(key);
46
47 xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
48
49 /* show install-msg if exists */
50 msg = xbps_dictionary_get(pkgd, key);
51 if (xbps_object_type(msg) != XBPS_TYPE_DATA)
52 goto out;
53
54 /* turn data from msg into a string */
55 data = xbps_data_data_nocopy(msg);
56 len = xbps_data_size(msg);
57 buf = malloc(len+1);
58 assert(buf);
59 memcpy(buf, data, len);
60 /* terminate string */
61 buf[len] = '\0';
62
63 /* notify client to show the post-install message */
64 if (strcmp(key, "install-msg") == 0)
65 xbps_set_cb_state(xhp, XBPS_STATE_SHOW_INSTALL_MSG, 0, pkgver, "%s", buf);
66 else
67 xbps_set_cb_state(xhp, XBPS_STATE_SHOW_REMOVE_MSG, 0, pkgver, "%s", buf);
68
69out:
70 free(buf);
71 return rv;
72}
Generic XBPS structure handler for initialization.
Definition xbps.h:550