1 /*
2  * gnome-keyring
3  *
4  * Copyright (C) 2008 Stefan Walter
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as
8  * published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #if !defined (__GCR_INSIDE_HEADER__) && !defined (GCR_COMPILATION)
21 #error "Only <gcr/gcr.h> or <gcr/gcr-base.h> can be included directly."
22 #endif
23 
24 #ifndef __GCR_PARSER_H__
25 #define __GCR_PARSER_H__
26 
27 #include <glib-object.h>
28 #include <gio/gio.h>
29 
30 #include "gcr-types.h"
31 
32 G_BEGIN_DECLS
33 
34 #define GCR_TYPE_PARSER               (gcr_parser_get_type ())
35 #define GCR_PARSER(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCR_TYPE_PARSER, GcrParser))
36 #define GCR_PARSER_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GCR_TYPE_PARSER, GcrParserClass))
37 #define GCR_IS_PARSER(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCR_TYPE_PARSER))
38 #define GCR_IS_PARSER_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), GCR_TYPE_PARSER))
39 #define GCR_PARSER_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GCR_TYPE_PARSER, GcrParserClass))
40 
41 typedef struct _GcrParser GcrParser;
42 typedef struct _GcrParserClass GcrParserClass;
43 typedef struct _GcrParserPrivate GcrParserPrivate;
44 typedef struct _GcrParsed GcrParsed;
45 
46 struct _GcrParser {
47 	GObject parent;
48 
49 	/*< private >*/
50 	GcrParserPrivate *pv;
51 };
52 
53 struct _GcrParserClass {
54 	GObjectClass parent_class;
55 
56 	/* signals --------------------------------------------------------- */
57 
58 	/* A callback for each password needed */
59 	gboolean (*authenticate) (GcrParser *self, gint count);
60 
61 	void     (*parsed) (GcrParser *self);
62 };
63 
64 GType                    gcr_parser_get_type               (void);
65 
66 GcrParser*               gcr_parser_new                    (void);
67 
68 void                     gcr_parser_format_enable          (GcrParser *self,
69                                                             GcrDataFormat format);
70 
71 void                     gcr_parser_format_disable         (GcrParser *self,
72                                                             GcrDataFormat format);
73 
74 gboolean                 gcr_parser_format_supported       (GcrParser *self,
75                                                             GcrDataFormat format);
76 
77 gboolean                 gcr_parser_parse_bytes            (GcrParser *self,
78                                                             GBytes *data,
79                                                             GError **error);
80 
81 gboolean                 gcr_parser_parse_data             (GcrParser *self,
82                                                             const guchar *data,
83                                                             gsize n_data,
84                                                             GError **error);
85 
86 gboolean                 gcr_parser_parse_stream           (GcrParser *self,
87                                                             GInputStream *input,
88                                                             GCancellable *cancellable,
89                                                             GError **error);
90 
91 void                     gcr_parser_parse_stream_async     (GcrParser *self,
92                                                             GInputStream *input,
93                                                             GCancellable *cancellable,
94                                                             GAsyncReadyCallback callback,
95                                                             gpointer user_data);
96 
97 gboolean                 gcr_parser_parse_stream_finish    (GcrParser *self,
98                                                             GAsyncResult *result,
99                                                             GError **error);
100 
101 void                     gcr_parser_add_password           (GcrParser *self,
102                                                             const gchar *password);
103 
104 GcrParsed *              gcr_parser_get_parsed             (GcrParser *self);
105 
106 const gchar*             gcr_parser_get_parsed_label       (GcrParser *self);
107 
108 const gchar*             gcr_parser_get_parsed_description (GcrParser *self);
109 
110 GckAttributes*           gcr_parser_get_parsed_attributes  (GcrParser *self);
111 
112 const guchar *           gcr_parser_get_parsed_block       (GcrParser *self,
113                                                             gsize *n_block);
114 
115 GBytes *                 gcr_parser_get_parsed_bytes       (GcrParser *self);
116 
117 GcrDataFormat            gcr_parser_get_parsed_format      (GcrParser *self);
118 
119 const gchar*             gcr_parser_get_filename           (GcrParser *self);
120 
121 void                     gcr_parser_set_filename           (GcrParser *self,
122 		                                            const gchar *filename);
123 
124 #define                  GCR_TYPE_PARSED                   (gcr_parsed_get_type ())
125 
126 GType                    gcr_parsed_get_type               (void) G_GNUC_CONST;
127 
128 GcrParsed *              gcr_parsed_ref                    (GcrParsed *parsed);
129 
130 void                     gcr_parsed_unref                  (gpointer parsed);
131 
132 const gchar*             gcr_parsed_get_label              (GcrParsed *parsed);
133 
134 const gchar*             gcr_parsed_get_description        (GcrParsed *parsed);
135 
136 GckAttributes*           gcr_parsed_get_attributes         (GcrParsed *parsed);
137 
138 const guchar *           gcr_parsed_get_data               (GcrParsed *parsed,
139                                                             gsize *n_data);
140 
141 GBytes *                 gcr_parsed_get_bytes              (GcrParsed *parsed);
142 
143 GcrDataFormat            gcr_parsed_get_format             (GcrParsed *parsed);
144 
145 const gchar*             gcr_parsed_get_filename           (GcrParsed *parsed);
146 
147 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GcrParsed, g_object_unref)
148 
149 G_END_DECLS
150 
151 #endif /* __GCR_PARSER_H__ */
152