add blend mode tests
[swfdec.git] / swfdec / swfdec_net_connection.c
blob25da84ba8f01c9ffb3dd57bcc957db734e1de286
1 /* Swfdec
2 * Copyright (C) 2007 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
24 #include <string.h>
25 #include "swfdec_net_connection.h"
26 #include "swfdec_as_context.h"
27 #include "swfdec_as_native_function.h"
28 #include "swfdec_as_internal.h"
29 #include "swfdec_as_object.h"
30 #include "swfdec_as_strings.h"
31 #include "swfdec_debug.h"
32 #include "swfdec_internal.h"
34 /*** SwfdecNetConnection ***/
36 G_DEFINE_TYPE (SwfdecNetConnection, swfdec_net_connection, SWFDEC_TYPE_AS_RELAY)
38 static void
39 swfdec_net_connection_dispose (GObject *object)
41 SwfdecNetConnection *conn = SWFDEC_NET_CONNECTION (object);
43 g_free (conn->url);
44 conn->url = NULL;
46 G_OBJECT_CLASS (swfdec_net_connection_parent_class)->dispose (object);
49 static void
50 swfdec_net_connection_class_init (SwfdecNetConnectionClass *klass)
52 GObjectClass *object_class = G_OBJECT_CLASS (klass);
54 object_class->dispose = swfdec_net_connection_dispose;
57 static void
58 swfdec_net_connection_init (SwfdecNetConnection *net_connection)
62 static void
63 swfdec_net_connection_onstatus (SwfdecNetConnection *conn, const char *code,
64 const char *level, const char *description)
66 SwfdecAsValue value;
67 SwfdecAsObject *info;
69 info = swfdec_as_object_new (swfdec_gc_object_get_context (conn), SWFDEC_AS_STR_Object, NULL);
70 SWFDEC_AS_VALUE_SET_STRING (&value, code);
71 swfdec_as_object_set_variable (info, SWFDEC_AS_STR_code, &value);
72 SWFDEC_AS_VALUE_SET_STRING (&value, level);
73 swfdec_as_object_set_variable (info, SWFDEC_AS_STR_level, &value);
74 if (description) {
75 SWFDEC_AS_VALUE_SET_STRING (&value, description);
76 swfdec_as_object_set_variable (info, SWFDEC_AS_STR_description, &value);
78 SWFDEC_AS_VALUE_SET_OBJECT (&value, info);
79 swfdec_as_relay_call (SWFDEC_AS_RELAY(conn), SWFDEC_AS_STR_onStatus, 1, &value, NULL);
82 void
83 swfdec_net_connection_connect (SwfdecNetConnection *conn, const char *url)
85 g_return_if_fail (SWFDEC_IS_NET_CONNECTION (conn));
87 g_free (conn->url);
88 conn->url = g_strdup (url);
89 if (url) {
90 SWFDEC_FIXME ("NetConnection with non-null URL %s (aka RTMP) not implemented", url);
92 swfdec_net_connection_onstatus (conn, SWFDEC_AS_STR_NetConnection_Connect_Success,
93 SWFDEC_AS_STR_status, NULL);
96 /*** AS CODE ***/
98 SWFDEC_AS_NATIVE (2100, 0, swfdec_net_connection_do_connect)
99 void
100 swfdec_net_connection_do_connect (SwfdecAsContext *cx, SwfdecAsObject *object,
101 guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
103 SwfdecNetConnection *conn;
104 SwfdecAsValue val;
105 const char *url;
107 SWFDEC_AS_CHECK (SWFDEC_TYPE_NET_CONNECTION, &conn, "v", &val);
109 if (SWFDEC_AS_VALUE_IS_STRING (val)) {
110 url = SWFDEC_AS_VALUE_GET_STRING (val);
111 } else if (SWFDEC_AS_VALUE_IS_NULL (val)) {
112 url = NULL;
113 } else {
114 SWFDEC_FIXME ("untested argument to NetConnection.connect: type %u",
115 SWFDEC_AS_VALUE_GET_TYPE (val));
116 url = NULL;
118 swfdec_net_connection_connect (conn, url);
121 SWFDEC_AS_NATIVE (2100, 1, swfdec_net_connection_do_close)
122 void
123 swfdec_net_connection_do_close (SwfdecAsContext *cx, SwfdecAsObject *object,
124 guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
126 SWFDEC_STUB ("NetConnection.close");
129 SWFDEC_AS_NATIVE (2100, 2, swfdec_net_connection_do_call)
130 void
131 swfdec_net_connection_do_call (SwfdecAsContext *cx, SwfdecAsObject *object,
132 guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
134 SWFDEC_STUB ("NetConnection.call");
137 SWFDEC_AS_NATIVE (2100, 3, swfdec_net_connection_do_addHeader)
138 void
139 swfdec_net_connection_do_addHeader (SwfdecAsContext *cx, SwfdecAsObject *object,
140 guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
142 SWFDEC_STUB ("NetConnection.addHeader");
145 SWFDEC_AS_NATIVE (2100, 4, swfdec_net_connection_get_connectedProxyType)
146 void
147 swfdec_net_connection_get_connectedProxyType (SwfdecAsContext *cx,
148 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
149 SwfdecAsValue *rval)
151 SWFDEC_STUB ("NetConnection.connectedProxyType (get)");
154 SWFDEC_AS_NATIVE (2100, 5, swfdec_net_connection_get_usingTLS)
155 void
156 swfdec_net_connection_get_usingTLS (SwfdecAsContext *cx,
157 SwfdecAsObject *object, guint argc, SwfdecAsValue *argv,
158 SwfdecAsValue *rval)
160 SWFDEC_STUB ("NetConnection.usingTLS (get)");
163 // not actually the constructor, but called from the constructor
164 SWFDEC_AS_NATIVE (2100, 200, swfdec_net_connection_construct)
165 void
166 swfdec_net_connection_construct (SwfdecAsContext *cx, SwfdecAsObject *obj,
167 guint argc, SwfdecAsValue *argv, SwfdecAsValue *rval)
169 SwfdecNetConnection *conn;
171 if (obj == NULL)
172 return;
174 conn = g_object_new (SWFDEC_TYPE_NET_CONNECTION, "context", cx, NULL);
175 // FIXME: Set contentType and possible do some other stuff too
176 swfdec_as_object_set_relay (obj, SWFDEC_AS_RELAY (conn));