Add gtest for line coverage
[platform/core/api/tethering.git] / src / tethering_client.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 #include <stdlib.h>
18 #include <string.h>
19 #include "tethering_private.h"
20
21 API int tethering_client_clone(tethering_client_h *dest, tethering_client_h origin)
22 {
23         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
24
25         _retvm_if(dest == NULL, TETHERING_ERROR_INVALID_PARAMETER,
26                         "Parameter(dest) is NULL\n");
27         _retvm_if(origin == NULL, TETHERING_ERROR_INVALID_PARAMETER,
28                         "Parameter(origin) is NULL\n");
29
30         __tethering_client_h *si = NULL;
31         __tethering_client_h *source = NULL;
32
33         source = (__tethering_client_h *)origin;
34
35         si = malloc(sizeof(__tethering_client_h));
36         if (si == NULL) {
37                 ERR("malloc is failed\n");
38                 return TETHERING_ERROR_OUT_OF_MEMORY;
39         }
40
41         memcpy(si, source, sizeof(__tethering_client_h));
42         si->hostname = g_strdup(source->hostname);
43         if (si->hostname == NULL) {
44                 ERR("malloc is failed\n");
45                 free(si);
46                 return TETHERING_ERROR_OUT_OF_MEMORY;
47         }
48
49         *dest = (tethering_client_h)si;
50
51         return TETHERING_ERROR_NONE;
52 }
53
54 API int tethering_client_destroy(tethering_client_h client)
55 {
56         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
57
58         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
59                         "Parameter(client) is NULL\n");
60
61         __tethering_client_h *si = NULL;
62
63         si = (__tethering_client_h *)client;
64
65         g_free(si->hostname);
66
67         free(client);
68
69         return TETHERING_ERROR_NONE;
70 }
71
72 API int tethering_client_get_tethering_type(tethering_client_h client, tethering_type_e *type)
73 {
74         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
75
76         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
77                         "Parameter(client) is NULL\n");
78         _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
79                         "Parameter(type) is NULL\n");
80
81         __tethering_client_h *si = (__tethering_client_h *)client;
82
83         *type = si->interface;
84
85         return TETHERING_ERROR_NONE;
86 }
87
88 API int tethering_client_get_name(tethering_client_h client, char **name)
89 {
90         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
91
92         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
93                         "Parameter(client) is NULL\n");
94         _retvm_if(name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
95                         "Parameter(name) is NULL\n");
96
97         __tethering_client_h *si = (__tethering_client_h *)client;
98
99         *name = strdup(si->hostname);
100         if (*name == NULL) {
101                 ERR("strdup is failed\n");
102                 return TETHERING_ERROR_OUT_OF_MEMORY;
103         }
104
105         return TETHERING_ERROR_NONE;
106 }
107
108 API int tethering_client_get_ip_address(tethering_client_h client, tethering_address_family_e address_family, char **ip_address)
109 {
110         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
111
112         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
113                         "Parameter(client) is NULL\n");
114         _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
115                         "Parameter(ip_address) is NULL\n");
116
117         __tethering_client_h *si = (__tethering_client_h *)client;
118
119         *ip_address = strdup(si->ip);
120         if (*ip_address == NULL) {
121                 ERR("strdup is failed\n");
122                 return TETHERING_ERROR_OUT_OF_MEMORY;
123         }
124
125         return TETHERING_ERROR_NONE;
126 }
127
128 API int tethering_client_get_mac_address(tethering_client_h client, char **mac_address)
129 {
130         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
131
132         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
133                         "Parameter(client) is NULL\n");
134         _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
135                         "Parameter(mac_address) is NULL\n");
136
137         __tethering_client_h *si = (__tethering_client_h *)client;
138
139         *mac_address = strdup(si->mac);
140         if (*mac_address == NULL) {
141                 ERR("strdup is failed\n");
142                 return TETHERING_ERROR_OUT_OF_MEMORY;
143         }
144
145         return TETHERING_ERROR_NONE;
146 }
147
148 API int tethering_client_get_time(tethering_client_h client, time_t *timestamp)
149 {
150         CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
151
152         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
153                         "Parameter(client) is NULL\n");
154         _retvm_if(timestamp == NULL, TETHERING_ERROR_INVALID_PARAMETER,
155                         "Parameter(timestamp) is NULL\n");
156
157
158         __tethering_client_h *si = (__tethering_client_h *)client;
159
160         *timestamp = si->tm;
161
162         return TETHERING_ERROR_NONE;
163 }
164