opkg: correct the name of the state changed callback and run it when appropriate
[project/opkg-lede.git] / pkg_dest_list.c
1 /* pkg_dest_list.c - the itsy package management system
2
3 Carl D. Worth
4
5 Copyright (C) 2001 University of Southern California
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16 */
17
18 #include "opkg.h"
19
20 #include "pkg_dest.h"
21 #include "void_list.h"
22 #include "pkg_dest_list.h"
23
24 int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
25 {
26 return void_list_elt_init((void_list_elt_t *) elt, data);
27 }
28
29 void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
30 {
31 void_list_elt_deinit((void_list_elt_t *) elt);
32 }
33
34 int pkg_dest_list_init(pkg_dest_list_t *list)
35 {
36 return void_list_init((void_list_t *) list);
37 }
38
39 void pkg_dest_list_deinit(pkg_dest_list_t *list)
40 {
41 pkg_dest_list_elt_t *iter;
42 pkg_dest_t *pkg_dest;
43
44 for (iter = list->head; iter; iter = iter->next) {
45 pkg_dest = iter->data;
46 pkg_dest_deinit(pkg_dest);
47
48 /* malloced in pkg_dest_list_append */
49 free(pkg_dest);
50 iter->data = NULL;
51 }
52 void_list_deinit((void_list_t *) list);
53 }
54
55 pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
56 const char *root_dir,const char *lists_dir)
57 {
58 int err;
59 pkg_dest_t *pkg_dest;
60
61 /* freed in plg_dest_list_deinit */
62 pkg_dest = malloc(sizeof(pkg_dest_t));
63 if (pkg_dest == NULL) {
64 fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
65 return NULL;
66 }
67
68 pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
69 err = void_list_append((void_list_t *) list, pkg_dest);
70 if (err) {
71 return NULL;
72 }
73
74 return pkg_dest;
75 }
76
77 int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
78 {
79 return void_list_push((void_list_t *) list, data);
80 }
81
82 pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
83 {
84 return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
85 }