Starting on TcpClient, some formatting fixes
[cascardo/gnio.git] / gnio / ginetaddress.c
1 /* GNIO - GLib Network Layer of GIO
2  *
3  * Copyright (C) 2008 Christian Kellner, Samuel Cormier-Iijima
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Authors: Christian Kellner <gicmo@gnome.org>
21  *          Samuel Cormier-Iijima <sciyoshi@gmail.com>
22  */
23
24 #include <config.h>
25 #include <glib.h>
26
27 #include "ginetaddress.h"
28
29 /**
30  * SECTION:ginetaddress
31  * @short_description: Base class for implementing IPv4/IPv6 classes
32  *
33  * 
34  * 
35  **/
36
37 G_DEFINE_ABSTRACT_TYPE (GInetAddress, g_inet_address, G_TYPE_INITIALLY_UNOWNED);
38
39 enum
40 {
41   PROP_0,
42   PROP_IS_ANY,
43   PROP_IS_LINKLOCAL,
44   PROP_IS_LOOPBACK,
45   PROP_IS_SITELOCAL,
46   PROP_IS_MULTICAST,
47   PROP_IS_MC_GLOBAL,
48   PROP_IS_MC_LINKLOCAL,
49   PROP_IS_MC_NODELOCAL,
50   PROP_IS_MC_ORGLOCAL,
51   PROP_IS_MC_SITELOCAL,
52 };
53
54 static void
55 g_inet_address_get_property (GObject    *object,
56                              guint       prop_id,
57                              GValue     *value,
58                              GParamSpec *pspec)
59 {
60   GInetAddress *address = G_INET_ADDRESS (object);
61
62   switch (prop_id)
63     {
64       case PROP_IS_ANY:
65         g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_any (address));
66         break;
67
68       case PROP_IS_LINKLOCAL:
69         g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_linklocal (address));
70         break;
71
72       case PROP_IS_LOOPBACK:
73         g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_loopback (address));
74         break;
75
76       default:
77         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
78     }
79 }
80
81 static void
82 g_inet_address_set_property (GObject      *object,
83                              guint         prop_id,
84                              const GValue *value,
85                              GParamSpec   *pspec)
86 {
87   GInetAddress *address G_GNUC_UNUSED = G_INET_ADDRESS (object);
88
89   switch (prop_id)
90     {
91       default:
92         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
93     }
94 }
95
96 static void
97 g_inet_address_class_init (GInetAddressClass *klass)
98 {
99   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
100
101   gobject_class->get_property = g_inet_address_get_property;
102   gobject_class->set_property = g_inet_address_set_property;
103
104   g_object_class_install_property (gobject_class, PROP_IS_ANY,
105                                    g_param_spec_boolean ("is-any",
106                                                          "",
107                                                          "",
108                                                          FALSE,
109                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
110
111   g_object_class_install_property (gobject_class, PROP_IS_LINKLOCAL,
112                                    g_param_spec_boolean ("is-link-local",
113                                                          "",
114                                                          "",
115                                                          FALSE,
116                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
117
118   g_object_class_install_property (gobject_class, PROP_IS_LOOPBACK,
119                                    g_param_spec_boolean ("is-loopback",
120                                                          "",
121                                                          "",
122                                                          FALSE,
123                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
124
125   g_object_class_install_property (gobject_class, PROP_IS_SITELOCAL,
126                                    g_param_spec_boolean ("is-site-local",
127                                                          "",
128                                                          "",
129                                                          FALSE,
130                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
131
132   g_object_class_install_property (gobject_class, PROP_IS_MULTICAST,
133                                    g_param_spec_boolean ("is-multicast",
134                                                          "",
135                                                          "",
136                                                          FALSE,
137                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
138
139   g_object_class_install_property (gobject_class, PROP_IS_MC_GLOBAL,
140                                    g_param_spec_boolean ("is-mc-global",
141                                                          "",
142                                                          "",
143                                                          FALSE,
144                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
145
146   g_object_class_install_property (gobject_class, PROP_IS_MC_LINKLOCAL,
147                                    g_param_spec_boolean ("is-mc-link-local",
148                                                          "",
149                                                          "",
150                                                          FALSE,
151                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
152
153   g_object_class_install_property (gobject_class, PROP_IS_MC_NODELOCAL,
154                                    g_param_spec_boolean ("is-mc-node-local",
155                                                          "",
156                                                          "",
157                                                          FALSE,
158                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
159
160   g_object_class_install_property (gobject_class, PROP_IS_MC_ORGLOCAL,
161                                    g_param_spec_boolean ("is-mc-org-local",
162                                                          "",
163                                                          "",
164                                                          FALSE,
165                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
166
167   g_object_class_install_property (gobject_class, PROP_IS_MC_SITELOCAL,
168                                    g_param_spec_boolean ("is-mc-site-local",
169                                                          "",
170                                                          "",
171                                                          FALSE,
172                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
173 }
174
175 static void
176 g_inet_address_init (GInetAddress *address)
177 {
178
179 }
180
181 gchar *
182 g_inet_address_to_string (GInetAddress *address)
183 {
184   g_return_val_if_fail (G_IS_INET_ADDRESS (address), NULL);
185
186   return G_INET_ADDRESS_GET_CLASS (address)->to_string (address);
187 }
188
189 /* ******************************************* */
190 /* Getters for properties */
191
192 static gboolean
193 get_boolean_property (GInetAddress *address, const gchar *property)
194 {
195   gboolean value;
196
197   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
198
199   g_object_get (address, property, &value, NULL);
200
201   return value;
202 }
203
204 gboolean
205 g_inet_address_is_any (GInetAddress *address)
206 {
207   return get_boolean_property (address, "is-any");
208 }
209
210 gboolean
211 g_inet_address_is_linklocal (GInetAddress *address)
212 {
213   return get_boolean_property (address, "is-link-local");
214 }
215
216 gboolean
217 g_inet_address_is_loopback (GInetAddress *address)
218 {
219   return get_boolean_property (address, "is-loopback");
220 }
221
222 gboolean
223 g_inet_address_is_sitelocal (GInetAddress *address)
224 {
225   return get_boolean_property (address, "is-site-local");
226 }
227
228 gboolean
229 g_inet_address_is_multicast (GInetAddress *address)
230 {
231   return get_boolean_property (address, "is-multicast");
232 }
233
234 gboolean
235 g_inet_address_is_mc_global (GInetAddress *address)
236 {
237   return get_boolean_property (address, "is-mc-global");
238 }
239
240 gboolean
241 g_inet_address_is_mc_linklocal (GInetAddress *address)
242 {
243   return get_boolean_property (address, "is-mc-link-local");
244 }
245
246 gboolean
247 g_inet_address_is_mc_nodelocal (GInetAddress *address)
248 {
249   return get_boolean_property (address, "is-mc-node-local");
250 }
251
252 gboolean
253 g_inet_address_is_mc_orglocal  (GInetAddress *address)
254 {
255   return get_boolean_property (address, "is-mc-org-local");
256 }
257
258 gboolean
259 g_inet_address_is_mc_sitelocal (GInetAddress *address)
260 {
261   return get_boolean_property (address, "is-mc-site-local");
262 }
263