Tizen 2.1 base
[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 int tethering_client_clone(tethering_client_h *dest, tethering_client_h origin)
22 {
23         _retvm_if(dest == NULL, TETHERING_ERROR_INVALID_PARAMETER,
24                         "Parameter(dest) is NULL\n");
25
26         __tethering_client_h *si = NULL;
27
28         si = malloc(sizeof(__tethering_client_h));
29         if (si == NULL) {
30                 ERR("malloc is failed\n");
31                 return TETHERING_ERROR_OUT_OF_MEMORY;
32         }
33
34         memcpy(si, (__tethering_client_h *)origin,
35                         sizeof(__tethering_client_h));
36
37         *dest = (tethering_client_h)si;
38
39         return TETHERING_ERROR_NONE;
40 }
41
42 int tethering_client_destroy(tethering_client_h client)
43 {
44         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
45                         "Parameter(client) is NULL\n");
46
47         free(client);
48
49         return TETHERING_ERROR_NONE;
50 }
51
52 int tethering_client_get_tethering_type(tethering_client_h client, tethering_type_e *type)
53 {
54         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
55                         "Parameter(client) is NULL\n");
56         _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER,
57                         "Parameter(type) is NULL\n");
58
59         __tethering_client_h *si = (__tethering_client_h *)client;
60
61         *type = si->interface;
62
63         return TETHERING_ERROR_NONE;
64 }
65
66 int tethering_client_get_name(tethering_client_h client, char **name)
67 {
68         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
69                         "Parameter(client) is NULL\n");
70         _retvm_if(name == NULL, TETHERING_ERROR_INVALID_PARAMETER,
71                         "Parameter(name) is NULL\n");
72
73         __tethering_client_h *si = (__tethering_client_h *)client;
74
75         *name = strdup(si->hostname);
76         if (*name == NULL) {
77                 ERR("strdup is failed\n");
78                 return TETHERING_ERROR_OUT_OF_MEMORY;
79         }
80
81         return TETHERING_ERROR_NONE;
82 }
83
84 int tethering_client_get_ip_address(tethering_client_h client, tethering_address_family_e address_family, char **ip_address)
85 {
86         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
87                         "Parameter(client) is NULL\n");
88         _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
89                         "Parameter(ip_address) is NULL\n");
90
91         __tethering_client_h *si = (__tethering_client_h *)client;
92
93         *ip_address = strdup(si->ip);
94         if (*ip_address == NULL) {
95                 ERR("strdup is failed\n");
96                 return TETHERING_ERROR_OUT_OF_MEMORY;
97         }
98
99         return TETHERING_ERROR_NONE;
100 }
101
102 int tethering_client_get_mac_address(tethering_client_h client, char **mac_address)
103 {
104         _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
105                         "Parameter(client) is NULL\n");
106         _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER,
107                         "Parameter(mac_address) is NULL\n");
108
109         __tethering_client_h *si = (__tethering_client_h *)client;
110
111         *mac_address = strdup(si->mac);
112         if (*mac_address == NULL) {
113                 ERR("strdup is failed\n");
114                 return TETHERING_ERROR_OUT_OF_MEMORY;
115         }
116
117         return TETHERING_ERROR_NONE;
118 }
119