First set of changes for windows
[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_OBJECT);
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, guint prop_id, GValue *value, GParamSpec *pspec)
56 {
57   GInetAddress *address = G_INET_ADDRESS (object);
58
59   switch (prop_id)
60     {
61       case PROP_IS_ANY:
62         g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_any (address));
63         break;
64
65       case PROP_IS_LINKLOCAL:
66         g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_linklocal (address));
67         break;
68
69       case PROP_IS_LOOPBACK:
70         g_value_set_boolean (value, G_INET_ADDRESS_GET_CLASS (address)->is_loopback (address));
71         break;
72
73       default:
74         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
75     }
76 }
77
78 static void
79 g_inet_address_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
80 {
81   GInetAddress *address G_GNUC_UNUSED = G_INET_ADDRESS (object);
82
83   switch (prop_id)
84     {
85       default:
86         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
87     }
88 }
89
90 static void
91 g_inet_address_class_init (GInetAddressClass *klass)
92 {
93   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
94
95   gobject_class->get_property = g_inet_address_get_property;
96   gobject_class->set_property = g_inet_address_set_property;
97
98   g_object_class_install_property (gobject_class, PROP_IS_ANY,
99                                    g_param_spec_boolean ("is-any",
100                                                          "",
101                                                          "",
102                                                          FALSE,
103                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
104
105   g_object_class_install_property (gobject_class, PROP_IS_LINKLOCAL,
106                                    g_param_spec_boolean ("is-link-local",
107                                                          "",
108                                                          "",
109                                                          FALSE,
110                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
111
112   g_object_class_install_property (gobject_class, PROP_IS_LOOPBACK,
113                                    g_param_spec_boolean ("is-loopback",
114                                                          "",
115                                                          "",
116                                                          FALSE,
117                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
118
119   g_object_class_install_property (gobject_class, PROP_IS_SITELOCAL,
120                                    g_param_spec_boolean ("is-site-local",
121                                                          "",
122                                                          "",
123                                                          FALSE,
124                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
125
126   g_object_class_install_property (gobject_class, PROP_IS_MULTICAST,
127                                    g_param_spec_boolean ("is-multicast",
128                                                          "",
129                                                          "",
130                                                          FALSE,
131                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
132
133   g_object_class_install_property (gobject_class, PROP_IS_MC_GLOBAL,
134                                    g_param_spec_boolean ("is-mc-global",
135                                                          "",
136                                                          "",
137                                                          FALSE,
138                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
139
140   g_object_class_install_property (gobject_class, PROP_IS_MC_LINKLOCAL,
141                                    g_param_spec_boolean ("is-mc-link-local",
142                                                          "",
143                                                          "",
144                                                          FALSE,
145                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
146
147   g_object_class_install_property (gobject_class, PROP_IS_MC_NODELOCAL,
148                                    g_param_spec_boolean ("is-mc-node-local",
149                                                          "",
150                                                          "",
151                                                          FALSE,
152                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
153
154   g_object_class_install_property (gobject_class, PROP_IS_MC_ORGLOCAL,
155                                    g_param_spec_boolean ("is-mc-org-local",
156                                                          "",
157                                                          "",
158                                                          FALSE,
159                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
160
161   g_object_class_install_property (gobject_class, PROP_IS_MC_SITELOCAL,
162                                    g_param_spec_boolean ("is-mc-site-local",
163                                                          "",
164                                                          "",
165                                                          FALSE,
166                                                          G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME));
167 }
168
169 static void
170 g_inet_address_init (GInetAddress *address)
171 {
172
173 }
174
175 /* ******************************************* */
176 /* Getters for properties */
177
178 static gboolean
179 get_boolean_property (GInetAddress *address, const gchar *property)
180 {
181   gboolean value;
182
183   g_return_val_if_fail (G_IS_INET_ADDRESS (address), FALSE);
184
185   g_object_get (address, property, &value, NULL);
186
187   return value;
188 }
189
190 gboolean
191 g_inet_address_is_any (GInetAddress *address)
192 {
193   return get_boolean_property (address, "is-any");
194 }
195
196 gboolean
197 g_inet_address_is_linklocal (GInetAddress *address)
198 {
199   return get_boolean_property (address, "is-link-local");
200 }
201
202 gboolean
203 g_inet_address_is_loopback (GInetAddress *address)
204 {
205   return get_boolean_property (address, "is-loopback");
206 }
207
208 gboolean
209 g_inet_address_is_sitelocal (GInetAddress *address)
210 {
211   return get_boolean_property (address, "is-site-local");
212 }
213
214 gboolean
215 g_inet_address_is_multicast (GInetAddress *address)
216 {
217   return get_boolean_property (address, "is-multicast");
218 }
219
220 gboolean
221 g_inet_address_is_mc_global (GInetAddress *address)
222 {
223   return get_boolean_property (address, "is-mc-global");
224 }
225
226 gboolean
227 g_inet_address_is_mc_linklocal (GInetAddress *address)
228 {
229   return get_boolean_property (address, "is-mc-link-local");
230 }
231
232 gboolean
233 g_inet_address_is_mc_nodelocal (GInetAddress *address)
234 {
235   return get_boolean_property (address, "is-mc-node-local");
236 }
237
238 gboolean
239 g_inet_address_is_mc_orglocal  (GInetAddress *address)
240 {
241   return get_boolean_property (address, "is-mc-org-local");
242 }
243
244 gboolean
245 g_inet_address_is_mc_sitelocal (GInetAddress *address)
246 {
247   return get_boolean_property (address, "is-mc-site-local");
248 }
249