edbfa2157cec3158945570b5cd0c1b5d94b79d86
[apps/livebox/data-provider-master.git] / src / abi.c
1 /*
2  * Copyright 2013  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <string.h>
19 #include <errno.h>
20
21 #include <Eina.h>
22 #include <dlog.h>
23 #include <livebox-errno.h>
24
25 #include "util.h"
26 #include "debug.h"
27 #include "conf.h"
28
29 int errno;
30
31 struct item {
32         char *abi;
33         char *pkgname; /*!< Slave package name */
34 };
35
36 static struct {
37         Eina_List *list;
38 } s_abi = {
39         .list = NULL,
40 };
41
42 HAPI int abi_add_entry(const char *abi, const char *pkgname)
43 {
44         struct item *item;
45
46         item = malloc(sizeof(*item));
47         if (!item) {
48                 ErrPrint("Failed to add a new entry for abi[%s - %s]\n", abi, pkgname);
49                 return LB_STATUS_ERROR_MEMORY;
50         }
51
52         item->abi = strdup(abi);
53         if (!item->abi) {
54                 ErrPrint("Heap: %s\n", strerror(errno));
55                 DbgFree(item);
56                 return LB_STATUS_ERROR_MEMORY;
57         }
58
59         item->pkgname = strdup(pkgname);
60         if (!item->pkgname) {
61                 ErrPrint("Heap: %s\n", strerror(errno));
62                 DbgFree(item->abi);
63                 DbgFree(item);
64                 return LB_STATUS_ERROR_MEMORY;
65         }
66
67         s_abi.list = eina_list_append(s_abi.list, item);
68         return LB_STATUS_SUCCESS;
69 }
70
71 HAPI int abi_update_entry(const char *abi, const char *pkgname)
72 {
73         Eina_List *l;
74         Eina_List *n;
75         struct item *item;
76         char *_pkgname;
77
78         _pkgname = strdup(pkgname);
79         if (!_pkgname) {
80                 ErrPrint("Heap: %s\n", strerror(errno));
81                 return LB_STATUS_ERROR_MEMORY;
82         }
83
84         EINA_LIST_FOREACH_SAFE(s_abi.list, l, n, item) {
85                 if (!strcasecmp(item->abi, abi)) {
86                         DbgFree(item->pkgname);
87                         item->pkgname = _pkgname;
88                         return 0;
89                 }
90         }
91
92         DbgFree(_pkgname);
93         return LB_STATUS_ERROR_NOT_EXIST;
94 }
95
96 HAPI int abi_del_entry(const char *abi)
97 {
98         Eina_List *l;
99         Eina_List *n;
100         struct item *item;
101
102         EINA_LIST_FOREACH_SAFE(s_abi.list, l, n, item) {
103                 if (!strcasecmp(item->abi, abi)) {
104                         s_abi.list = eina_list_remove(s_abi.list, item);
105                         DbgFree(item->abi);
106                         DbgFree(item->pkgname);
107                         DbgFree(item);
108                         return LB_STATUS_SUCCESS;
109                 }
110         }
111
112         return LB_STATUS_ERROR_NOT_EXIST;
113 }
114
115 HAPI void abi_del_all(void)
116 {
117         struct item *item;
118
119         EINA_LIST_FREE(s_abi.list, item) {
120                 DbgFree(item->abi);
121                 DbgFree(item->pkgname);
122                 DbgFree(item);
123         }
124 }
125
126 HAPI const char *abi_find_slave(const char *abi)
127 {
128         Eina_List *l;
129         struct item *item;
130
131         EINA_LIST_FOREACH(s_abi.list, l, item) {
132                 if (!strcasecmp(item->abi, abi)) {
133                         return item->pkgname;
134                 }
135         }
136
137         return NULL;
138 }
139
140 HAPI const char *abi_find_by_pkgname(const char *pkgname)
141 {
142         Eina_List *l;
143         struct item *item;
144
145         EINA_LIST_FOREACH(s_abi.list, l, item) {
146                 if (!strcmp(item->pkgname, pkgname)) {
147                         return item->abi;
148                 }
149         }
150
151         return NULL;
152 }
153
154 /* End of a file */