1/*
2 * Copyright (C) 2012 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 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 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21#include "WebKitSoupRequestGeneric.h"
22
23#include "ResourceRequest.h"
24#include <wtf/text/CString.h>
25
26using namespace WebCore;
27
28G_DEFINE_TYPE(WebKitSoupRequestGeneric, webkit_soup_request_generic, SOUP_TYPE_REQUEST)
29
30struct _WebKitSoupRequestGenericPrivate {
31 CString mimeType;
32 goffset contentLength;
33 ResourceRequest resourceRequest;
34};
35
36static void webkitSoupRequestGenericFinalize(GObject* object)
37{
38 WEBKIT_SOUP_REQUEST_GENERIC(object)->priv->~WebKitSoupRequestGenericPrivate();
39 G_OBJECT_CLASS(webkit_soup_request_generic_parent_class)->finalize(object);
40}
41
42static void webkit_soup_request_generic_init(WebKitSoupRequestGeneric* request)
43{
44 WebKitSoupRequestGenericPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(request, WEBKIT_TYPE_SOUP_REQUEST_GENERIC, WebKitSoupRequestGenericPrivate);
45 request->priv = priv;
46 new (priv) WebKitSoupRequestGenericPrivate();
47}
48
49static void webkitSoupRequestGenericSendAsync(SoupRequest* request, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData)
50{
51 WebKitSoupRequestGenericClient* client = WEBKIT_SOUP_REQUEST_GENERIC_GET_CLASS(request)->client;
52 ASSERT(client);
53 client->startRequest(adoptGRef(g_task_new(request, cancellable, callback, userData)));
54}
55
56static GInputStream* webkitSoupRequestGenericSendFinish(SoupRequest* request, GAsyncResult* result, GError** error)
57{
58 g_return_val_if_fail(g_task_is_valid(result, request), nullptr);
59 auto* inputStream = g_task_propagate_pointer(G_TASK(result), error);
60 return inputStream ? G_INPUT_STREAM(inputStream) : nullptr;
61}
62
63static goffset webkitSoupRequestGenericGetContentLength(SoupRequest* request)
64{
65 return WEBKIT_SOUP_REQUEST_GENERIC(request)->priv->contentLength;
66}
67
68static const char* webkitSoupRequestGenericGetContentType(SoupRequest* request)
69{
70 return WEBKIT_SOUP_REQUEST_GENERIC(request)->priv->mimeType.data();
71}
72
73static void webkit_soup_request_generic_class_init(WebKitSoupRequestGenericClass* requestGenericClass)
74{
75 GObjectClass* gObjectClass = G_OBJECT_CLASS(requestGenericClass);
76 gObjectClass->finalize = webkitSoupRequestGenericFinalize;
77
78 SoupRequestClass* requestClass = SOUP_REQUEST_CLASS(requestGenericClass);
79 requestClass->send_async = webkitSoupRequestGenericSendAsync;
80 requestClass->send_finish = webkitSoupRequestGenericSendFinish;
81 requestClass->get_content_length = webkitSoupRequestGenericGetContentLength;
82 requestClass->get_content_type = webkitSoupRequestGenericGetContentType;
83
84 g_type_class_add_private(requestGenericClass, sizeof(WebKitSoupRequestGenericPrivate));
85}
86
87void webkitSoupRequestGenericSetContentLength(WebKitSoupRequestGeneric* request, goffset contentLength)
88{
89 request->priv->contentLength = contentLength;
90}
91
92void webkitSoupRequestGenericSetContentType(WebKitSoupRequestGeneric* request, const char* mimeType)
93{
94 request->priv->mimeType = mimeType;
95}
96
97void webkitSoupRequestGenericSetRequest(WebKitSoupRequestGeneric* request, const ResourceRequest& resourceRequest)
98{
99 request->priv->resourceRequest = resourceRequest;
100}
101
102const ResourceRequest& webkitSoupRequestGenericGetRequest(WebKitSoupRequestGeneric* request)
103{
104 return request->priv->resourceRequest;
105}
106