~ubuntu-branches/ubuntu/raring/librsvg/raring-proposed

« back to all changes in this revision

Viewing changes to rsvg-xml.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2011-01-23 19:55:29 UTC
  • mfrom: (1.1.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20110123195529-2nxp0op9yrk3qb77
Tags: 2.32.0-1
* New upstream release.
  + debian/control.in:
    - Update build dependencies.
  + debian/librsvg2-common.install,
    debian/librsvg2-dev.links:
    - Updated for the new help location.
  + debian/rules:
    - Don't run dh_makeshlibs on librsvg2-common.
* debian/source/format,
  debian/patches/*,
  debian/rules:
  + Switch to source format 3.0 (quilt).
* debian/librsvg2-2.symbols:
  + Add a symbols file.
* debian/rules:
  + Make the shlibs file always depend on the latest upstream version.
  + Abort the build if the symbols file is outdated.
  + Drop obsolete configure flag.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2010 Christian Persch
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public License as
 
6
 * published by the Free Software Foundation; either version 2.1 of the
 
7
 * License, or (at your option) any later version.
 
8
  
 
9
 * This program 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 program; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
*/
 
19
 
 
20
#include "config.h"
 
21
 
 
22
#include "rsvg-xml.h"
 
23
 
 
24
typedef struct {
 
25
    GInputStream *stream;
 
26
    GCancellable *cancellable;
 
27
    GError      **error;
 
28
} RsvgXmlInputStreamContext;
 
29
 
 
30
/* this should use gsize, but libxml2 is borked */
 
31
static int
 
32
context_read (RsvgXmlInputStreamContext *context,
 
33
              char *buffer,
 
34
              int   len)
 
35
{
 
36
    gssize n_read;
 
37
 
 
38
    if (*(context->error))
 
39
        return -1;
 
40
 
 
41
    n_read = g_input_stream_read (context->stream, buffer, (gsize) len,
 
42
                                  context->cancellable,
 
43
                                  context->error);
 
44
    if (n_read < 0)
 
45
        return -1;
 
46
 
 
47
    return (int) n_read;
 
48
}
 
49
 
 
50
static int
 
51
context_close (RsvgXmlInputStreamContext *context)
 
52
{
 
53
    gboolean ret;
 
54
 
 
55
    /* Don't overwrite a previous error */
 
56
    ret = g_input_stream_close (context->stream, context->cancellable,
 
57
                                *(context->error) == NULL ? context->error : NULL);
 
58
 
 
59
    g_object_unref (context->stream);
 
60
    if (context->cancellable)
 
61
        g_object_unref (context->cancellable);
 
62
    g_slice_free (RsvgXmlInputStreamContext, context);
 
63
 
 
64
    return ret ? 0 : -1;
 
65
}
 
66
 
 
67
/**
 
68
 * _rsvg_xml_input_buffer_new_from_stream:
 
69
 * @context: a #xmlParserCtxtPtr
 
70
 * @input_stream: a #GInputStream
 
71
 *
 
72
 * Returns: a new #xmlParserInputPtr wrapping @input_stream
 
73
 */
 
74
xmlParserInputBufferPtr
 
75
_rsvg_xml_input_buffer_new_from_stream (GInputStream   *stream,
 
76
                                        GCancellable   *cancellable,
 
77
                                        xmlCharEncoding enc,
 
78
                                        GError        **error)
 
79
 
 
80
{
 
81
    RsvgXmlInputStreamContext *context;
 
82
 
 
83
    g_return_val_if_fail (G_IS_INPUT_STREAM (stream), NULL);
 
84
    g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
 
85
    g_return_val_if_fail (error != NULL, NULL);
 
86
 
 
87
    context = g_slice_new (RsvgXmlInputStreamContext);
 
88
    context->stream = g_object_ref (stream);
 
89
    context->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
 
90
    context->error = error;
 
91
 
 
92
    return xmlParserInputBufferCreateIO ((xmlInputReadCallback) context_read,
 
93
                                         (xmlInputCloseCallback) context_close,
 
94
                                         context,
 
95
                                         enc);
 
96
}