Patch from Samuel Cormier-Iijima <sciyoshi@gmail.com>:
[cascardo/gnio.git] / gnio / ginetaddress.c
1 /* GNIO - GLib Network Layer of GIO
2  * 
3  * Copyright (C) 2008 Christian Kellner 
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  * Author: Christian Kellner <gicmo@gnome.org>
21  */
22
23 #include <config.h>
24 #include <glib.h>
25
26 #include "ginetaddress.h"
27
28 /**
29  * SECTION:ginetaddress
30  * @short_description: Base class for implementing IPv4/IPv6 classes
31  *
32  * 
33  * 
34  **/
35
36 G_DEFINE_ABSTRACT_TYPE (GInetAddress, g_inet_address, G_TYPE_OBJECT);
37
38 enum
39 {
40   PROP_0,
41   PROP_IS_ANY,
42   PROP_IS_LINKLOCAL,
43   PROP_IS_LOOPBACK,
44   PROP_IS_SITELOCAL,
45   PROP_IS_MULTICAST,
46   PROP_IS_MC_GLOBAL,
47   PROP_IS_MC_LINKLOCAL,
48   PROP_IS_MC_NODELOCAL,
49   PROP_IS_MC_ORGLOCAL,
50   PROP_IS_MC_SITELOCAL,
51 };
52
53 static void
54 g_inet_address_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
55 {
56   GInetAddress *address = G_INET_ADDRESS (object);
57
58   switch (prop_id)
59     {
60       case PROP_IS_ANY:
61         g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_any (address));
62         break;
63
64       case PROP_IS_LINKLOCAL:
65         g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_linklocal (address));
66         break;
67
68       case PROP_IS_LOOPBACK:
69         g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_loopback (address));
70         break;
71
72       default:
73         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
74     }
75 }
76
77 static void
78 g_inet_address_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
79 {
80   GInetAddress *address G_GNUC_UNUSED = G_INET_ADDRESS (object);
81
82   switch (prop_id)
83     {
84       default:
85         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
86     }
87 }
88
89 static void
90 g_inet_address_class_init (GInetAddressClass *klass)
91 {
92   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
93
94   gobject_class->get_property = g_inet_address_get_property;
95   gobject_class->set_property = g_inet_address_set_property;
96
97   g_object_class_install_property (gobject_class, PROP_IS_ANY,
98                                    g_param_spec_boolean ("is-any",
99                                                          "",
100                                                          "",
101                                                          FALSE,
102                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
103
104   g_object_class_install_property (gobject_class, PROP_IS_LINKLOCAL,
105                                    g_param_spec_boolean ("is-link-local",
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_LOOPBACK,
112                                    g_param_spec_boolean ("is-loopback",
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_SITELOCAL,
119                                    g_param_spec_boolean ("is-site-local",
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_MULTICAST,
126                                    g_param_spec_boolean ("is-multicast",
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_MC_GLOBAL,
133                                    g_param_spec_boolean ("is-mc-global",
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_LINKLOCAL,
140                                    g_param_spec_boolean ("is-mc-link-local",
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_NODELOCAL,
147                                    g_param_spec_boolean ("is-mc-node-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_ORGLOCAL,
154                                    g_param_spec_boolean ("is-mc-org-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_SITELOCAL,
161                                    g_param_spec_boolean ("is-mc-site-local",
162                                                          "",
163                                                          "",
164                                                          FALSE,
165                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
166 }
167
168 static void
169 g_inet_address_init (GInetAddress *address)
170 {
171
172 }
173
174 /* ******************************************* */
175 /* Getters for properties */
176
177 static gboolean
178 get_boolean_property (GInetAddress *address, const gchar *property)
179 {
180   gboolean value;
181
182   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
183
184   g_object_get (address, property, &value, NULL);
185
186   return value;
187 }
188
189 gboolean
190 g_inet_address_is_any (GInetAddress *address)
191 {
192   return get_boolean_property (address, "is-any");
193 }
194
195 gboolean
196 g_inet_address_is_linklocal (GInetAddress *address)
197 {
198   return get_boolean_property (address, "is-link-local");
199 }
200
201 gboolean
202 g_inet_address_is_loopback (GInetAddress *address)
203 {
204   return get_boolean_property (address, "is-loopback");
205 }
206
207 gboolean
208 g_inet_address_is_sitelocal (GInetAddress *address)
209 {
210   return get_boolean_property (address, "is-site-local");
211 }
212
213 gboolean
214 g_inet_address_is_multicast (GInetAddress *address)
215 {
216   return get_boolean_property (address, "is-multicast");
217 }
218
219 gboolean
220 g_inet_address_is_mc_global (GInetAddress *address)
221 {
222   return get_boolean_property (address, "is-mc-global");
223 }
224
225 gboolean
226 g_inet_address_is_mc_linklocal (GInetAddress *address)
227 {
228   return get_boolean_property (address, "is-mc-link-local");
229 }
230
231 gboolean
232 g_inet_address_is_mc_nodelocal (GInetAddress *address)
233 {
234   return get_boolean_property (address, "is-mc-node-local");
235 }
236
237 gboolean
238 g_inet_address_is_mc_orglocal  (GInetAddress *address)
239 {
240   return get_boolean_property (address, "is-mc-org-local");
241 }
242
243 gboolean
244 g_inet_address_is_mc_sitelocal (GInetAddress *address)
245 {
246   return get_boolean_property (address, "is-mc-site-local");
247 }
248