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.
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
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
)
39 swfdec_net_connection_dispose (GObject
*object
)
41 SwfdecNetConnection
*conn
= SWFDEC_NET_CONNECTION (object
);
46 G_OBJECT_CLASS (swfdec_net_connection_parent_class
)->dispose (object
);
50 swfdec_net_connection_class_init (SwfdecNetConnectionClass
*klass
)
52 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
54 object_class
->dispose
= swfdec_net_connection_dispose
;
58 swfdec_net_connection_init (SwfdecNetConnection
*net_connection
)
63 swfdec_net_connection_onstatus (SwfdecNetConnection
*conn
, const char *code
,
64 const char *level
, const char *description
)
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
);
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
);
83 swfdec_net_connection_connect (SwfdecNetConnection
*conn
, const char *url
)
85 g_return_if_fail (SWFDEC_IS_NET_CONNECTION (conn
));
88 conn
->url
= g_strdup (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
);
98 SWFDEC_AS_NATIVE (2100, 0, swfdec_net_connection_do_connect
)
100 swfdec_net_connection_do_connect (SwfdecAsContext
*cx
, SwfdecAsObject
*object
,
101 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
103 SwfdecNetConnection
*conn
;
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
)) {
114 SWFDEC_FIXME ("untested argument to NetConnection.connect: type %u",
115 SWFDEC_AS_VALUE_GET_TYPE (val
));
118 swfdec_net_connection_connect (conn
, url
);
121 SWFDEC_AS_NATIVE (2100, 1, swfdec_net_connection_do_close
)
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
)
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
)
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
)
147 swfdec_net_connection_get_connectedProxyType (SwfdecAsContext
*cx
,
148 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
151 SWFDEC_STUB ("NetConnection.connectedProxyType (get)");
154 SWFDEC_AS_NATIVE (2100, 5, swfdec_net_connection_get_usingTLS
)
156 swfdec_net_connection_get_usingTLS (SwfdecAsContext
*cx
,
157 SwfdecAsObject
*object
, guint argc
, SwfdecAsValue
*argv
,
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
)
166 swfdec_net_connection_construct (SwfdecAsContext
*cx
, SwfdecAsObject
*obj
,
167 guint argc
, SwfdecAsValue
*argv
, SwfdecAsValue
*rval
)
169 SwfdecNetConnection
*conn
;
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
));