Initialize the project.
[apps/livebox/data-provider-master.git] / src / abi.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.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
24 #include "util.h"
25 #include "debug.h"
26 #include "conf.h"
27
28 int errno;
29
30 struct item {
31         char *abi;
32         char *pkgname; /*!< Slave package name */
33 };
34
35 static struct {
36         Eina_List *list;
37 } s_abi = {
38         .list = NULL,
39 };
40
41 HAPI int abi_add_entry(const char *abi, const char *pkgname)
42 {
43         struct item *item;
44
45         item = malloc(sizeof(*item));
46         if (!item) {
47                 ErrPrint("Failed to add a new entry for abi[%s - %s]\n", abi, pkgname);
48                 return -ENOMEM;
49         }
50
51         item->abi = strdup(abi);
52         if (!item->abi) {
53                 ErrPrint("Heap: %s\n", strerror(errno));
54                 DbgFree(item);
55                 return -ENOMEM;
56         }
57
58         item->pkgname = strdup(pkgname);
59         if (!item->pkgname) {
60                 ErrPrint("Heap: %s\n", strerror(errno));
61                 DbgFree(item->abi);
62                 DbgFree(item);
63                 return -ENOMEM;
64         }
65
66         s_abi.list = eina_list_append(s_abi.list, item);
67         return 0;
68 }
69
70 HAPI int abi_update_entry(const char *abi, const char *pkgname)
71 {
72         Eina_List *l;
73         Eina_List *n;
74         struct item *item;
75         char *_pkgname;
76
77         _pkgname = strdup(pkgname);
78         if (!_pkgname) {
79                 ErrPrint("Heap: %s\n", strerror(errno));
80                 return -ENOMEM;
81         }
82
83         EINA_LIST_FOREACH_SAFE(s_abi.list, l, n, item) {
84                 if (!strcasecmp(item->abi, abi)) {
85                         DbgFree(item->pkgname);
86                         item->pkgname = _pkgname;
87                         return 0;
88                 }
89         }
90
91         DbgFree(_pkgname);
92         return -ENOENT;
93 }
94
95 HAPI int abi_del_entry(const char *abi)
96 {
97         Eina_List *l;
98         Eina_List *n;
99         struct item *item;
100
101         EINA_LIST_FOREACH_SAFE(s_abi.list, l, n, item) {
102                 if (!strcasecmp(item->abi, abi)) {
103                         s_abi.list = eina_list_remove(s_abi.list, item);
104                         DbgFree(item->abi);
105                         DbgFree(item->pkgname);
106                         DbgFree(item);
107                         return 0;
108                 }
109         }
110
111         return -ENOENT;
112 }
113
114 HAPI int abi_del_all(void)
115 {
116         struct item *item;
117
118         EINA_LIST_FREE(s_abi.list, item) {
119                 DbgFree(item->abi);
120                 DbgFree(item->pkgname);
121                 DbgFree(item);
122         }
123
124         return 0;
125 }
126
127 HAPI const char *abi_find_slave(const char *abi)
128 {
129         Eina_List *l;
130         struct item *item;
131
132         EINA_LIST_FOREACH(s_abi.list, l, item) {
133                 if (!strcasecmp(item->abi, abi))
134                         return item->pkgname;
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         return NULL;
151 }
152
153 /* End of a file */