File: uri-digest.c

package info (click to toggle)
gtkhash 1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,132 kB
  • sloc: ansic: 6,711; sh: 4,249; xml: 2,413; makefile: 392
file content (90 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download | duplicates (3)
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
/*
 *   Copyright (C) 2007-2016 Tristan Heaven <tristan@tristanheaven.net>
 *
 *   This file is part of GtkHash.
 *
 *   GtkHash is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   GtkHash 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 General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with GtkHash. If not, see <https://gnu.org/licenses/gpl-2.0.txt>.
 */

#ifdef HAVE_CONFIG_H
	#include "config.h"
#endif

#include <stdlib.h>
#include <glib.h>

#include "uri-digest.h"

struct uri_digest_s *uri_digest_new(char *uri, char *digest)
{
	struct uri_digest_s *ud = g_new(struct uri_digest_s, 1);
	ud->uri = uri;
	ud->digest = digest;

	return ud;
}

void uri_digest_free_full(struct uri_digest_s *ud)
{
	if (!ud)
		return;

	if (ud->uri) {
		g_free(ud->uri);
		ud->uri = NULL;
	}
	if (ud->digest) {
		g_free(ud->digest);
		ud->digest = NULL;
	}

	g_free(ud);
}

GSList *uri_digest_list_from_uri_list(GSList *uris)
{
	if (!uris)
		return NULL;

	GSList *ud_list = NULL;

	do {
		ud_list = g_slist_prepend(ud_list, uri_digest_new(uris->data, NULL));
	} while ((uris = g_slist_next(uris)));

	return g_slist_reverse(ud_list);
}

GSList *uri_digest_list_from_uri_strv(char **uris)
{
	if (!uris)
		return NULL;

	GSList *ud_list = NULL;

	for (int i = 0; uris[i]; i++)
		ud_list = g_slist_prepend(ud_list, uri_digest_new(uris[i], NULL));

	return g_slist_reverse(ud_list);
}

void uri_digest_list_free(GSList *ud_list)
{
	g_slist_free_full(ud_list, g_free);
}

void uri_digest_list_free_full(GSList *ud_list)
{
	g_slist_free_full(ud_list, (GDestroyNotify)uri_digest_free_full);
}