summaryrefslogtreecommitdiffstats
path: root/src/software-dbus/sw-utils.h
blob: 5e61ccbf3a3924dcba81adafffa1b808d9e2803f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Authors: Peter Schiffer <pschiffe@redhat.com>
 */

#ifndef SW_UTILS_H_
#define SW_UTILS_H_

#define I_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <packagekit-glib2/packagekit.h>

#include "globals.h"

const char *provider_name;
const ConfigEntry *provider_config_defaults;

/* Software Package */
typedef struct _SwPackage {
    char *name;         /* Package name w/o anything else */
    char *epoch;        /* Epoch number */
    char *version;      /* Version number, w/o epoch or release */
    char *release;      /* Release number */
    char *arch;         /* Architecture */
    char *pk_version;   /* PackageKit style package version - (epoch:)?version-release */
} SwPackage;

/*
 * Initialize SwPackage structure.
 * @param pkg SwPackage
 */
void init_sw_package(SwPackage *pkg);

/*
 * Free SwPackage structure.
 * @param pkg SwPackage
 */
void free_sw_package(SwPackage *pkg);

/*
 * Create SwPackage from PkPackage.
 * @param pk_pkg source package
 * @param sw_pkg output package
 * @return 0 on success, negative value otherwise
 */
short create_sw_package_from_pk_pkg(PkPackage *pk_pkg, SwPackage *sw_pkg);

/*
 * Create SwPackage from element name.
 * @param elem_name element name in format name-(epoch:)?version-release.arch
 * @param sw_pkg output package
 * @return 0 on success, negative value otherwise
 */
short create_sw_package_from_elem_name(const char *elem_name, SwPackage *sw_pkg);

/*
 * Construct version name in format epoch:version-release.arch for
 * SwPackage structure.
 * @param pkg SwPackage
 * @param ver_str version string
 * @param ver_str_len length of version string
 */
void sw_pkg_get_version_str(const SwPackage *pkg, char *ver_str,
        const unsigned ver_str_len);

/*
 * Construct element name in format name-epoch:version-release.arch for
 * SwPackage structure.
 * @param pkg SwPackage
 * @param elem_name element name string
 * @param elem_name_len length of element name string
 */
void sw_pkg_get_element_name(const SwPackage *pkg, char *elem_name,
        const unsigned elem_name_len);

/*
 * Analyze PkResults and construct error message if error occurred.
 * @param results from package kit call
 * @param custom_msg message preceding error message from package kit
 * @param error_msg final error message
 * @param error_msg_len length of error_msg
 * @return 0 if no error occurred, positive value if error occurred
 *      and error_msg was modified
 */
short check_and_create_error_msg(PkResults *results, const char *custom_msg,
        char *error_msg, const unsigned error_msg_len);

/*
 * Create standard instance ID based on class name and ID.
 * @param class_name
 * @param id, may by null
 * @param instance_id output string
 * @param instance_id_len length of output string
 */
void create_instance_id(const char *class_name, const char *id,
        char *instance_id, const unsigned instance_id_len);

#endif /* SW_UTILS_H_ */