Revise directory structure
[platform/core/connectivity/asp-manager.git] / src / asp-manager-util.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 /*****************************************************************************
18  * Standard headers
19  *****************************************************************************/
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include <unistd.h>
26 #include <sys/types.h>
27 #include <sys/wait.h>
28 /*****************************************************************************
29  * System headers
30  *****************************************************************************/
31
32 #include<glib.h>
33 #include <gio/gio.h>
34
35 #include<dlog.h>
36
37 /*****************************************************************************
38  * Application Service Platform manager headers
39  *****************************************************************************/
40 #include "asp-manager.h"
41 #include "asp-manager-util.h"
42
43 /*****************************************************************************
44  * Macros and Typedefs
45  *****************************************************************************/
46
47 /*****************************************************************************
48  * Global Variables
49  *****************************************************************************/
50
51 /*****************************************************************************
52  * Local Functions Definition
53  *****************************************************************************/
54
55 gint32 macaddr_atoe(const gchar *p, guint8 mac[])
56 {
57         gint32 i = 0;
58
59         for (;;) {
60                 mac[i++] = (gchar)strtoul(p, (char **)&p, 16);
61                 if (!*p++ || i == 6)
62                         break;
63         }
64
65         return (i == 6);
66 }
67
68 gint32 asp_dbus_unpack_ay(guint8 *dst, GVariant *src, gint32 size)
69 {
70         GVariantIter *iter = NULL;
71         gint32 length = 0;
72         gint32 rv = 1;
73
74         if (!dst || !src || size == 0) {
75                 ASP_LOGE("Invalid parameter");
76                 return -1;
77         }
78         g_variant_get(src, "ay", &iter);
79         if (iter == NULL) {
80                 ASP_LOGE("failed to get iterator");
81                 return -1;
82         }
83
84         while (g_variant_iter_loop(iter, "y", &dst[length])) {
85                 length++;
86                 if (length >= size)
87                         break;
88         }
89         g_variant_iter_free(iter);
90
91         if (length < size) {
92                 ASP_LOGE("array is shorter than size");
93                 rv = -1;
94         }
95
96         return rv;
97 }