1 | /* |
2 | * Copyright (C) 2013 Company 100 Inc. |
3 | * |
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 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. |
13 | * |
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, Boston, MA 02110-1301 USA |
17 | */ |
18 | |
19 | #include "config.h" |
20 | |
21 | #if USE(SOUP) |
22 | |
23 | #include "SharedBuffer.h" |
24 | |
25 | #include <libsoup/soup.h> |
26 | |
27 | namespace WebCore { |
28 | |
29 | SharedBuffer::SharedBuffer(SoupBuffer* soupBuffer) |
30 | { |
31 | ASSERT(soupBuffer); |
32 | m_size = soupBuffer->length; |
33 | m_segments.append({0, DataSegment::create(GUniquePtr<SoupBuffer>(soupBuffer))}); |
34 | } |
35 | |
36 | Ref<SharedBuffer> SharedBuffer::wrapSoupBuffer(SoupBuffer* soupBuffer) |
37 | { |
38 | return adoptRef(*new SharedBuffer(soupBuffer)); |
39 | } |
40 | |
41 | GUniquePtr<SoupBuffer> SharedBuffer::createSoupBuffer(unsigned offset, unsigned size) |
42 | { |
43 | ref(); |
44 | GUniquePtr<SoupBuffer> buffer(soup_buffer_new_with_owner(data() + offset, size ? size : this->size(), this, [](void* data) { |
45 | static_cast<SharedBuffer*>(data)->deref(); |
46 | })); |
47 | return buffer; |
48 | } |
49 | |
50 | } // namespace WebCore |
51 | |
52 | #endif |
53 | |