Mercurial > pidgin
comparison libpurple/protocols/jabber/jingle/rawudp.c @ 24947:7252e3d0c627
Add files I missed committing before and remove a few unnecessary functions.
author | Mike Ruprecht <maiku@soc.pidgin.im> |
---|---|
date | Mon, 20 Oct 2008 00:11:33 +0000 |
parents | |
children | 365eb0b68d5f |
comparison
equal
deleted
inserted
replaced
24946:46387cbfaf85 | 24947:7252e3d0c627 |
---|---|
1 /** | |
2 * @file rawudp.c | |
3 * | |
4 * purple | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | |
19 */ | |
20 | |
21 #include "rawudp.h" | |
22 #include "jingle.h" | |
23 #include "debug.h" | |
24 | |
25 #include <string.h> | |
26 | |
27 struct _JingleRawUdpPrivate | |
28 { | |
29 guint generation; | |
30 gchar *id; | |
31 gchar *ip; | |
32 guint port; | |
33 }; | |
34 | |
35 #define JINGLE_RAWUDP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), JINGLE_TYPE_RAWUDP, JingleRawUdpPrivate)) | |
36 | |
37 static void jingle_rawudp_class_init (JingleRawUdpClass *klass); | |
38 static void jingle_rawudp_init (JingleRawUdp *rawudp); | |
39 static void jingle_rawudp_finalize (GObject *object); | |
40 static void jingle_rawudp_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); | |
41 static void jingle_rawudp_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); | |
42 static JingleTransport *jingle_rawudp_parse_internal(xmlnode *rawudp); | |
43 static xmlnode *jingle_rawudp_to_xml_internal(JingleTransport *transport, xmlnode *content, JingleActionType action); | |
44 | |
45 static JingleTransportClass *parent_class = NULL; | |
46 | |
47 enum { | |
48 PROP_0, | |
49 PROP_GENERATION, | |
50 PROP_ID, | |
51 PROP_IP, | |
52 PROP_PORT, | |
53 }; | |
54 | |
55 GType | |
56 jingle_rawudp_get_type() | |
57 { | |
58 static GType type = 0; | |
59 | |
60 if (type == 0) { | |
61 static const GTypeInfo info = { | |
62 sizeof(JingleRawUdpClass), | |
63 NULL, | |
64 NULL, | |
65 (GClassInitFunc) jingle_rawudp_class_init, | |
66 NULL, | |
67 NULL, | |
68 sizeof(JingleRawUdp), | |
69 0, | |
70 (GInstanceInitFunc) jingle_rawudp_init, | |
71 NULL | |
72 }; | |
73 type = g_type_register_static(JINGLE_TYPE_TRANSPORT, "JingleRawUdp", &info, 0); | |
74 } | |
75 return type; | |
76 } | |
77 | |
78 static void | |
79 jingle_rawudp_class_init (JingleRawUdpClass *klass) | |
80 { | |
81 GObjectClass *gobject_class = (GObjectClass*)klass; | |
82 parent_class = g_type_class_peek_parent(klass); | |
83 | |
84 gobject_class->finalize = jingle_rawudp_finalize; | |
85 gobject_class->set_property = jingle_rawudp_set_property; | |
86 gobject_class->get_property = jingle_rawudp_get_property; | |
87 klass->parent_class.to_xml = jingle_rawudp_to_xml_internal; | |
88 klass->parent_class.parse = jingle_rawudp_parse_internal; | |
89 klass->parent_class.transport_type = JINGLE_TRANSPORT_RAWUDP; | |
90 | |
91 g_object_class_install_property(gobject_class, PROP_GENERATION, | |
92 g_param_spec_uint("generation", | |
93 "Generation", | |
94 "The generation for this transport.", | |
95 0, | |
96 G_MAXUINT, | |
97 0, | |
98 G_PARAM_READWRITE)); | |
99 | |
100 g_object_class_install_property(gobject_class, PROP_ID, | |
101 g_param_spec_string("id", | |
102 "Id", | |
103 "The id for this transport.", | |
104 NULL, | |
105 G_PARAM_READWRITE)); | |
106 | |
107 g_object_class_install_property(gobject_class, PROP_IP, | |
108 g_param_spec_string("ip", | |
109 "IP Address", | |
110 "The IP address for this transport.", | |
111 NULL, | |
112 G_PARAM_READWRITE)); | |
113 | |
114 g_object_class_install_property(gobject_class, PROP_PORT, | |
115 g_param_spec_uint("port", | |
116 "Port", | |
117 "The port for this transport.", | |
118 0, | |
119 65535, | |
120 0, | |
121 G_PARAM_READWRITE)); | |
122 | |
123 g_type_class_add_private(klass, sizeof(JingleRawUdpPrivate)); | |
124 } | |
125 | |
126 static void | |
127 jingle_rawudp_init (JingleRawUdp *rawudp) | |
128 { | |
129 rawudp->priv = JINGLE_RAWUDP_GET_PRIVATE(rawudp); | |
130 memset(rawudp->priv, 0, sizeof(rawudp->priv)); | |
131 } | |
132 | |
133 static void | |
134 jingle_rawudp_finalize (GObject *rawudp) | |
135 { | |
136 JingleRawUdpPrivate *priv = JINGLE_RAWUDP_GET_PRIVATE(rawudp); | |
137 purple_debug_info("jingle","jingle_rawudp_finalize\n"); | |
138 | |
139 g_free(priv->id); | |
140 g_free(priv->ip); | |
141 } | |
142 | |
143 static void | |
144 jingle_rawudp_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) | |
145 { | |
146 JingleRawUdp *rawudp; | |
147 g_return_if_fail(JINGLE_IS_RAWUDP(object)); | |
148 | |
149 rawudp = JINGLE_RAWUDP(object); | |
150 | |
151 switch (prop_id) { | |
152 case PROP_GENERATION: | |
153 rawudp->priv->generation = g_value_get_uint(value); | |
154 break; | |
155 case PROP_ID: | |
156 g_free(rawudp->priv->id); | |
157 rawudp->priv->id = g_value_dup_string(value); | |
158 break; | |
159 case PROP_IP: | |
160 g_free(rawudp->priv->ip); | |
161 rawudp->priv->ip = g_value_dup_string(value); | |
162 break; | |
163 case PROP_PORT: | |
164 rawudp->priv->port = g_value_get_uint(value); | |
165 break; | |
166 default: | |
167 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
168 break; | |
169 } | |
170 } | |
171 | |
172 static void | |
173 jingle_rawudp_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) | |
174 { | |
175 JingleRawUdp *rawudp; | |
176 g_return_if_fail(JINGLE_IS_RAWUDP(object)); | |
177 | |
178 rawudp = JINGLE_RAWUDP(object); | |
179 | |
180 switch (prop_id) { | |
181 case PROP_GENERATION: | |
182 g_value_set_uint(value, rawudp->priv->generation); | |
183 break; | |
184 case PROP_ID: | |
185 g_value_set_string(value, rawudp->priv->id); | |
186 break; | |
187 case PROP_IP: | |
188 g_value_set_string(value, rawudp->priv->ip); | |
189 break; | |
190 case PROP_PORT: | |
191 g_value_set_uint(value, rawudp->priv->port); | |
192 break; | |
193 default: | |
194 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | |
195 break; | |
196 } | |
197 } | |
198 | |
199 JingleRawUdp * | |
200 jingle_rawudp_create(guint generation, const gchar *id, const gchar *ip, guint port) | |
201 { | |
202 return g_object_new(jingle_rawudp_get_type(), | |
203 "generation", generation, | |
204 "id", id, | |
205 "ip", ip, | |
206 "port", port, NULL); | |
207 } | |
208 | |
209 static JingleTransport * | |
210 jingle_rawudp_parse_internal(xmlnode *rawudp) | |
211 { | |
212 JingleTransport *transport = parent_class->parse(rawudp); | |
213 | |
214 return transport; | |
215 } | |
216 | |
217 static xmlnode * | |
218 jingle_rawudp_to_xml_internal(JingleTransport *transport, xmlnode *content, JingleActionType action) | |
219 { | |
220 xmlnode *node = parent_class->to_xml(transport, content, action); | |
221 | |
222 if (action == JINGLE_SESSION_INITIATE || action == JINGLE_TRANSPORT_INFO) { | |
223 xmlnode *xmltransport = xmlnode_new_child(node, "candidate"); | |
224 JingleRawUdpPrivate *priv = JINGLE_RAWUDP_GET_PRIVATE(transport); | |
225 gchar *generation = g_strdup_printf("%d", priv->generation); | |
226 gchar *port = g_strdup_printf("%d", priv->port); | |
227 | |
228 xmlnode_set_attrib(xmltransport, "generation", generation); | |
229 xmlnode_set_attrib(xmltransport, "id", priv->id); | |
230 xmlnode_set_attrib(xmltransport, "ip", priv->ip); | |
231 xmlnode_set_attrib(xmltransport, "port", port); | |
232 | |
233 g_free(port); | |
234 g_free(generation); | |
235 } | |
236 | |
237 return node; | |
238 } | |
239 |