Merge lp:~kamstrup/couchdb-glib/couchdb-glib-gtkdoc into lp:couchdb-glib
- couchdb-glib-gtkdoc
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Rodrigo Moya |
Approved revision: | 117 |
Merge reported by: | dobey |
Merged at revision: | not available |
Proposed branch: | lp:~kamstrup/couchdb-glib/couchdb-glib-gtkdoc |
Merge into: | lp:couchdb-glib |
Diff against target: |
3027 lines 32 files modified
Makefile.am (+13/-2) NOTES.kamstrup (+32/-0) configure.ac (+9/-0) couchdb-glib/Makefile.am (+17/-5) couchdb-glib/couchdb-database-info.c (+151/-0) couchdb-glib/couchdb-database-info.h (+59/-0) couchdb-glib/couchdb-document-contact.c (+10/-10) couchdb-glib/couchdb-document-contact.h (+9/-2) couchdb-glib/couchdb-document-info.c (+107/-0) couchdb-glib/couchdb-document-info.h (+45/-0) couchdb-glib/couchdb-document.c (+38/-20) couchdb-glib/couchdb-document.h (+134/-0) couchdb-glib/couchdb-glib.h (+13/-108) couchdb-glib/couchdb-struct-field.c (+291/-0) couchdb-glib/couchdb-struct-field.h (+68/-0) couchdb-glib/couchdb-types.c (+0/-466) couchdb-glib/couchdb-types.h (+0/-89) couchdb-glib/couchdb.c (+214/-31) couchdb-glib/couchdb.h (+84/-0) couchdb-glib/dbwatch.c (+7/-7) couchdb-glib/dbwatch.h (+3/-1) couchdb-glib/utils.c (+0/-144) couchdb-glib/utils.h (+4/-75) debian/control (+12/-0) debian/libcouchdb-glib-doc.install (+1/-0) debian/rules (+2/-0) doc/Makefile.am (+4/-0) doc/reference/Makefile.am (+67/-0) doc/reference/couchdb-glib-docs.sgml (+19/-0) doc/reference/couchdb-glib.types (+6/-0) tests/test-couchdb-glib.c (+13/-3) tests/test-list-databases.c (+9/-2) |
To merge this branch: | bzr merge lp:~kamstrup/couchdb-glib/couchdb-glib-gtkdoc |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rodrigo Moya (community) | Approve | ||
Tim Cole (community) | Approve | ||
Review via email: mp+12917@code.launchpad.net |
Commit message
Description of the change
Mikkel Kamstrup Erlandsen (kamstrup) wrote : | # |
Mikkel Kamstrup Erlandsen (kamstrup) wrote : | # |
I should also add that I also want to start writing some of the actual documentation once I start on the rest of my TODOs. Currently we just generate empty gtk-doc.
Rodrigo Moya (rodrigo-moya) wrote : | # |
Code-wise it looks ok to me, too big a change to merge into the current tree (for karmic), so I need to make a branch on GNOME's GIT, and import that into bazaar so that that becomes the tree for karmic merge proposals.
Running now the tests...
Mikkel Kamstrup Erlandsen (kamstrup) wrote : | # |
> Code-wise it looks ok to me, too big a change to merge into the current tree
> (for karmic), so I need to make a branch on GNOME's GIT, and import that into
> bazaar so that that becomes the tree for karmic merge proposals.
Yeah, agreed. So if I understand correctly, I keep it here as a Bzr tree on LP? If you would rather have a Git branch on Gnome's Git server then I can do that too.
Rodrigo Moya (rodrigo-moya) wrote : | # |
> > Code-wise it looks ok to me, too big a change to merge into the current tree
> > (for karmic), so I need to make a branch on GNOME's GIT, and import that
> into
> > bazaar so that that becomes the tree for karmic merge proposals.
>
> Yeah, agreed. So if I understand correctly, I keep it here as a Bzr tree on
> LP? If you would rather have a Git branch on Gnome's Git server then I can do
> that too.
well, if you can do that, that would be better. But no need to create a GIT branch, let me first find out how to import a GIT branch into LP (so that we use that for karmic merge proposals), and then, once the GIT branch has been created (doing it now), you can just commit to GIT trunk
- 115. By Mikkel Kamstrup Erlandsen
-
Update TODO
Rodrigo Moya (rodrigo-moya) wrote : | # |
ok, so there is no way to import GIT branches into LP, so we will be doing manual code review (sending patches to an internal list) for the next few weeks from the gnome-2-28 branch I've created in GIT.
So, I'll approve your branch as soon as this other branch (https:/
Tim Cole (tcole) wrote : | # |
The refcounting logic is unsafe as written; correct refcounting in the multithreaded case can be subtle and not something I would recommend attempting on your own.
(Is there a reason to use a boxed type rather than deriving from gobject, which has correct refcounting?)
The two biggest thread-related issues are with _unref; first, there is a race between the read of the refcount and acting on it, and secondly g_atomic_
The requirements for refcounting here are at least a little simpler than gobject's (since I don't think you have to worry about e.g. revivification or weak/floating refs); if you were to continue with a boxed type, a correct implementation for your simple case would look something like this:
CouchDBDatabas
couchdb_
{
g_return_
g_return_
g_atomic_
return dbinfo;
}
void
couchdb_
{
gboolean is_zero;
g_return_if_fail (dbinfo != NULL);
g_return_if_fail (dbinfo->ref_count > 0);
is_zero = g_atomic_
if (is_zero) {
g_free (dbinfo->dbname);
g_slice_free (CouchDBDatabas
}
}
(Also, is single-space-indent acceptable from a CodingStyle point of view?)
Mikkel Kamstrup Erlandsen (kamstrup) wrote : | # |
> The refcounting logic is unsafe as written; correct refcounting in the
> multithreaded case can be subtle and not something I would recommend
> attempting on your own.
Note that I didn't change any of this code - I simply moved it around. I intentionally kept the branch API stable. I don't think it would be a good idea to block the merging of this branch because of this issue.
I agree however, that we could just as well use full GObjects everywhere we use custom boxed types (DatabaseInfo, DocumentInfo, and StructField as far as I recall). But we can work on this in master now that Rodrigo branched off the 0.5 series.
I have a bunch of API-breaking comments as well, but we should probably discuss such matters on the mailing list.
- 116. By Mikkel Kamstrup Erlandsen
-
More items for the todo :-)
- 117. By Mikkel Kamstrup Erlandsen
-
Port bugfix in rev. 98 of lp:~rodrigo-moya/couchdb-glib/no-revision-in-auth-header to this branch
Mikkel Kamstrup Erlandsen (kamstrup) wrote : | # |
> ok, so there is no way to import GIT branches into LP, so we will be doing
> manual code review (sending patches to an internal list) for the next few
> weeks from the gnome-2-28 branch I've created in GIT.
>
> So, I'll approve your branch as soon as this other branch
> (https:/
> auth-header) gets accepted/merged. Just make sure your branch includes those 2
> simple fixes, push it, so that the new diff is shown, and, as I said, I'll
> approve it (and push it to GNOME master branch, if you can't do so) as soon as
> the other branch lands in GNOME GIT.
I've ported you fixes to my branch in rev. 117: http://
Tim Cole (tcole) wrote : | # |
Hmm.. okay....
I'd still really like to see the refcounting fixed per my example though. That shouldn't cause any ABI/API incompatibilities.
Rodrigo Moya (rodrigo-moya) wrote : | # |
Well, AFAICS boxed types are used everywhere in GNOME for structs, so that's why I used them. I wouldn't mind using GObject's, but since they won't have any signal, property, or any other GObject-related feature, I think we can live with implementing the refcounting ourselves. Of course, it makes sense to use the g_atomic_* calls Tim suggests, although, yes, let's fix that once the branch has landed.
So Mikkel, please commit to GIT master
Mikkel Kamstrup Erlandsen (kamstrup) wrote : | # |
> So Mikkel, please commit to GIT master
Done.
(I hope I did not mess something up too badly with my bzr->git transition (using the bzr fast-import plugin)).
Preview Diff
1 | === modified file 'Makefile.am' | |||
2 | --- Makefile.am 2009-07-20 11:27:33 +0000 | |||
3 | +++ Makefile.am 2009-10-06 18:10:22 +0000 | |||
4 | @@ -1,4 +1,6 @@ | |||
6 | 1 | SUBDIRS = couchdb-glib tests | 1 | SUBDIRS = couchdb-glib tests doc |
7 | 2 | |||
8 | 3 | DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc | ||
9 | 2 | 4 | ||
10 | 3 | pcfiles = couchdb-glib-1.0.pc | 5 | pcfiles = couchdb-glib-1.0.pc |
11 | 4 | 6 | ||
12 | @@ -8,7 +10,16 @@ | |||
13 | 8 | pkgconfig_DATA = $(pcfiles) | 10 | pkgconfig_DATA = $(pcfiles) |
14 | 9 | pkgconfigdir = $(libdir)/pkgconfig | 11 | pkgconfigdir = $(libdir)/pkgconfig |
15 | 10 | 12 | ||
17 | 11 | EXTRA_DIST = couchdb-glib.pc.in LICENSE | 13 | couchdbdocdir = ${datadir}/doc/couchdb-glib |
18 | 14 | couchdbdoc_DATA = \ | ||
19 | 15 | README \ | ||
20 | 16 | LICENSE \ | ||
21 | 17 | couchdb-glib.doap \ | ||
22 | 18 | NEWS | ||
23 | 19 | |||
24 | 20 | EXTRA_DIST = \ | ||
25 | 21 | couchdb-glib.pc.in \ | ||
26 | 22 | $(couchdbdoc_DATA) | ||
27 | 12 | 23 | ||
28 | 13 | dist-hook: | 24 | dist-hook: |
29 | 14 | git log --stat > ChangeLog.in && \ | 25 | git log --stat > ChangeLog.in && \ |
30 | 15 | 26 | ||
31 | === added file 'NOTES.kamstrup' | |||
32 | --- NOTES.kamstrup 1970-01-01 00:00:00 +0000 | |||
33 | +++ NOTES.kamstrup 2009-10-06 18:10:22 +0000 | |||
34 | @@ -0,0 +1,32 @@ | |||
35 | 1 | TODO: | ||
36 | 2 | ----- | ||
37 | 3 | Silent build rules | ||
38 | 4 | Single header includes | ||
39 | 5 | ? Get rid of CouchDBStructField ? | ||
40 | 6 | Make 'make check' run unit tests | ||
41 | 7 | Rename CouchDB class to CouchDBConnection | ||
42 | 8 | Add method couchdb_send_async using a SoupSessionAsync underneath | ||
43 | 9 | A .ini parser to extract OAUTH credentials from desktop-couchdb.ini | ||
44 | 10 | Move couchdb_document_put() to couchdb_put(doc) in order to separate responsibilities and make CouchDB sub-classable | ||
45 | 11 | Class struct padding for future ABI stability | ||
46 | 12 | Ref counting in custom boxed types vs. full GObjects | ||
47 | 13 | Abstract out OAUTH, in favour of custom message filters in couchdb_send_message | ||
48 | 14 | |||
49 | 15 | DONE: | ||
50 | 16 | ----- | ||
51 | 17 | |||
52 | 18 | In couchdb.*: | ||
53 | 19 | * Don't make API depend on whether we are configured with OAUTH | ||
54 | 20 | * Move OAUTH related functionality from util.* here | ||
55 | 21 | * New method couchdb_send_message() replacing send_message_and_parse() from util.* | ||
56 | 22 | |||
57 | 23 | In couchdb-document.c: | ||
58 | 24 | * Change refs to internal API of CouchDB object's ->hostname to method calls | ||
59 | 25 | * Change refs to internal API of CouchDBStructField ->json_object to use method call | ||
60 | 26 | |||
61 | 27 | In couchdb-struct-field.*: | ||
62 | 28 | * Add method _get_json_object() | ||
63 | 29 | |||
64 | 30 | THOUGHTS: | ||
65 | 31 | * CouchDBStructField seems to be a superfluous wrapper of JSonObject | ||
66 | 32 | * Rename CouchDB object to CouchDBConnection | ||
67 | 0 | 33 | ||
68 | === modified file 'configure.ac' | |||
69 | --- configure.ac 2009-09-29 12:19:40 +0000 | |||
70 | +++ configure.ac 2009-10-06 18:10:22 +0000 | |||
71 | @@ -43,11 +43,20 @@ | |||
72 | 43 | AC_SUBST(LIBCOUCHDBGLIB_REVISION) | 43 | AC_SUBST(LIBCOUCHDBGLIB_REVISION) |
73 | 44 | AC_SUBST(LIBCOUCHDBGLIB_AGE) | 44 | AC_SUBST(LIBCOUCHDBGLIB_AGE) |
74 | 45 | 45 | ||
75 | 46 | ################################################## | ||
76 | 47 | # Check for gtk-doc. | ||
77 | 48 | ################################################## | ||
78 | 49 | GTK_DOC_CHECK(1.0) | ||
79 | 50 | DISTCHECK_CONFIGURE_FLAGS="--enable-gtk-doc" | ||
80 | 51 | AC_SUBST(DISTCHECK_CONFIGURE_FLAGS) | ||
81 | 52 | |||
82 | 46 | AC_OUTPUT([ | 53 | AC_OUTPUT([ |
83 | 47 | Makefile | 54 | Makefile |
84 | 48 | couchdb-glib.pc | 55 | couchdb-glib.pc |
85 | 49 | couchdb-glib/Makefile | 56 | couchdb-glib/Makefile |
86 | 50 | tests/Makefile | 57 | tests/Makefile |
87 | 58 | doc/Makefile | ||
88 | 59 | doc/reference/Makefile | ||
89 | 51 | ]) | 60 | ]) |
90 | 52 | 61 | ||
91 | 53 | AC_MSG_NOTICE([ | 62 | AC_MSG_NOTICE([ |
92 | 54 | 63 | ||
93 | === modified file 'couchdb-glib/Makefile.am' | |||
94 | --- couchdb-glib/Makefile.am 2009-09-09 15:09:10 +0000 | |||
95 | +++ couchdb-glib/Makefile.am 2009-10-06 18:10:22 +0000 | |||
96 | @@ -22,21 +22,33 @@ | |||
97 | 22 | couchdb-marshal.c: couchdb-marshal.list $(GLIB_GENMARSHAL) | 22 | couchdb-marshal.c: couchdb-marshal.list $(GLIB_GENMARSHAL) |
98 | 23 | $(GLIB_GENMARSHAL) $< --body --prefix=_couchdb_marshal > $@ | 23 | $(GLIB_GENMARSHAL) $< --body --prefix=_couchdb_marshal > $@ |
99 | 24 | 24 | ||
102 | 25 | libcouchdb_glib_1_0_la_SOURCES = \ | 25 | libcouchdb_glib_1_0_la_SOURCES = \ |
101 | 26 | $(MARSHAL_GENERATED) \ | ||
103 | 27 | couchdb.c \ | 26 | couchdb.c \ |
104 | 27 | couchdb.h \ | ||
105 | 28 | couchdb-database-info.c \ | ||
106 | 29 | couchdb-database-info.h \ | ||
107 | 28 | couchdb-document.c \ | 30 | couchdb-document.c \ |
108 | 31 | couchdb-document.h \ | ||
109 | 29 | couchdb-document-contact.c \ | 32 | couchdb-document-contact.c \ |
111 | 30 | couchdb-types.c \ | 33 | couchdb-document-contact.h \ |
112 | 34 | couchdb-document-info.c \ | ||
113 | 35 | couchdb-document-info.h \ | ||
114 | 36 | couchdb-glib.h \ | ||
115 | 37 | couchdb-struct-field.c \ | ||
116 | 38 | couchdb-struct-field.h \ | ||
117 | 39 | couchdb-types.h \ | ||
118 | 31 | dbwatch.c \ | 40 | dbwatch.c \ |
119 | 32 | dbwatch.h \ | 41 | dbwatch.h \ |
120 | 33 | $(OAUTH_SOURCES) \ | ||
121 | 34 | utils.c \ | 42 | utils.c \ |
123 | 35 | utils.h | 43 | utils.h \ |
124 | 44 | $(MARSHAL_GENERATED) \ | ||
125 | 45 | $(OAUTH_SOURCES) | ||
126 | 46 | |||
127 | 36 | libcouchdb_glib_1_0_la_LIBADD = \ | 47 | libcouchdb_glib_1_0_la_LIBADD = \ |
128 | 37 | $(COUCHDB_GLIB_LIBS) \ | 48 | $(COUCHDB_GLIB_LIBS) \ |
129 | 38 | $(OAUTH_LIBS) \ | 49 | $(OAUTH_LIBS) \ |
130 | 39 | -luuid | 50 | -luuid |
131 | 51 | |||
132 | 40 | libcouchdb_glib_1_0_la_LDFLAGS = \ | 52 | libcouchdb_glib_1_0_la_LDFLAGS = \ |
133 | 41 | -version-info $(LIBCOUCHDBGLIB_CURRENT):$(LIBCOUCHDBGLIB_REVISION):$(LIBCOUCHDBGLIB_AGE) | 53 | -version-info $(LIBCOUCHDBGLIB_CURRENT):$(LIBCOUCHDBGLIB_REVISION):$(LIBCOUCHDBGLIB_AGE) |
134 | 42 | 54 | ||
135 | 43 | 55 | ||
136 | === added file 'couchdb-glib/couchdb-database-info.c' | |||
137 | --- couchdb-glib/couchdb-database-info.c 1970-01-01 00:00:00 +0000 | |||
138 | +++ couchdb-glib/couchdb-database-info.c 2009-10-06 18:10:22 +0000 | |||
139 | @@ -0,0 +1,151 @@ | |||
140 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
141 | 2 | /* | ||
142 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
143 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
144 | 5 | * | ||
145 | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
146 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
147 | 8 | * | ||
148 | 9 | * This library is free software; you can redistribute it and/or | ||
149 | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
150 | 11 | * License as published by the Free Software Foundation. | ||
151 | 12 | * | ||
152 | 13 | * This program is distributed in the hope that it will be useful, | ||
153 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
154 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
155 | 16 | * General Public License for more details. | ||
156 | 17 | * | ||
157 | 18 | * You should have received a copy of the GNU Lesser General Public | ||
158 | 19 | * License along with this library; if not, write to the | ||
159 | 20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
160 | 21 | * Boston, MA 02110-1301, USA. | ||
161 | 22 | */ | ||
162 | 23 | |||
163 | 24 | #include "couchdb-database-info.h" | ||
164 | 25 | |||
165 | 26 | struct _CouchDBDatabaseInfo { | ||
166 | 27 | gint ref_count; | ||
167 | 28 | |||
168 | 29 | char *dbname; | ||
169 | 30 | gint doc_count; | ||
170 | 31 | gint doc_del_count; | ||
171 | 32 | gint update_seq; | ||
172 | 33 | gboolean compact_running; | ||
173 | 34 | gint disk_size; | ||
174 | 35 | }; | ||
175 | 36 | |||
176 | 37 | /* | ||
177 | 38 | * CouchDBDatabaseInfo object | ||
178 | 39 | */ | ||
179 | 40 | |||
180 | 41 | GType | ||
181 | 42 | couchdb_database_info_get_type (void) | ||
182 | 43 | { | ||
183 | 44 | static GType object_type = 0; | ||
184 | 45 | |||
185 | 46 | if (G_UNLIKELY (!object_type)) | ||
186 | 47 | object_type = g_boxed_type_register_static (g_intern_static_string ("CouchDBDatabaseInfo"), | ||
187 | 48 | (GBoxedCopyFunc) couchdb_database_info_ref, | ||
188 | 49 | (GBoxedFreeFunc) couchdb_database_info_unref); | ||
189 | 50 | |||
190 | 51 | return object_type; | ||
191 | 52 | } | ||
192 | 53 | |||
193 | 54 | CouchDBDatabaseInfo * | ||
194 | 55 | couchdb_database_info_new (const char *dbname, | ||
195 | 56 | gint doc_count, | ||
196 | 57 | gint doc_del_count, | ||
197 | 58 | gint update_seq, | ||
198 | 59 | gboolean compact_running, | ||
199 | 60 | gint disk_size) | ||
200 | 61 | { | ||
201 | 62 | CouchDBDatabaseInfo *dbinfo; | ||
202 | 63 | |||
203 | 64 | dbinfo = g_slice_new (CouchDBDatabaseInfo); | ||
204 | 65 | dbinfo->ref_count = 1; | ||
205 | 66 | dbinfo->dbname = g_strdup (dbname); | ||
206 | 67 | dbinfo->doc_count = doc_count; | ||
207 | 68 | dbinfo->doc_del_count = doc_del_count; | ||
208 | 69 | dbinfo->update_seq = update_seq; | ||
209 | 70 | dbinfo->compact_running = compact_running; | ||
210 | 71 | dbinfo->disk_size = disk_size; | ||
211 | 72 | |||
212 | 73 | return dbinfo; | ||
213 | 74 | } | ||
214 | 75 | |||
215 | 76 | CouchDBDatabaseInfo * | ||
216 | 77 | couchdb_database_info_ref (CouchDBDatabaseInfo *dbinfo) | ||
217 | 78 | { | ||
218 | 79 | g_return_val_if_fail (dbinfo != NULL, NULL); | ||
219 | 80 | g_return_val_if_fail (dbinfo->ref_count > 0, NULL); | ||
220 | 81 | |||
221 | 82 | g_atomic_int_exchange_and_add (&dbinfo->ref_count, 1); | ||
222 | 83 | |||
223 | 84 | return dbinfo; | ||
224 | 85 | } | ||
225 | 86 | |||
226 | 87 | void | ||
227 | 88 | couchdb_database_info_unref (CouchDBDatabaseInfo *dbinfo) | ||
228 | 89 | { | ||
229 | 90 | gint old_ref; | ||
230 | 91 | |||
231 | 92 | g_return_if_fail (dbinfo != NULL); | ||
232 | 93 | g_return_if_fail (dbinfo->ref_count > 0); | ||
233 | 94 | |||
234 | 95 | old_ref = g_atomic_int_get (&dbinfo->ref_count); | ||
235 | 96 | if (old_ref > 1) | ||
236 | 97 | g_atomic_int_compare_and_exchange (&dbinfo->ref_count, old_ref, old_ref - 1); | ||
237 | 98 | else { | ||
238 | 99 | g_free (dbinfo->dbname); | ||
239 | 100 | g_slice_free (CouchDBDatabaseInfo, dbinfo); | ||
240 | 101 | } | ||
241 | 102 | } | ||
242 | 103 | |||
243 | 104 | const char * | ||
244 | 105 | couchdb_database_info_get_dbname (CouchDBDatabaseInfo *dbinfo) | ||
245 | 106 | { | ||
246 | 107 | g_return_val_if_fail (dbinfo != NULL, NULL); | ||
247 | 108 | |||
248 | 109 | return (const char *) dbinfo->dbname; | ||
249 | 110 | } | ||
250 | 111 | |||
251 | 112 | gint | ||
252 | 113 | couchdb_database_info_get_documents_count (CouchDBDatabaseInfo *dbinfo) | ||
253 | 114 | { | ||
254 | 115 | g_return_val_if_fail (dbinfo != NULL, 0); | ||
255 | 116 | |||
256 | 117 | return dbinfo->doc_count; | ||
257 | 118 | } | ||
258 | 119 | |||
259 | 120 | gint | ||
260 | 121 | couchdb_database_info_get_deleted_documents_count (CouchDBDatabaseInfo *dbinfo) | ||
261 | 122 | { | ||
262 | 123 | g_return_val_if_fail (dbinfo != NULL, 0); | ||
263 | 124 | |||
264 | 125 | return dbinfo->doc_del_count; | ||
265 | 126 | } | ||
266 | 127 | |||
267 | 128 | gint | ||
268 | 129 | couchdb_database_info_get_update_sequence (CouchDBDatabaseInfo *dbinfo) | ||
269 | 130 | { | ||
270 | 131 | g_return_val_if_fail (dbinfo != NULL, 0); | ||
271 | 132 | |||
272 | 133 | return dbinfo->update_seq; | ||
273 | 134 | } | ||
274 | 135 | |||
275 | 136 | gboolean | ||
276 | 137 | couchdb_database_info_is_compact_running (CouchDBDatabaseInfo *dbinfo) | ||
277 | 138 | { | ||
278 | 139 | g_return_val_if_fail (dbinfo != NULL, FALSE); | ||
279 | 140 | |||
280 | 141 | return dbinfo->compact_running; | ||
281 | 142 | } | ||
282 | 143 | |||
283 | 144 | gint | ||
284 | 145 | couchdb_database_info_get_disk_size (CouchDBDatabaseInfo *dbinfo) | ||
285 | 146 | { | ||
286 | 147 | g_return_val_if_fail (dbinfo != NULL, 0); | ||
287 | 148 | |||
288 | 149 | return dbinfo->disk_size; | ||
289 | 150 | } | ||
290 | 151 | |||
291 | 0 | 152 | ||
292 | === added file 'couchdb-glib/couchdb-database-info.h' | |||
293 | --- couchdb-glib/couchdb-database-info.h 1970-01-01 00:00:00 +0000 | |||
294 | +++ couchdb-glib/couchdb-database-info.h 2009-10-06 18:10:22 +0000 | |||
295 | @@ -0,0 +1,59 @@ | |||
296 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
297 | 2 | /* | ||
298 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
299 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
300 | 5 | * | ||
301 | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
302 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
303 | 8 | * | ||
304 | 9 | * This library is free software; you can redistribute it and/or | ||
305 | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
306 | 11 | * License as published by the Free Software Foundation. | ||
307 | 12 | * | ||
308 | 13 | * This program is distributed in the hope that it will be useful, | ||
309 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
310 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
311 | 16 | * General Public License for more details. | ||
312 | 17 | * | ||
313 | 18 | * You should have received a copy of the GNU Lesser General Public | ||
314 | 19 | * License along with this library; if not, write to the | ||
315 | 20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
316 | 21 | * Boston, MA 02110-1301, USA. | ||
317 | 22 | */ | ||
318 | 23 | |||
319 | 24 | #ifndef __COUCHDB_DATABASE_INFO_H__ | ||
320 | 25 | #define __COUCHDB_DATABASE_INFO_H__ | ||
321 | 26 | |||
322 | 27 | #include <glib.h> | ||
323 | 28 | #include <glib-object.h> | ||
324 | 29 | #include "couchdb-types.h" | ||
325 | 30 | |||
326 | 31 | G_BEGIN_DECLS | ||
327 | 32 | |||
328 | 33 | #define COUCHDB_TYPE_DATABASE_INFO (couchdb_database_info_get_type ()) | ||
329 | 34 | |||
330 | 35 | /* | ||
331 | 36 | * CouchDBDatabaseInfo | ||
332 | 37 | */ | ||
333 | 38 | |||
334 | 39 | GType couchdb_database_info_get_type (void); | ||
335 | 40 | CouchDBDatabaseInfo *couchdb_database_info_ref (CouchDBDatabaseInfo *dbinfo); | ||
336 | 41 | void couchdb_database_info_unref (CouchDBDatabaseInfo *dbinfo); | ||
337 | 42 | |||
338 | 43 | const char *couchdb_database_info_get_dbname (CouchDBDatabaseInfo *dbinfo); | ||
339 | 44 | gint couchdb_database_info_get_documents_count (CouchDBDatabaseInfo *dbinfo); | ||
340 | 45 | gint couchdb_database_info_get_deleted_documents_count (CouchDBDatabaseInfo *dbinfo); | ||
341 | 46 | gint couchdb_database_info_get_update_sequence (CouchDBDatabaseInfo *dbinfo); | ||
342 | 47 | gboolean couchdb_database_info_is_compact_running (CouchDBDatabaseInfo *dbinfo); | ||
343 | 48 | gint couchdb_database_info_get_disk_size (CouchDBDatabaseInfo *dbinfo); | ||
344 | 49 | |||
345 | 50 | CouchDBDatabaseInfo* couchdb_database_info_new (const char *dbname, | ||
346 | 51 | gint doc_count, | ||
347 | 52 | gint doc_del_count, | ||
348 | 53 | gint update_seq, | ||
349 | 54 | gboolean compact_running, | ||
350 | 55 | gint disk_size); | ||
351 | 56 | |||
352 | 57 | G_END_DECLS | ||
353 | 58 | |||
354 | 59 | #endif /* __COUCHDB_DATABASE_INFO_H__ */ | ||
355 | 0 | 60 | ||
356 | === modified file 'couchdb-glib/couchdb-document-contact.c' | |||
357 | --- couchdb-glib/couchdb-document-contact.c 2009-09-22 12:38:41 +0000 | |||
358 | +++ couchdb-glib/couchdb-document-contact.c 2009-10-06 18:10:22 +0000 | |||
359 | @@ -337,7 +337,7 @@ | |||
360 | 337 | g_return_val_if_fail (couchdb_document_is_contact (document), NULL); | 337 | g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
361 | 338 | 338 | ||
362 | 339 | addresses_json = json_object_get_object_member ( | 339 | addresses_json = json_object_get_object_member ( |
364 | 340 | json_node_get_object (document->root_node), "email_addresses");; | 340 | couchdb_document_get_json_object (document), "email_addresses");; |
365 | 341 | if (addresses_json) { | 341 | if (addresses_json) { |
366 | 342 | json_object_foreach_member (addresses_json, | 342 | json_object_foreach_member (addresses_json, |
367 | 343 | (JsonObjectForeach) foreach_object_cb, | 343 | (JsonObjectForeach) foreach_object_cb, |
368 | @@ -375,7 +375,7 @@ | |||
369 | 375 | } | 375 | } |
370 | 376 | } | 376 | } |
371 | 377 | 377 | ||
373 | 378 | json_object_set_object_member (json_node_get_object (document->root_node), "email_addresses", addresses_json); | 378 | json_object_set_object_member (couchdb_document_get_json_object (document), "email_addresses", addresses_json); |
374 | 379 | } | 379 | } |
375 | 380 | 380 | ||
376 | 381 | GSList * | 381 | GSList * |
377 | @@ -388,7 +388,7 @@ | |||
378 | 388 | g_return_val_if_fail (couchdb_document_is_contact (document), NULL); | 388 | g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
379 | 389 | 389 | ||
380 | 390 | phone_numbers = json_object_get_object_member ( | 390 | phone_numbers = json_object_get_object_member ( |
382 | 391 | json_node_get_object (document->root_node), "phone_numbers"); | 391 | couchdb_document_get_json_object (document), "phone_numbers"); |
383 | 392 | if (phone_numbers) { | 392 | if (phone_numbers) { |
384 | 393 | json_object_foreach_member (phone_numbers, | 393 | json_object_foreach_member (phone_numbers, |
385 | 394 | (JsonObjectForeach) foreach_object_cb, | 394 | (JsonObjectForeach) foreach_object_cb, |
386 | @@ -428,7 +428,7 @@ | |||
387 | 428 | } | 428 | } |
388 | 429 | } | 429 | } |
389 | 430 | 430 | ||
391 | 431 | json_object_set_object_member (json_node_get_object (document->root_node), "phone_numbers", phone_numbers); | 431 | json_object_set_object_member (couchdb_document_get_json_object (document), "phone_numbers", phone_numbers); |
392 | 432 | } | 432 | } |
393 | 433 | 433 | ||
394 | 434 | GSList * | 434 | GSList * |
395 | @@ -441,7 +441,7 @@ | |||
396 | 441 | g_return_val_if_fail (couchdb_document_is_contact (document), NULL); | 441 | g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
397 | 442 | 442 | ||
398 | 443 | addresses = json_object_get_object_member ( | 443 | addresses = json_object_get_object_member ( |
400 | 444 | json_node_get_object (document->root_node), "addresses"); | 444 | couchdb_document_get_json_object (document), "addresses"); |
401 | 445 | if (addresses) { | 445 | if (addresses) { |
402 | 446 | json_object_foreach_member (addresses, | 446 | json_object_foreach_member (addresses, |
403 | 447 | (JsonObjectForeach) foreach_object_cb, | 447 | (JsonObjectForeach) foreach_object_cb, |
404 | @@ -489,7 +489,7 @@ | |||
405 | 489 | } | 489 | } |
406 | 490 | } | 490 | } |
407 | 491 | 491 | ||
409 | 492 | json_object_set_object_member (json_node_get_object (document->root_node), "addresses", addresses); | 492 | json_object_set_object_member (couchdb_document_get_json_object (document), "addresses", addresses); |
410 | 493 | } | 493 | } |
411 | 494 | 494 | ||
412 | 495 | GSList * | 495 | GSList * |
413 | @@ -502,7 +502,7 @@ | |||
414 | 502 | g_return_val_if_fail (couchdb_document_is_contact (document), NULL); | 502 | g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
415 | 503 | 503 | ||
416 | 504 | im_addresses = json_object_get_object_member ( | 504 | im_addresses = json_object_get_object_member ( |
418 | 505 | json_node_get_object (document->root_node), "im_addresses"); | 505 | couchdb_document_get_json_object (document), "im_addresses"); |
419 | 506 | if (im_addresses != NULL) { | 506 | if (im_addresses != NULL) { |
420 | 507 | json_object_foreach_member (im_addresses, | 507 | json_object_foreach_member (im_addresses, |
421 | 508 | (JsonObjectForeach) foreach_object_cb, | 508 | (JsonObjectForeach) foreach_object_cb, |
422 | @@ -542,7 +542,7 @@ | |||
423 | 542 | } | 542 | } |
424 | 543 | } | 543 | } |
425 | 544 | 544 | ||
427 | 545 | json_object_set_object_member (json_node_get_object (document->root_node), "im_addresses", im_addresses_json); | 545 | json_object_set_object_member (couchdb_document_get_json_object (document), "im_addresses", im_addresses_json); |
428 | 546 | } | 546 | } |
429 | 547 | 547 | ||
430 | 548 | GSList * | 548 | GSList * |
431 | @@ -555,7 +555,7 @@ | |||
432 | 555 | g_return_val_if_fail (couchdb_document_is_contact (document), NULL); | 555 | g_return_val_if_fail (couchdb_document_is_contact (document), NULL); |
433 | 556 | 556 | ||
434 | 557 | urls = json_object_get_object_member ( | 557 | urls = json_object_get_object_member ( |
436 | 558 | json_node_get_object (document->root_node), "urls"); | 558 | couchdb_document_get_json_object (document), "urls"); |
437 | 559 | if (urls) { | 559 | if (urls) { |
438 | 560 | json_object_foreach_member (urls, | 560 | json_object_foreach_member (urls, |
439 | 561 | (JsonObjectForeach) foreach_object_cb, | 561 | (JsonObjectForeach) foreach_object_cb, |
440 | @@ -593,7 +593,7 @@ | |||
441 | 593 | } | 593 | } |
442 | 594 | } | 594 | } |
443 | 595 | 595 | ||
445 | 596 | json_object_set_object_member (json_node_get_object (document->root_node), "urls", urls_json); | 596 | json_object_set_object_member (couchdb_document_get_json_object (document), "urls", urls_json); |
446 | 597 | } | 597 | } |
447 | 598 | 598 | ||
448 | 599 | const char * | 599 | const char * |
449 | 600 | 600 | ||
450 | === modified file 'couchdb-glib/couchdb-document-contact.h' | |||
451 | --- couchdb-glib/couchdb-document-contact.h 2009-09-21 22:34:18 +0000 | |||
452 | +++ couchdb-glib/couchdb-document-contact.h 2009-10-06 18:10:22 +0000 | |||
453 | @@ -22,7 +22,11 @@ | |||
454 | 22 | #ifndef __COUCHDB_DOCUMENT_CONTACT_H__ | 22 | #ifndef __COUCHDB_DOCUMENT_CONTACT_H__ |
455 | 23 | #define __COUCHDB_DOCUMENT_CONTACT_H__ | 23 | #define __COUCHDB_DOCUMENT_CONTACT_H__ |
456 | 24 | 24 | ||
458 | 25 | #include <couchdb-glib.h> | 25 | #include <glib.h> |
459 | 26 | #include "couchdb-document.h" | ||
460 | 27 | #include "couchdb-struct-field.h" | ||
461 | 28 | |||
462 | 29 | G_BEGIN_DECLS | ||
463 | 26 | 30 | ||
464 | 27 | #define COUCHDB_RECORD_TYPE_CONTACT "http://www.freedesktop.org/wiki/Specifications/desktopcouch/contact" | 31 | #define COUCHDB_RECORD_TYPE_CONTACT "http://www.freedesktop.org/wiki/Specifications/desktopcouch/contact" |
465 | 28 | 32 | ||
466 | @@ -191,4 +195,7 @@ | |||
467 | 191 | 195 | ||
468 | 192 | const char *couchdb_document_contact_url_get_description (CouchDBStructField *sf); | 196 | const char *couchdb_document_contact_url_get_description (CouchDBStructField *sf); |
469 | 193 | void couchdb_document_contact_url_set_description (CouchDBStructField *sf, const char *description); | 197 | void couchdb_document_contact_url_set_description (CouchDBStructField *sf, const char *description); |
471 | 194 | #endif | 198 | |
472 | 199 | G_END_DECLS | ||
473 | 200 | |||
474 | 201 | #endif /* __COUCHDB_DOCUMENT_CONTACT_H__ */ | ||
475 | 195 | 202 | ||
476 | === added file 'couchdb-glib/couchdb-document-info.c' | |||
477 | --- couchdb-glib/couchdb-document-info.c 1970-01-01 00:00:00 +0000 | |||
478 | +++ couchdb-glib/couchdb-document-info.c 2009-10-06 18:10:22 +0000 | |||
479 | @@ -0,0 +1,107 @@ | |||
480 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
481 | 2 | /* | ||
482 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
483 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
484 | 5 | * | ||
485 | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
486 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
487 | 8 | * | ||
488 | 9 | * This library is free software; you can redistribute it and/or | ||
489 | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
490 | 11 | * License as published by the Free Software Foundation. | ||
491 | 12 | * | ||
492 | 13 | * This program is distributed in the hope that it will be useful, | ||
493 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
494 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
495 | 16 | * General Public License for more details. | ||
496 | 17 | * | ||
497 | 18 | * You should have received a copy of the GNU Lesser General Public | ||
498 | 19 | * License along with this library; if not, write to the | ||
499 | 20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
500 | 21 | * Boston, MA 02110-1301, USA. | ||
501 | 22 | */ | ||
502 | 23 | |||
503 | 24 | #include "couchdb-document-info.h" | ||
504 | 25 | |||
505 | 26 | struct _CouchDBDocumentInfo { | ||
506 | 27 | gint ref_count; | ||
507 | 28 | |||
508 | 29 | char *docid; | ||
509 | 30 | char *revision; | ||
510 | 31 | }; | ||
511 | 32 | |||
512 | 33 | /* | ||
513 | 34 | * CouchDBDocumentInfo object | ||
514 | 35 | */ | ||
515 | 36 | |||
516 | 37 | GType | ||
517 | 38 | couchdb_document_info_get_type (void) | ||
518 | 39 | { | ||
519 | 40 | static GType object_type = 0; | ||
520 | 41 | |||
521 | 42 | if (G_UNLIKELY (!object_type)) | ||
522 | 43 | object_type = g_boxed_type_register_static (g_intern_static_string ("CouchDBDocumentInfo"), | ||
523 | 44 | (GBoxedCopyFunc) couchdb_document_info_ref, | ||
524 | 45 | (GBoxedFreeFunc) couchdb_document_info_unref); | ||
525 | 46 | |||
526 | 47 | return object_type; | ||
527 | 48 | } | ||
528 | 49 | |||
529 | 50 | CouchDBDocumentInfo * | ||
530 | 51 | couchdb_document_info_new (const char *docid, const char *revision) | ||
531 | 52 | { | ||
532 | 53 | CouchDBDocumentInfo *doc_info; | ||
533 | 54 | |||
534 | 55 | doc_info = g_slice_new (CouchDBDocumentInfo); | ||
535 | 56 | doc_info->ref_count = 1; | ||
536 | 57 | doc_info->docid = g_strdup (docid); | ||
537 | 58 | doc_info->revision = g_strdup (revision); | ||
538 | 59 | |||
539 | 60 | return doc_info; | ||
540 | 61 | } | ||
541 | 62 | |||
542 | 63 | CouchDBDocumentInfo * | ||
543 | 64 | couchdb_document_info_ref (CouchDBDocumentInfo *doc_info) | ||
544 | 65 | { | ||
545 | 66 | g_return_val_if_fail (doc_info != NULL, NULL); | ||
546 | 67 | g_return_val_if_fail (doc_info->ref_count > 0, NULL); | ||
547 | 68 | |||
548 | 69 | g_atomic_int_exchange_and_add (&doc_info->ref_count, 1); | ||
549 | 70 | |||
550 | 71 | return doc_info; | ||
551 | 72 | } | ||
552 | 73 | |||
553 | 74 | void | ||
554 | 75 | couchdb_document_info_unref (CouchDBDocumentInfo *doc_info) | ||
555 | 76 | { | ||
556 | 77 | gint old_ref; | ||
557 | 78 | |||
558 | 79 | g_return_if_fail (doc_info != NULL); | ||
559 | 80 | g_return_if_fail (doc_info->ref_count > 0); | ||
560 | 81 | |||
561 | 82 | old_ref = g_atomic_int_get (&doc_info->ref_count); | ||
562 | 83 | if (old_ref > 1) | ||
563 | 84 | g_atomic_int_compare_and_exchange (&doc_info->ref_count, old_ref, old_ref - 1); | ||
564 | 85 | else { | ||
565 | 86 | g_free (doc_info->docid); | ||
566 | 87 | g_free (doc_info->revision); | ||
567 | 88 | g_slice_free (CouchDBDocumentInfo, doc_info); | ||
568 | 89 | } | ||
569 | 90 | } | ||
570 | 91 | |||
571 | 92 | const char * | ||
572 | 93 | couchdb_document_info_get_docid (CouchDBDocumentInfo *doc_info) | ||
573 | 94 | { | ||
574 | 95 | g_return_val_if_fail (doc_info != NULL, NULL); | ||
575 | 96 | |||
576 | 97 | return (const char *) doc_info->docid; | ||
577 | 98 | } | ||
578 | 99 | |||
579 | 100 | const char * | ||
580 | 101 | couchdb_document_info_get_revision (CouchDBDocumentInfo *doc_info) | ||
581 | 102 | { | ||
582 | 103 | g_return_val_if_fail (doc_info != NULL, NULL); | ||
583 | 104 | |||
584 | 105 | return (const char *) doc_info->revision; | ||
585 | 106 | } | ||
586 | 107 | |||
587 | 0 | 108 | ||
588 | === added file 'couchdb-glib/couchdb-document-info.h' | |||
589 | --- couchdb-glib/couchdb-document-info.h 1970-01-01 00:00:00 +0000 | |||
590 | +++ couchdb-glib/couchdb-document-info.h 2009-10-06 18:10:22 +0000 | |||
591 | @@ -0,0 +1,45 @@ | |||
592 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
593 | 2 | /* | ||
594 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
595 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
596 | 5 | * | ||
597 | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
598 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
599 | 8 | * | ||
600 | 9 | * This library is free software; you can redistribute it and/or | ||
601 | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
602 | 11 | * License as published by the Free Software Foundation. | ||
603 | 12 | * | ||
604 | 13 | * This program is distributed in the hope that it will be useful, | ||
605 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
606 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
607 | 16 | * General Public License for more details. | ||
608 | 17 | * | ||
609 | 18 | * You should have received a copy of the GNU Lesser General Public | ||
610 | 19 | * License along with this library; if not, write to the | ||
611 | 20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
612 | 21 | * Boston, MA 02110-1301, USA. | ||
613 | 22 | */ | ||
614 | 23 | |||
615 | 24 | #ifndef __COUCHDB_DOCUMENT_INFO_H__ | ||
616 | 25 | #define __COUCHDB_DOCUMENT_INFO_H__ | ||
617 | 26 | |||
618 | 27 | #include <glib.h> | ||
619 | 28 | #include <glib-object.h> | ||
620 | 29 | #include "couchdb-types.h" | ||
621 | 30 | |||
622 | 31 | G_BEGIN_DECLS | ||
623 | 32 | |||
624 | 33 | #define COUCHDB_TYPE_DOCUMENT_INFO (couchdb_document_info_get_type ()) | ||
625 | 34 | |||
626 | 35 | GType couchdb_document_info_get_type (void); | ||
627 | 36 | CouchDBDocumentInfo *couchdb_document_info_new (const char *docid, const char *revision); | ||
628 | 37 | CouchDBDocumentInfo *couchdb_document_info_ref (CouchDBDocumentInfo *dbinfo); | ||
629 | 38 | void couchdb_document_info_unref (CouchDBDocumentInfo *dbinfo); | ||
630 | 39 | |||
631 | 40 | const char *couchdb_document_info_get_docid (CouchDBDocumentInfo *doc_info); | ||
632 | 41 | const char *couchdb_document_info_get_revision (CouchDBDocumentInfo *doc_info); | ||
633 | 42 | |||
634 | 43 | G_END_DECLS | ||
635 | 44 | |||
636 | 45 | #endif /* __COUCHDB_DOCUMENT_INFO_H__ */ | ||
637 | 0 | 46 | ||
638 | === modified file 'couchdb-glib/couchdb-document.c' | |||
639 | --- couchdb-glib/couchdb-document.c 2009-09-09 12:30:29 +0000 | |||
640 | +++ couchdb-glib/couchdb-document.c 2009-10-06 18:10:22 +0000 | |||
641 | @@ -1,8 +1,10 @@ | |||
642 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
643 | 2 | /* | 2 | /* |
644 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) |
645 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
646 | 4 | * | 5 | * |
647 | 5 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> |
648 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
649 | 6 | * | 8 | * |
650 | 7 | * This library is free software; you can redistribute it and/or | 9 | * This library is free software; you can redistribute it and/or |
651 | 8 | * modify it under the terms of version 2 of the GNU Lesser General Public | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public |
652 | @@ -23,9 +25,17 @@ | |||
653 | 23 | #include <libsoup/soup-session-async.h> | 25 | #include <libsoup/soup-session-async.h> |
654 | 24 | #include <libsoup/soup-gnome.h> | 26 | #include <libsoup/soup-gnome.h> |
655 | 25 | #include <json-glib/json-glib.h> | 27 | #include <json-glib/json-glib.h> |
657 | 26 | #include "couchdb-glib.h" | 28 | #include "couchdb-document.h" |
658 | 27 | #include "utils.h" | 29 | #include "utils.h" |
659 | 28 | 30 | ||
660 | 31 | struct _CouchDBDocument { | ||
661 | 32 | GObject parent; | ||
662 | 33 | |||
663 | 34 | CouchDB *couchdb; | ||
664 | 35 | char *dbname; | ||
665 | 36 | JsonNode *root_node; | ||
666 | 37 | }; | ||
667 | 38 | |||
668 | 29 | G_DEFINE_TYPE(CouchDBDocument, couchdb_document, G_TYPE_OBJECT); | 39 | G_DEFINE_TYPE(CouchDBDocument, couchdb_document, G_TYPE_OBJECT); |
669 | 30 | 40 | ||
670 | 31 | static void | 41 | static void |
671 | @@ -85,17 +95,16 @@ | |||
672 | 85 | g_return_val_if_fail (docid != NULL, NULL); | 95 | g_return_val_if_fail (docid != NULL, NULL); |
673 | 86 | 96 | ||
674 | 87 | encoded_docid = soup_uri_encode (docid, NULL); | 97 | encoded_docid = soup_uri_encode (docid, NULL); |
678 | 88 | url = g_strdup_printf ("%s/%s/%s", couchdb->hostname, dbname, encoded_docid); | 98 | url = g_strdup_printf ("%s/%s/%s", couchdb_get_hostname (couchdb), dbname, encoded_docid); |
679 | 89 | parser = send_message_and_parse (couchdb, SOUP_METHOD_GET, url, NULL, error); | 99 | parser = json_parser_new (); |
680 | 90 | if (parser) { | 100 | if (couchdb_send_message (couchdb, SOUP_METHOD_GET, url, NULL, parser, error)) { |
681 | 91 | document = g_object_new (COUCHDB_TYPE_DOCUMENT, NULL); | 101 | document = g_object_new (COUCHDB_TYPE_DOCUMENT, NULL); |
682 | 92 | document->couchdb = couchdb; | 102 | document->couchdb = couchdb; |
683 | 93 | document->dbname = g_strdup (dbname); | 103 | document->dbname = g_strdup (dbname); |
684 | 94 | 104 | ||
687 | 95 | document->root_node = json_node_copy (json_parser_get_root (parser)); | 105 | document->root_node = json_node_copy (json_parser_get_root (parser)); |
686 | 96 | g_object_unref (G_OBJECT (parser)); | ||
688 | 97 | } | 106 | } |
690 | 98 | 107 | g_object_unref (G_OBJECT (parser)); | |
691 | 99 | g_free (encoded_docid); | 108 | g_free (encoded_docid); |
692 | 100 | g_free (url); | 109 | g_free (url); |
693 | 101 | 110 | ||
694 | @@ -111,34 +120,34 @@ | |||
695 | 111 | const char *id; | 120 | const char *id; |
696 | 112 | JsonParser *parser; | 121 | JsonParser *parser; |
697 | 113 | gboolean result = FALSE; | 122 | gboolean result = FALSE; |
698 | 123 | gboolean send_ok;; | ||
699 | 114 | 124 | ||
700 | 115 | g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), FALSE); | 125 | g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), FALSE); |
701 | 116 | g_return_val_if_fail (dbname != NULL, FALSE); | 126 | g_return_val_if_fail (dbname != NULL, FALSE); |
702 | 117 | 127 | ||
703 | 118 | id = couchdb_document_get_id (document); | 128 | id = couchdb_document_get_id (document); |
704 | 119 | body = couchdb_document_to_string (document); | 129 | body = couchdb_document_to_string (document); |
705 | 130 | parser = json_parser_new (); | ||
706 | 120 | if (id) { | 131 | if (id) { |
707 | 121 | char *encoded_docid; | 132 | char *encoded_docid; |
708 | 122 | 133 | ||
709 | 123 | encoded_docid = soup_uri_encode (id, NULL); | 134 | encoded_docid = soup_uri_encode (id, NULL); |
712 | 124 | url = g_strdup_printf ("%s/%s/%s", document->couchdb->hostname, dbname, encoded_docid); | 135 | url = g_strdup_printf ("%s/%s/%s", couchdb_get_hostname (document->couchdb), dbname, encoded_docid); |
713 | 125 | parser = send_message_and_parse (document->couchdb, SOUP_METHOD_PUT, url, body, error); | 136 | send_ok = couchdb_send_message (document->couchdb, SOUP_METHOD_PUT, url, body, parser, error); |
714 | 126 | 137 | ||
715 | 127 | g_free (encoded_docid); | 138 | g_free (encoded_docid); |
716 | 128 | } else { | 139 | } else { |
719 | 129 | url = g_strdup_printf ("%s/%s/", document->couchdb->hostname, dbname); | 140 | url = g_strdup_printf ("%s/%s/", couchdb_get_hostname (document->couchdb), dbname); |
720 | 130 | parser = send_message_and_parse (document->couchdb, SOUP_METHOD_POST, url, body, error); | 141 | send_ok = couchdb_send_message (document->couchdb, SOUP_METHOD_POST, url, body, parser, error); |
721 | 131 | } | 142 | } |
722 | 132 | 143 | ||
724 | 133 | if (parser) { | 144 | if (send_ok) { |
725 | 134 | JsonObject *object; | 145 | JsonObject *object; |
726 | 135 | 146 | ||
727 | 136 | object = json_node_get_object (json_parser_get_root (parser)); | 147 | object = json_node_get_object (json_parser_get_root (parser)); |
728 | 137 | couchdb_document_set_id (document, json_object_get_string_member (object, "id")); | 148 | couchdb_document_set_id (document, json_object_get_string_member (object, "id")); |
729 | 138 | couchdb_document_set_revision (document, json_object_get_string_member (object, "rev")); | 149 | couchdb_document_set_revision (document, json_object_get_string_member (object, "rev")); |
730 | 139 | 150 | ||
731 | 140 | g_object_unref (G_OBJECT (parser)); | ||
732 | 141 | |||
733 | 142 | if (document->dbname) { | 151 | if (document->dbname) { |
734 | 143 | g_free (document->dbname); | 152 | g_free (document->dbname); |
735 | 144 | document->dbname = g_strdup (dbname); | 153 | document->dbname = g_strdup (dbname); |
736 | @@ -155,6 +164,7 @@ | |||
737 | 155 | /* free memory */ | 164 | /* free memory */ |
738 | 156 | g_free (url); | 165 | g_free (url); |
739 | 157 | g_free (body); | 166 | g_free (body); |
740 | 167 | g_object_unref (G_OBJECT (parser)); | ||
741 | 158 | 168 | ||
742 | 159 | return result; | 169 | return result; |
743 | 160 | } | 170 | } |
744 | @@ -174,11 +184,11 @@ | |||
745 | 174 | if (!id || !revision) /* we can't remove a document without an ID and/or a REVISION */ | 184 | if (!id || !revision) /* we can't remove a document without an ID and/or a REVISION */ |
746 | 175 | return FALSE; | 185 | return FALSE; |
747 | 176 | 186 | ||
753 | 177 | url = g_strdup_printf ("%s/%s/%s?rev=%s", document->couchdb->hostname, document->dbname, id, revision); | 187 | url = g_strdup_printf ("%s/%s/%s?rev=%s", couchdb_get_hostname (document->couchdb), document->dbname, id, revision); |
754 | 178 | parser = send_message_and_parse (document->couchdb, SOUP_METHOD_DELETE, url, NULL, error); | 188 | |
755 | 179 | if (parser) { | 189 | /* We don't parse the http response, therefore the parser arg is NULL */ |
756 | 180 | g_object_unref (G_OBJECT (parser)); | 190 | if (couchdb_send_message (document->couchdb, SOUP_METHOD_DELETE, url, NULL, NULL, error)) { |
757 | 181 | 191 | result = TRUE; | |
758 | 182 | g_signal_emit_by_name (document->couchdb, "document_deleted", document->dbname, id); | 192 | g_signal_emit_by_name (document->couchdb, "document_deleted", document->dbname, id); |
759 | 183 | } | 193 | } |
760 | 184 | 194 | ||
761 | @@ -410,7 +420,7 @@ | |||
762 | 410 | 420 | ||
763 | 411 | json_object_set_object_member (json_node_get_object (document->root_node), | 421 | json_object_set_object_member (json_node_get_object (document->root_node), |
764 | 412 | field, | 422 | field, |
766 | 413 | json_object_ref (value->json_object)); | 423 | json_object_ref (couchdb_struct_field_get_json_object (value))); |
767 | 414 | } | 424 | } |
768 | 415 | 425 | ||
769 | 416 | CouchDBStructField * | 426 | CouchDBStructField * |
770 | @@ -450,3 +460,11 @@ | |||
771 | 450 | 460 | ||
772 | 451 | return NULL; | 461 | return NULL; |
773 | 452 | } | 462 | } |
774 | 463 | |||
775 | 464 | JsonObject * | ||
776 | 465 | couchdb_document_get_json_object (CouchDBDocument *document) | ||
777 | 466 | { | ||
778 | 467 | g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL); | ||
779 | 468 | |||
780 | 469 | return json_node_get_object (document->root_node); | ||
781 | 470 | } | ||
782 | 453 | 471 | ||
783 | === added file 'couchdb-glib/couchdb-document.h' | |||
784 | --- couchdb-glib/couchdb-document.h 1970-01-01 00:00:00 +0000 | |||
785 | +++ couchdb-glib/couchdb-document.h 2009-10-06 18:10:22 +0000 | |||
786 | @@ -0,0 +1,134 @@ | |||
787 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
788 | 2 | /* | ||
789 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
790 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
791 | 5 | * | ||
792 | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
793 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
794 | 8 | * | ||
795 | 9 | * This library is free software; you can redistribute it and/or | ||
796 | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
797 | 11 | * License as published by the Free Software Foundation. | ||
798 | 12 | * | ||
799 | 13 | * This program is distributed in the hope that it will be useful, | ||
800 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
801 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
802 | 16 | * General Public License for more details. | ||
803 | 17 | * | ||
804 | 18 | * You should have received a copy of the GNU Lesser General Public | ||
805 | 19 | * License along with this library; if not, write to the | ||
806 | 20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
807 | 21 | * Boston, MA 02110-1301, USA. | ||
808 | 22 | */ | ||
809 | 23 | |||
810 | 24 | #ifndef __COUCHDB_DOCUMENT_H__ | ||
811 | 25 | #define __COUCHDB_DOCUMENT_H__ | ||
812 | 26 | |||
813 | 27 | #include <glib.h> | ||
814 | 28 | #include <glib-object.h> | ||
815 | 29 | #include <json-glib/json-glib.h> | ||
816 | 30 | #include "couchdb-types.h" | ||
817 | 31 | #include "couchdb-struct-field.h" | ||
818 | 32 | |||
819 | 33 | G_BEGIN_DECLS | ||
820 | 34 | |||
821 | 35 | #define COUCHDB_TYPE_DOCUMENT (couchdb_document_get_type ()) | ||
822 | 36 | #define COUCHDB_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COUCHDB_TYPE_DOCUMENT, CouchDBDocument)) | ||
823 | 37 | #define COUCHDB_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COUCHDB_TYPE_DOCUMENT)) | ||
824 | 38 | #define COUCHDB_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COUCHDB_TYPE_DOCUMENT, CouchDBDocumentClass)) | ||
825 | 39 | #define COUCHDB_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE_DOCUMENT)) | ||
826 | 40 | #define COUCHDB_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE_DOCUMENT, CouchDBDocumentClass)) | ||
827 | 41 | |||
828 | 42 | typedef struct { | ||
829 | 43 | GObjectClass parent_class; | ||
830 | 44 | } CouchDBDocumentClass; | ||
831 | 45 | |||
832 | 46 | |||
833 | 47 | GType couchdb_document_get_type (void); | ||
834 | 48 | |||
835 | 49 | CouchDBDocument *couchdb_document_new (CouchDB *couchdb); | ||
836 | 50 | |||
837 | 51 | CouchDBDocument *couchdb_document_get (CouchDB *couchdb, | ||
838 | 52 | const char *dbname, | ||
839 | 53 | const char *docid, | ||
840 | 54 | GError **error); | ||
841 | 55 | |||
842 | 56 | gboolean couchdb_document_put (CouchDBDocument *document, | ||
843 | 57 | const char *dbname, | ||
844 | 58 | GError **error); | ||
845 | 59 | |||
846 | 60 | gboolean couchdb_document_delete (CouchDBDocument *document, | ||
847 | 61 | GError **error); | ||
848 | 62 | |||
849 | 63 | const char *couchdb_document_get_id (CouchDBDocument *document); | ||
850 | 64 | |||
851 | 65 | void couchdb_document_set_id (CouchDBDocument *document, | ||
852 | 66 | const char *id); | ||
853 | 67 | |||
854 | 68 | const char *couchdb_document_get_revision (CouchDBDocument *document); | ||
855 | 69 | void couchdb_document_set_revision (CouchDBDocument *document, | ||
856 | 70 | const char *revision); | ||
857 | 71 | |||
858 | 72 | const char *couchdb_document_get_record_type (CouchDBDocument *document); | ||
859 | 73 | |||
860 | 74 | void couchdb_document_set_record_type (CouchDBDocument *document, | ||
861 | 75 | |||
862 | 76 | const char *record_type); | ||
863 | 77 | |||
864 | 78 | gboolean couchdb_document_has_field (CouchDBDocument *document, | ||
865 | 79 | const char *field); | ||
866 | 80 | |||
867 | 81 | void couchdb_document_remove_field (CouchDBDocument *document, | ||
868 | 82 | const char *field); | ||
869 | 83 | |||
870 | 84 | gboolean couchdb_document_get_boolean_field (CouchDBDocument *document, | ||
871 | 85 | const char *field); | ||
872 | 86 | |||
873 | 87 | void couchdb_document_set_boolean_field (CouchDBDocument *document, | ||
874 | 88 | const char *field, | ||
875 | 89 | gboolean value); | ||
876 | 90 | |||
877 | 91 | gint couchdb_document_get_int_field (CouchDBDocument *document, | ||
878 | 92 | const char *field); | ||
879 | 93 | |||
880 | 94 | void couchdb_document_set_int_field (CouchDBDocument *document, | ||
881 | 95 | const char *field, | ||
882 | 96 | gint value); | ||
883 | 97 | |||
884 | 98 | gdouble couchdb_document_get_double_field (CouchDBDocument *document, | ||
885 | 99 | const char *field); | ||
886 | 100 | |||
887 | 101 | void couchdb_document_set_double_field (CouchDBDocument *document, | ||
888 | 102 | const char *field, | ||
889 | 103 | gdouble value); | ||
890 | 104 | |||
891 | 105 | const char *couchdb_document_get_string_field (CouchDBDocument *document, | ||
892 | 106 | const char *field); | ||
893 | 107 | |||
894 | 108 | void couchdb_document_set_string_field (CouchDBDocument *document, | ||
895 | 109 | const char *field, | ||
896 | 110 | const char *value); | ||
897 | 111 | |||
898 | 112 | CouchDBStructField* | ||
899 | 113 | couchdb_document_get_struct_field (CouchDBDocument *document, | ||
900 | 114 | const char *field); | ||
901 | 115 | |||
902 | 116 | void couchdb_document_set_struct_field (CouchDBDocument *document, | ||
903 | 117 | const char *field, | ||
904 | 118 | CouchDBStructField *value); | ||
905 | 119 | |||
906 | 120 | CouchDBStructField* | ||
907 | 121 | couchdb_document_get_application_annotations | ||
908 | 122 | (CouchDBDocument *document); | ||
909 | 123 | |||
910 | 124 | void couchdb_document_set_application_annotations | ||
911 | 125 | (CouchDBDocument *document, | ||
912 | 126 | CouchDBStructField *annotations); | ||
913 | 127 | |||
914 | 128 | char* couchdb_document_to_string (CouchDBDocument *document); | ||
915 | 129 | |||
916 | 130 | JsonObject* couchdb_document_get_json_object (CouchDBDocument *document); | ||
917 | 131 | |||
918 | 132 | G_END_DECLS | ||
919 | 133 | |||
920 | 134 | #endif /* __COUCHDB_DOCUMENT_H__ */ | ||
921 | 0 | 135 | ||
922 | === modified file 'couchdb-glib/couchdb-glib.h' | |||
923 | --- couchdb-glib/couchdb-glib.h 2009-09-09 14:53:00 +0000 | |||
924 | +++ couchdb-glib/couchdb-glib.h 2009-10-06 18:10:22 +0000 | |||
925 | @@ -1,8 +1,10 @@ | |||
926 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
927 | 2 | /* | 2 | /* |
928 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) |
929 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
930 | 4 | * | 5 | * |
931 | 5 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> |
932 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
933 | 6 | * | 8 | * |
934 | 7 | * This library is free software; you can redistribute it and/or | 9 | * This library is free software; you can redistribute it and/or |
935 | 8 | * modify it under the terms of version 2 of the GNU Lesser General Public | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public |
936 | @@ -18,115 +20,18 @@ | |||
937 | 18 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
938 | 19 | * Boston, MA 02110-1301, USA. | 21 | * Boston, MA 02110-1301, USA. |
939 | 20 | */ | 22 | */ |
941 | 21 | 23 | ||
942 | 22 | #ifndef __COUCHDB_GLIB_H__ | 24 | #ifndef __COUCHDB_GLIB_H__ |
943 | 23 | #define __COUCHDB_GLIB_H__ | 25 | #define __COUCHDB_GLIB_H__ |
944 | 24 | 26 | ||
945 | 25 | #include <couchdb-types.h> | 27 | #include <couchdb-types.h> |
1053 | 26 | 28 | #include <couchdb.h> | |
1054 | 27 | #define COUCHDB_TYPE (couchdb_get_type ()) | 29 | #include <couchdb-database-info.h> |
1055 | 28 | #define COUCHDB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COUCHDB_TYPE, CouchDB)) | 30 | #include <couchdb-document.h> |
1056 | 29 | #define COUCHDB_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COUCHDB_TYPE)) | 31 | #include <couchdb-document-contact.h> |
1057 | 30 | #define COUCHDB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COUCHDB_TYPE, CouchDBClass)) | 32 | #include <couchdb-document-info.h> |
1058 | 31 | #define COUCHDB_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE)) | 33 | #include <couchdb-struct-field.h> |
1059 | 32 | #define COUCHDB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE, CouchDBClass)) | 34 | |
1060 | 33 | 35 | #endif /* __COUCHDB_GLIB_H__ */ | |
1061 | 34 | typedef struct _CouchDBDocument CouchDBDocument; | 36 | |
1062 | 35 | 37 | ||
956 | 36 | typedef struct _CouchDB CouchDB; | ||
957 | 37 | typedef struct { | ||
958 | 38 | GObjectClass parent_class; | ||
959 | 39 | |||
960 | 40 | void (* database_created) (CouchDB *couchdb, const char *dbname); | ||
961 | 41 | void (* database_deleted) (CouchDB *couchdb, const char *dbname); | ||
962 | 42 | |||
963 | 43 | void (* document_created) (CouchDB *couchdb, const char *dbname, CouchDBDocument *document); | ||
964 | 44 | void (* document_updated) (CouchDB *couchdb, const char *dbname, CouchDBDocument *document); | ||
965 | 45 | void (* document_deleted) (CouchDB *couchdb, const char *dbname, const char *docid); | ||
966 | 46 | } CouchDBClass; | ||
967 | 47 | |||
968 | 48 | GType couchdb_get_type (void); | ||
969 | 49 | CouchDB *couchdb_new (const char *hostname); | ||
970 | 50 | |||
971 | 51 | const char *couchdb_get_hostname (CouchDB *couchdb); | ||
972 | 52 | |||
973 | 53 | /* | ||
974 | 54 | * Databases API | ||
975 | 55 | */ | ||
976 | 56 | |||
977 | 57 | GSList *couchdb_list_databases (CouchDB *couchdb, GError **error); | ||
978 | 58 | void couchdb_free_database_list (GSList *dblist); | ||
979 | 59 | |||
980 | 60 | CouchDBDatabaseInfo *couchdb_get_database_info (CouchDB *couchdb, const char *dbname, GError **error); | ||
981 | 61 | |||
982 | 62 | gboolean couchdb_create_database (CouchDB *couchdb, const char *dbname, GError **error); | ||
983 | 63 | gboolean couchdb_delete_database (CouchDB *couchdb, const char *dbname, GError **error); | ||
984 | 64 | |||
985 | 65 | void couchdb_listen_for_changes (CouchDB *couchdb, const char *dbname); | ||
986 | 66 | |||
987 | 67 | gboolean couchdb_enable_oauth (CouchDB *couchdb, | ||
988 | 68 | const char *consumer_key, | ||
989 | 69 | const char *consumer_secret, | ||
990 | 70 | const char *token_key, | ||
991 | 71 | const char *token_secret); | ||
992 | 72 | void couchdb_disable_oauth (CouchDB *couchdb); | ||
993 | 73 | |||
994 | 74 | /* | ||
995 | 75 | * Documents API | ||
996 | 76 | */ | ||
997 | 77 | |||
998 | 78 | #define COUCHDB_TYPE_DOCUMENT (couchdb_document_get_type ()) | ||
999 | 79 | #define COUCHDB_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COUCHDB_TYPE_DOCUMENT, CouchDBDocument)) | ||
1000 | 80 | #define COUCHDB_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COUCHDB_TYPE_DOCUMENT)) | ||
1001 | 81 | #define COUCHDB_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COUCHDB_TYPE_DOCUMENT, CouchDBDocumentClass)) | ||
1002 | 82 | #define COUCHDB_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE_DOCUMENT)) | ||
1003 | 83 | #define COUCHDB_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE_DOCUMENT, CouchDBDocumentClass)) | ||
1004 | 84 | |||
1005 | 85 | typedef struct { | ||
1006 | 86 | GObjectClass parent_class; | ||
1007 | 87 | } CouchDBDocumentClass; | ||
1008 | 88 | |||
1009 | 89 | GSList *couchdb_list_documents (CouchDB *couchdb, const char *dbname, GError **error); | ||
1010 | 90 | void couchdb_free_document_list (GSList *doclist); | ||
1011 | 91 | |||
1012 | 92 | GType couchdb_document_get_type (void); | ||
1013 | 93 | CouchDBDocument *couchdb_document_new (CouchDB *couchdb); | ||
1014 | 94 | CouchDBDocument *couchdb_document_get (CouchDB *couchdb, | ||
1015 | 95 | const char *dbname, | ||
1016 | 96 | const char *docid, | ||
1017 | 97 | GError **error); | ||
1018 | 98 | gboolean couchdb_document_put (CouchDBDocument *document, | ||
1019 | 99 | const char *dbname, | ||
1020 | 100 | GError **error); | ||
1021 | 101 | gboolean couchdb_document_delete (CouchDBDocument *document, GError **error); | ||
1022 | 102 | |||
1023 | 103 | const char *couchdb_document_get_id (CouchDBDocument *document); | ||
1024 | 104 | void couchdb_document_set_id (CouchDBDocument *document, const char *id); | ||
1025 | 105 | const char *couchdb_document_get_revision (CouchDBDocument *document); | ||
1026 | 106 | void couchdb_document_set_revision (CouchDBDocument *document, const char *revision); | ||
1027 | 107 | const char *couchdb_document_get_record_type (CouchDBDocument *document); | ||
1028 | 108 | void couchdb_document_set_record_type (CouchDBDocument *document, const char *record_type); | ||
1029 | 109 | |||
1030 | 110 | gboolean couchdb_document_has_field (CouchDBDocument *document, const char *field); | ||
1031 | 111 | void couchdb_document_remove_field (CouchDBDocument *document, const char *field); | ||
1032 | 112 | |||
1033 | 113 | gboolean couchdb_document_get_boolean_field (CouchDBDocument *document, const char *field); | ||
1034 | 114 | void couchdb_document_set_boolean_field (CouchDBDocument *document, const char *field, gboolean value); | ||
1035 | 115 | gint couchdb_document_get_int_field (CouchDBDocument *document, const char *field); | ||
1036 | 116 | void couchdb_document_set_int_field (CouchDBDocument *document, const char *field, gint value); | ||
1037 | 117 | gdouble couchdb_document_get_double_field (CouchDBDocument *document, const char *field); | ||
1038 | 118 | void couchdb_document_set_double_field (CouchDBDocument *document, const char *field, gdouble value); | ||
1039 | 119 | const char *couchdb_document_get_string_field (CouchDBDocument *document, const char *field); | ||
1040 | 120 | void couchdb_document_set_string_field (CouchDBDocument *document, const char *field, const char *value); | ||
1041 | 121 | CouchDBStructField *couchdb_document_get_struct_field (CouchDBDocument *document, const char *field); | ||
1042 | 122 | void couchdb_document_set_struct_field (CouchDBDocument *document, | ||
1043 | 123 | const char *field, | ||
1044 | 124 | CouchDBStructField *value); | ||
1045 | 125 | |||
1046 | 126 | CouchDBStructField *couchdb_document_get_application_annotations (CouchDBDocument *document); | ||
1047 | 127 | void couchdb_document_set_application_annotations (CouchDBDocument *document, CouchDBStructField *annotations); | ||
1048 | 128 | |||
1049 | 129 | char *couchdb_document_to_string (CouchDBDocument *document); | ||
1050 | 130 | |||
1051 | 131 | |||
1052 | 132 | #endif | ||
1063 | 133 | 38 | ||
1064 | === added file 'couchdb-glib/couchdb-struct-field.c' | |||
1065 | --- couchdb-glib/couchdb-struct-field.c 1970-01-01 00:00:00 +0000 | |||
1066 | +++ couchdb-glib/couchdb-struct-field.c 2009-10-06 18:10:22 +0000 | |||
1067 | @@ -0,0 +1,291 @@ | |||
1068 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
1069 | 2 | /* | ||
1070 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
1071 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
1072 | 5 | * | ||
1073 | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
1074 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
1075 | 8 | * | ||
1076 | 9 | * This library is free software; you can redistribute it and/or | ||
1077 | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
1078 | 11 | * License as published by the Free Software Foundation. | ||
1079 | 12 | * | ||
1080 | 13 | * This program is distributed in the hope that it will be useful, | ||
1081 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1082 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1083 | 16 | * General Public License for more details. | ||
1084 | 17 | * | ||
1085 | 18 | * You should have received a copy of the GNU Lesser General Public | ||
1086 | 19 | * License along with this library; if not, write to the | ||
1087 | 20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1088 | 21 | * Boston, MA 02110-1301, USA. | ||
1089 | 22 | */ | ||
1090 | 23 | |||
1091 | 24 | #include "couchdb-struct-field.h" | ||
1092 | 25 | |||
1093 | 26 | struct _CouchDBStructField { | ||
1094 | 27 | gint ref_count; | ||
1095 | 28 | JsonObject *json_object; | ||
1096 | 29 | |||
1097 | 30 | /* Extra data needed for some specific StructField's */ | ||
1098 | 31 | char *uuid; /* the UUID of this item */ | ||
1099 | 32 | }; | ||
1100 | 33 | |||
1101 | 34 | GType | ||
1102 | 35 | couchdb_struct_field_get_type (void) | ||
1103 | 36 | { | ||
1104 | 37 | static GType object_type = 0; | ||
1105 | 38 | |||
1106 | 39 | if (G_UNLIKELY (!object_type)) | ||
1107 | 40 | object_type = g_boxed_type_register_static (g_intern_static_string ("CouchDBStructField"), | ||
1108 | 41 | (GBoxedCopyFunc) couchdb_struct_field_ref, | ||
1109 | 42 | (GBoxedFreeFunc) couchdb_struct_field_unref); | ||
1110 | 43 | |||
1111 | 44 | return object_type; | ||
1112 | 45 | } | ||
1113 | 46 | |||
1114 | 47 | CouchDBStructField * | ||
1115 | 48 | couchdb_struct_field_new (void) | ||
1116 | 49 | { | ||
1117 | 50 | CouchDBStructField *sf; | ||
1118 | 51 | |||
1119 | 52 | sf = g_slice_new (CouchDBStructField); | ||
1120 | 53 | sf->ref_count = 1; | ||
1121 | 54 | sf->json_object = json_object_new (); | ||
1122 | 55 | sf->uuid = NULL; | ||
1123 | 56 | |||
1124 | 57 | return sf; | ||
1125 | 58 | } | ||
1126 | 59 | |||
1127 | 60 | CouchDBStructField * | ||
1128 | 61 | couchdb_struct_field_new_from_string (const char *str) | ||
1129 | 62 | { | ||
1130 | 63 | JsonParser *parser; | ||
1131 | 64 | GError *error = NULL; | ||
1132 | 65 | CouchDBStructField *sf = NULL; | ||
1133 | 66 | |||
1134 | 67 | g_return_val_if_fail (str != NULL, NULL); | ||
1135 | 68 | |||
1136 | 69 | parser = json_parser_new (); | ||
1137 | 70 | if (json_parser_load_from_data (parser, str, strlen (str), &error)) { | ||
1138 | 71 | JsonNode *node = json_parser_get_root (parser); | ||
1139 | 72 | |||
1140 | 73 | if (json_node_get_node_type (node) == JSON_NODE_OBJECT) | ||
1141 | 74 | sf = couchdb_struct_field_new_from_json_object (json_node_get_object (node)); | ||
1142 | 75 | } else { | ||
1143 | 76 | g_warning ("Could not parse string: %s", error->message); | ||
1144 | 77 | g_error_free (error); | ||
1145 | 78 | } | ||
1146 | 79 | |||
1147 | 80 | g_object_unref (G_OBJECT (parser)); | ||
1148 | 81 | |||
1149 | 82 | return sf; | ||
1150 | 83 | } | ||
1151 | 84 | |||
1152 | 85 | CouchDBStructField * | ||
1153 | 86 | couchdb_struct_field_new_from_json_object (JsonObject *json_object) | ||
1154 | 87 | { | ||
1155 | 88 | CouchDBStructField *sf; | ||
1156 | 89 | |||
1157 | 90 | sf = g_slice_new (CouchDBStructField); | ||
1158 | 91 | sf->ref_count = 1; | ||
1159 | 92 | sf->json_object = json_object_ref (json_object); | ||
1160 | 93 | sf->uuid = NULL; | ||
1161 | 94 | |||
1162 | 95 | return sf; | ||
1163 | 96 | } | ||
1164 | 97 | |||
1165 | 98 | CouchDBStructField * | ||
1166 | 99 | couchdb_struct_field_ref (CouchDBStructField *sf) | ||
1167 | 100 | { | ||
1168 | 101 | g_return_val_if_fail (sf != NULL, NULL); | ||
1169 | 102 | g_return_val_if_fail (sf->ref_count > 0, NULL); | ||
1170 | 103 | |||
1171 | 104 | g_atomic_int_exchange_and_add (&sf->ref_count, 1); | ||
1172 | 105 | |||
1173 | 106 | return sf; | ||
1174 | 107 | } | ||
1175 | 108 | |||
1176 | 109 | void | ||
1177 | 110 | couchdb_struct_field_unref (CouchDBStructField *sf) | ||
1178 | 111 | { | ||
1179 | 112 | gint old_ref; | ||
1180 | 113 | |||
1181 | 114 | g_return_if_fail (sf != NULL); | ||
1182 | 115 | g_return_if_fail (sf->ref_count > 0); | ||
1183 | 116 | |||
1184 | 117 | old_ref = g_atomic_int_get (&sf->ref_count); | ||
1185 | 118 | if (old_ref > 1) | ||
1186 | 119 | g_atomic_int_compare_and_exchange (&sf->ref_count, old_ref, old_ref - 1); | ||
1187 | 120 | else { | ||
1188 | 121 | json_object_unref (sf->json_object); | ||
1189 | 122 | g_slice_free (CouchDBStructField, sf); | ||
1190 | 123 | } | ||
1191 | 124 | } | ||
1192 | 125 | |||
1193 | 126 | gboolean | ||
1194 | 127 | couchdb_struct_field_has_field (CouchDBStructField *sf, const char *field) | ||
1195 | 128 | { | ||
1196 | 129 | g_return_val_if_fail (sf != NULL, FALSE); | ||
1197 | 130 | g_return_val_if_fail (field != NULL, FALSE); | ||
1198 | 131 | |||
1199 | 132 | return json_object_has_member (sf->json_object, field); | ||
1200 | 133 | } | ||
1201 | 134 | |||
1202 | 135 | void | ||
1203 | 136 | couchdb_struct_field_remove_field (CouchDBStructField *sf, const char *field) | ||
1204 | 137 | { | ||
1205 | 138 | g_return_if_fail (sf != NULL); | ||
1206 | 139 | g_return_if_fail (field != NULL); | ||
1207 | 140 | |||
1208 | 141 | json_object_remove_member (sf->json_object, field); | ||
1209 | 142 | } | ||
1210 | 143 | |||
1211 | 144 | gboolean | ||
1212 | 145 | couchdb_struct_field_get_boolean_field (CouchDBStructField *sf, const char *field) | ||
1213 | 146 | { | ||
1214 | 147 | g_return_val_if_fail (sf != NULL, 0); | ||
1215 | 148 | g_return_val_if_fail (field != NULL, 0); | ||
1216 | 149 | |||
1217 | 150 | return json_object_get_boolean_member (sf->json_object, field); | ||
1218 | 151 | } | ||
1219 | 152 | |||
1220 | 153 | void | ||
1221 | 154 | couchdb_struct_field_set_boolean_field (CouchDBStructField *sf, const char *field, gboolean value) | ||
1222 | 155 | { | ||
1223 | 156 | g_return_if_fail (sf != NULL); | ||
1224 | 157 | g_return_if_fail (field != NULL); | ||
1225 | 158 | |||
1226 | 159 | json_object_set_boolean_member (sf->json_object, field, value); | ||
1227 | 160 | } | ||
1228 | 161 | |||
1229 | 162 | gdouble | ||
1230 | 163 | couchdb_struct_field_get_double_field (CouchDBStructField *sf, const char *field) | ||
1231 | 164 | { | ||
1232 | 165 | g_return_val_if_fail (sf != NULL, 0); | ||
1233 | 166 | g_return_val_if_fail (field != NULL, 0); | ||
1234 | 167 | |||
1235 | 168 | return json_object_get_double_member (sf->json_object, field); | ||
1236 | 169 | } | ||
1237 | 170 | |||
1238 | 171 | void | ||
1239 | 172 | couchdb_struct_field_set_double_field (CouchDBStructField *sf, const char *field, gdouble value) | ||
1240 | 173 | { | ||
1241 | 174 | g_return_if_fail (sf != NULL); | ||
1242 | 175 | g_return_if_fail (field != NULL); | ||
1243 | 176 | |||
1244 | 177 | json_object_set_double_member (sf->json_object, field, value); | ||
1245 | 178 | } | ||
1246 | 179 | |||
1247 | 180 | gint | ||
1248 | 181 | couchdb_struct_field_get_int_field (CouchDBStructField *sf, const char *field) | ||
1249 | 182 | { | ||
1250 | 183 | g_return_val_if_fail (sf != NULL, 0); | ||
1251 | 184 | g_return_val_if_fail (field != NULL, 0); | ||
1252 | 185 | |||
1253 | 186 | return json_object_get_int_member (sf->json_object, field); | ||
1254 | 187 | } | ||
1255 | 188 | |||
1256 | 189 | void | ||
1257 | 190 | couchdb_struct_field_set_int_field (CouchDBStructField *sf, const char *field, gint value) | ||
1258 | 191 | { | ||
1259 | 192 | g_return_if_fail (sf != NULL); | ||
1260 | 193 | g_return_if_fail (field != NULL); | ||
1261 | 194 | |||
1262 | 195 | json_object_set_int_member (sf->json_object, field, value); | ||
1263 | 196 | } | ||
1264 | 197 | |||
1265 | 198 | const char * | ||
1266 | 199 | couchdb_struct_field_get_string_field (CouchDBStructField *sf, const char *field) | ||
1267 | 200 | { | ||
1268 | 201 | g_return_val_if_fail (sf != NULL, NULL); | ||
1269 | 202 | g_return_val_if_fail (field != NULL, NULL); | ||
1270 | 203 | |||
1271 | 204 | return json_object_get_string_member (sf->json_object, field); | ||
1272 | 205 | } | ||
1273 | 206 | |||
1274 | 207 | void | ||
1275 | 208 | couchdb_struct_field_set_string_field (CouchDBStructField *sf, const char *field, const char *value) | ||
1276 | 209 | { | ||
1277 | 210 | g_return_if_fail (sf != NULL); | ||
1278 | 211 | g_return_if_fail (field != NULL); | ||
1279 | 212 | |||
1280 | 213 | if (value) | ||
1281 | 214 | json_object_set_string_member (sf->json_object, field, value); | ||
1282 | 215 | else { | ||
1283 | 216 | /* Remove the field if the value is NULL */ | ||
1284 | 217 | couchdb_struct_field_remove_field (sf, field); | ||
1285 | 218 | } | ||
1286 | 219 | } | ||
1287 | 220 | |||
1288 | 221 | CouchDBStructField * | ||
1289 | 222 | couchdb_struct_field_get_struct_field (CouchDBStructField *sf, const char *field) | ||
1290 | 223 | { | ||
1291 | 224 | g_return_val_if_fail (sf != NULL, NULL); | ||
1292 | 225 | g_return_val_if_fail (field != NULL, NULL); | ||
1293 | 226 | |||
1294 | 227 | return couchdb_struct_field_new_from_json_object ( | ||
1295 | 228 | json_object_get_object_member (sf->json_object, field)); | ||
1296 | 229 | } | ||
1297 | 230 | |||
1298 | 231 | void | ||
1299 | 232 | couchdb_struct_field_set_struct_field (CouchDBStructField *sf, const char *field, CouchDBStructField *value) | ||
1300 | 233 | { | ||
1301 | 234 | g_return_if_fail (sf != NULL); | ||
1302 | 235 | g_return_if_fail (field != NULL); | ||
1303 | 236 | g_return_if_fail (value != NULL); | ||
1304 | 237 | |||
1305 | 238 | json_object_set_object_member (sf->json_object, field, json_object_ref (value->json_object)); | ||
1306 | 239 | } | ||
1307 | 240 | |||
1308 | 241 | const char * | ||
1309 | 242 | couchdb_struct_field_get_uuid (CouchDBStructField *sf) | ||
1310 | 243 | { | ||
1311 | 244 | g_return_val_if_fail (sf != NULL, NULL); | ||
1312 | 245 | |||
1313 | 246 | return (const char *) sf->uuid; | ||
1314 | 247 | } | ||
1315 | 248 | |||
1316 | 249 | void | ||
1317 | 250 | couchdb_struct_field_set_uuid (CouchDBStructField *sf, const char *uuid) | ||
1318 | 251 | { | ||
1319 | 252 | g_return_if_fail (sf != NULL); | ||
1320 | 253 | |||
1321 | 254 | if (sf->uuid) | ||
1322 | 255 | g_free (sf->uuid); | ||
1323 | 256 | |||
1324 | 257 | sf->uuid = g_strdup (uuid); | ||
1325 | 258 | } | ||
1326 | 259 | |||
1327 | 260 | char * | ||
1328 | 261 | couchdb_struct_field_to_string (CouchDBStructField *sf) | ||
1329 | 262 | { | ||
1330 | 263 | JsonNode *node; | ||
1331 | 264 | JsonGenerator *generator; | ||
1332 | 265 | gsize size; | ||
1333 | 266 | char *str = NULL; | ||
1334 | 267 | |||
1335 | 268 | g_return_val_if_fail (sf != NULL, NULL); | ||
1336 | 269 | |||
1337 | 270 | node = json_node_new (JSON_NODE_OBJECT); | ||
1338 | 271 | json_node_set_object (node, sf->json_object); | ||
1339 | 272 | |||
1340 | 273 | generator = json_generator_new (); | ||
1341 | 274 | json_generator_set_root (generator, node); | ||
1342 | 275 | |||
1343 | 276 | str = json_generator_to_data (generator, &size); | ||
1344 | 277 | g_object_unref (G_OBJECT (generator)); | ||
1345 | 278 | |||
1346 | 279 | json_node_free (node); | ||
1347 | 280 | |||
1348 | 281 | return str; | ||
1349 | 282 | } | ||
1350 | 283 | |||
1351 | 284 | JsonObject * | ||
1352 | 285 | couchdb_struct_field_get_json_object (CouchDBStructField *sf) | ||
1353 | 286 | { | ||
1354 | 287 | g_return_val_if_fail (sf != NULL, NULL); | ||
1355 | 288 | |||
1356 | 289 | return sf->json_object; | ||
1357 | 290 | } | ||
1358 | 291 | |||
1359 | 0 | 292 | ||
1360 | === added file 'couchdb-glib/couchdb-struct-field.h' | |||
1361 | --- couchdb-glib/couchdb-struct-field.h 1970-01-01 00:00:00 +0000 | |||
1362 | +++ couchdb-glib/couchdb-struct-field.h 2009-10-06 18:10:22 +0000 | |||
1363 | @@ -0,0 +1,68 @@ | |||
1364 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
1365 | 2 | /* | ||
1366 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
1367 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
1368 | 5 | * | ||
1369 | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
1370 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
1371 | 8 | * | ||
1372 | 9 | * This library is free software; you can redistribute it and/or | ||
1373 | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
1374 | 11 | * License as published by the Free Software Foundation. | ||
1375 | 12 | * | ||
1376 | 13 | * This program is distributed in the hope that it will be useful, | ||
1377 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1378 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1379 | 16 | * General Public License for more details. | ||
1380 | 17 | * | ||
1381 | 18 | * You should have received a copy of the GNU Lesser General Public | ||
1382 | 19 | * License along with this library; if not, write to the | ||
1383 | 20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1384 | 21 | * Boston, MA 02110-1301, USA. | ||
1385 | 22 | */ | ||
1386 | 23 | |||
1387 | 24 | #ifndef __COUCHDB_STRUCT_FIELD_H__ | ||
1388 | 25 | #define __COUCHDB_STRUCT_FIELD_H__ | ||
1389 | 26 | |||
1390 | 27 | #include <glib.h> | ||
1391 | 28 | #include <glib-object.h> | ||
1392 | 29 | #include <json-glib/json-glib.h> | ||
1393 | 30 | #include "couchdb.h" | ||
1394 | 31 | #include "couchdb-types.h" | ||
1395 | 32 | |||
1396 | 33 | G_BEGIN_DECLS | ||
1397 | 34 | |||
1398 | 35 | #define COUCHDB_TYPE_STRUCT_FIELD (couchdb_struct_field_get_type ()) | ||
1399 | 36 | |||
1400 | 37 | GType couchdb_struct_field_get_type (void); | ||
1401 | 38 | CouchDBStructField *couchdb_struct_field_new (void); | ||
1402 | 39 | CouchDBStructField *couchdb_struct_field_new_from_string (const char *str); | ||
1403 | 40 | CouchDBStructField *couchdb_struct_field_ref (CouchDBStructField *sf); | ||
1404 | 41 | void couchdb_struct_field_unref (CouchDBStructField *sf); | ||
1405 | 42 | |||
1406 | 43 | gboolean couchdb_struct_field_has_field (CouchDBStructField *sf, const char *field); | ||
1407 | 44 | void couchdb_struct_field_remove_field (CouchDBStructField *sf, const char *field); | ||
1408 | 45 | |||
1409 | 46 | gboolean couchdb_struct_field_get_boolean_field (CouchDBStructField *sf, const char *field); | ||
1410 | 47 | void couchdb_struct_field_set_boolean_field (CouchDBStructField *sf, const char *field, gboolean value); | ||
1411 | 48 | gdouble couchdb_struct_field_get_double_field (CouchDBStructField *sf, const char *field); | ||
1412 | 49 | void couchdb_struct_field_set_double_field (CouchDBStructField *sf, const char *field, gdouble value); | ||
1413 | 50 | gint couchdb_struct_field_get_int_field (CouchDBStructField *sf, const char *field); | ||
1414 | 51 | void couchdb_struct_field_set_int_field (CouchDBStructField *sf, const char *field, gint value); | ||
1415 | 52 | const char *couchdb_struct_field_get_string_field (CouchDBStructField *sf, const char *field); | ||
1416 | 53 | void couchdb_struct_field_set_string_field (CouchDBStructField *sf, const char *field, const char *value); | ||
1417 | 54 | CouchDBStructField *couchdb_struct_field_get_struct_field (CouchDBStructField *sf, const char *field); | ||
1418 | 55 | void couchdb_struct_field_set_struct_field (CouchDBStructField *sf, const char *field, CouchDBStructField *value); | ||
1419 | 56 | |||
1420 | 57 | const char *couchdb_struct_field_get_uuid (CouchDBStructField *sf); | ||
1421 | 58 | void couchdb_struct_field_set_uuid (CouchDBStructField *sf, const char *uuid); | ||
1422 | 59 | |||
1423 | 60 | char *couchdb_struct_field_to_string (CouchDBStructField *sf); | ||
1424 | 61 | |||
1425 | 62 | CouchDBStructField *couchdb_struct_field_new_from_json_object (JsonObject *json_object); | ||
1426 | 63 | |||
1427 | 64 | JsonObject *couchdb_struct_field_get_json_object (CouchDBStructField *sf); | ||
1428 | 65 | |||
1429 | 66 | G_END_DECLS | ||
1430 | 67 | |||
1431 | 68 | #endif /* __COUCHDB_STRUCT_FIELD__ */ | ||
1432 | 0 | 69 | ||
1433 | === removed file 'couchdb-glib/couchdb-types.c' | |||
1434 | --- couchdb-glib/couchdb-types.c 2009-08-19 16:43:24 +0000 | |||
1435 | +++ couchdb-glib/couchdb-types.c 1970-01-01 00:00:00 +0000 | |||
1436 | @@ -1,466 +0,0 @@ | |||
1437 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
1438 | 2 | /* | ||
1439 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
1440 | 4 | * | ||
1441 | 5 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
1442 | 6 | * | ||
1443 | 7 | * This library is free software; you can redistribute it and/or | ||
1444 | 8 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
1445 | 9 | * License as published by the Free Software Foundation. | ||
1446 | 10 | * | ||
1447 | 11 | * This program is distributed in the hope that it will be useful, | ||
1448 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1449 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1450 | 14 | * General Public License for more details. | ||
1451 | 15 | * | ||
1452 | 16 | * You should have received a copy of the GNU Lesser General Public | ||
1453 | 17 | * License along with this library; if not, write to the | ||
1454 | 18 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1455 | 19 | * Boston, MA 02110-1301, USA. | ||
1456 | 20 | */ | ||
1457 | 21 | |||
1458 | 22 | #include "couchdb-glib.h" | ||
1459 | 23 | #include "utils.h" | ||
1460 | 24 | |||
1461 | 25 | /* | ||
1462 | 26 | * CouchDBDatabaseInfo object | ||
1463 | 27 | */ | ||
1464 | 28 | |||
1465 | 29 | GType | ||
1466 | 30 | couchdb_database_info_get_type (void) | ||
1467 | 31 | { | ||
1468 | 32 | static GType object_type = 0; | ||
1469 | 33 | |||
1470 | 34 | if (G_UNLIKELY (!object_type)) | ||
1471 | 35 | object_type = g_boxed_type_register_static (g_intern_static_string ("CouchDBDatabaseInfo"), | ||
1472 | 36 | (GBoxedCopyFunc) couchdb_database_info_ref, | ||
1473 | 37 | (GBoxedFreeFunc) couchdb_database_info_unref); | ||
1474 | 38 | |||
1475 | 39 | return object_type; | ||
1476 | 40 | } | ||
1477 | 41 | |||
1478 | 42 | CouchDBDatabaseInfo * | ||
1479 | 43 | couchdb_database_info_new (const char *dbname, | ||
1480 | 44 | gint doc_count, | ||
1481 | 45 | gint doc_del_count, | ||
1482 | 46 | gint update_seq, | ||
1483 | 47 | gboolean compact_running, | ||
1484 | 48 | gint disk_size) | ||
1485 | 49 | { | ||
1486 | 50 | CouchDBDatabaseInfo *dbinfo; | ||
1487 | 51 | |||
1488 | 52 | dbinfo = g_slice_new (CouchDBDatabaseInfo); | ||
1489 | 53 | dbinfo->ref_count = 1; | ||
1490 | 54 | dbinfo->dbname = g_strdup (dbname); | ||
1491 | 55 | dbinfo->doc_count = doc_count; | ||
1492 | 56 | dbinfo->doc_del_count = doc_del_count; | ||
1493 | 57 | dbinfo->update_seq = update_seq; | ||
1494 | 58 | dbinfo->compact_running = compact_running; | ||
1495 | 59 | dbinfo->disk_size = disk_size; | ||
1496 | 60 | |||
1497 | 61 | return dbinfo; | ||
1498 | 62 | } | ||
1499 | 63 | |||
1500 | 64 | CouchDBDatabaseInfo * | ||
1501 | 65 | couchdb_database_info_ref (CouchDBDatabaseInfo *dbinfo) | ||
1502 | 66 | { | ||
1503 | 67 | g_return_val_if_fail (dbinfo != NULL, NULL); | ||
1504 | 68 | g_return_val_if_fail (dbinfo->ref_count > 0, NULL); | ||
1505 | 69 | |||
1506 | 70 | g_atomic_int_exchange_and_add (&dbinfo->ref_count, 1); | ||
1507 | 71 | |||
1508 | 72 | return dbinfo; | ||
1509 | 73 | } | ||
1510 | 74 | |||
1511 | 75 | void | ||
1512 | 76 | couchdb_database_info_unref (CouchDBDatabaseInfo *dbinfo) | ||
1513 | 77 | { | ||
1514 | 78 | gint old_ref; | ||
1515 | 79 | |||
1516 | 80 | g_return_if_fail (dbinfo != NULL); | ||
1517 | 81 | g_return_if_fail (dbinfo->ref_count > 0); | ||
1518 | 82 | |||
1519 | 83 | old_ref = g_atomic_int_get (&dbinfo->ref_count); | ||
1520 | 84 | if (old_ref > 1) | ||
1521 | 85 | g_atomic_int_compare_and_exchange (&dbinfo->ref_count, old_ref, old_ref - 1); | ||
1522 | 86 | else { | ||
1523 | 87 | g_free (dbinfo->dbname); | ||
1524 | 88 | g_slice_free (CouchDBDatabaseInfo, dbinfo); | ||
1525 | 89 | } | ||
1526 | 90 | } | ||
1527 | 91 | |||
1528 | 92 | const char * | ||
1529 | 93 | couchdb_database_info_get_dbname (CouchDBDatabaseInfo *dbinfo) | ||
1530 | 94 | { | ||
1531 | 95 | g_return_val_if_fail (dbinfo != NULL, NULL); | ||
1532 | 96 | |||
1533 | 97 | return (const char *) dbinfo->dbname; | ||
1534 | 98 | } | ||
1535 | 99 | |||
1536 | 100 | gint | ||
1537 | 101 | couchdb_database_info_get_documents_count (CouchDBDatabaseInfo *dbinfo) | ||
1538 | 102 | { | ||
1539 | 103 | g_return_val_if_fail (dbinfo != NULL, 0); | ||
1540 | 104 | |||
1541 | 105 | return dbinfo->doc_count; | ||
1542 | 106 | } | ||
1543 | 107 | |||
1544 | 108 | gint | ||
1545 | 109 | couchdb_database_info_get_deleted_documents_count (CouchDBDatabaseInfo *dbinfo) | ||
1546 | 110 | { | ||
1547 | 111 | g_return_val_if_fail (dbinfo != NULL, 0); | ||
1548 | 112 | |||
1549 | 113 | return dbinfo->doc_del_count; | ||
1550 | 114 | } | ||
1551 | 115 | |||
1552 | 116 | gint | ||
1553 | 117 | couchdb_database_info_get_update_sequence (CouchDBDatabaseInfo *dbinfo) | ||
1554 | 118 | { | ||
1555 | 119 | g_return_val_if_fail (dbinfo != NULL, 0); | ||
1556 | 120 | |||
1557 | 121 | return dbinfo->update_seq; | ||
1558 | 122 | } | ||
1559 | 123 | |||
1560 | 124 | gboolean | ||
1561 | 125 | couchdb_database_info_is_compact_running (CouchDBDatabaseInfo *dbinfo) | ||
1562 | 126 | { | ||
1563 | 127 | g_return_val_if_fail (dbinfo != NULL, FALSE); | ||
1564 | 128 | |||
1565 | 129 | return dbinfo->compact_running; | ||
1566 | 130 | } | ||
1567 | 131 | |||
1568 | 132 | gint | ||
1569 | 133 | couchdb_database_info_get_disk_size (CouchDBDatabaseInfo *dbinfo) | ||
1570 | 134 | { | ||
1571 | 135 | g_return_val_if_fail (dbinfo != NULL, 0); | ||
1572 | 136 | |||
1573 | 137 | return dbinfo->disk_size; | ||
1574 | 138 | } | ||
1575 | 139 | |||
1576 | 140 | /* | ||
1577 | 141 | * CouchDBDocumentInfo object | ||
1578 | 142 | */ | ||
1579 | 143 | |||
1580 | 144 | GType | ||
1581 | 145 | couchdb_document_info_get_type (void) | ||
1582 | 146 | { | ||
1583 | 147 | static GType object_type = 0; | ||
1584 | 148 | |||
1585 | 149 | if (G_UNLIKELY (!object_type)) | ||
1586 | 150 | object_type = g_boxed_type_register_static (g_intern_static_string ("CouchDBDocumentInfo"), | ||
1587 | 151 | (GBoxedCopyFunc) couchdb_document_info_ref, | ||
1588 | 152 | (GBoxedFreeFunc) couchdb_document_info_unref); | ||
1589 | 153 | |||
1590 | 154 | return object_type; | ||
1591 | 155 | } | ||
1592 | 156 | |||
1593 | 157 | CouchDBDocumentInfo * | ||
1594 | 158 | couchdb_document_info_new (const char *docid, const char *revision) | ||
1595 | 159 | { | ||
1596 | 160 | CouchDBDocumentInfo *doc_info; | ||
1597 | 161 | |||
1598 | 162 | doc_info = g_slice_new (CouchDBDocumentInfo); | ||
1599 | 163 | doc_info->ref_count = 1; | ||
1600 | 164 | doc_info->docid = g_strdup (docid); | ||
1601 | 165 | doc_info->revision = g_strdup (revision); | ||
1602 | 166 | |||
1603 | 167 | return doc_info; | ||
1604 | 168 | } | ||
1605 | 169 | |||
1606 | 170 | CouchDBDocumentInfo * | ||
1607 | 171 | couchdb_document_info_ref (CouchDBDocumentInfo *doc_info) | ||
1608 | 172 | { | ||
1609 | 173 | g_return_val_if_fail (doc_info != NULL, NULL); | ||
1610 | 174 | g_return_val_if_fail (doc_info->ref_count > 0, NULL); | ||
1611 | 175 | |||
1612 | 176 | g_atomic_int_exchange_and_add (&doc_info->ref_count, 1); | ||
1613 | 177 | |||
1614 | 178 | return doc_info; | ||
1615 | 179 | } | ||
1616 | 180 | |||
1617 | 181 | void | ||
1618 | 182 | couchdb_document_info_unref (CouchDBDocumentInfo *doc_info) | ||
1619 | 183 | { | ||
1620 | 184 | gint old_ref; | ||
1621 | 185 | |||
1622 | 186 | g_return_if_fail (doc_info != NULL); | ||
1623 | 187 | g_return_if_fail (doc_info->ref_count > 0); | ||
1624 | 188 | |||
1625 | 189 | old_ref = g_atomic_int_get (&doc_info->ref_count); | ||
1626 | 190 | if (old_ref > 1) | ||
1627 | 191 | g_atomic_int_compare_and_exchange (&doc_info->ref_count, old_ref, old_ref - 1); | ||
1628 | 192 | else { | ||
1629 | 193 | g_free (doc_info->docid); | ||
1630 | 194 | g_free (doc_info->revision); | ||
1631 | 195 | g_slice_free (CouchDBDocumentInfo, doc_info); | ||
1632 | 196 | } | ||
1633 | 197 | } | ||
1634 | 198 | |||
1635 | 199 | const char * | ||
1636 | 200 | couchdb_document_info_get_docid (CouchDBDocumentInfo *doc_info) | ||
1637 | 201 | { | ||
1638 | 202 | g_return_val_if_fail (doc_info != NULL, NULL); | ||
1639 | 203 | |||
1640 | 204 | return (const char *) doc_info->docid; | ||
1641 | 205 | } | ||
1642 | 206 | |||
1643 | 207 | const char * | ||
1644 | 208 | couchdb_document_info_get_revision (CouchDBDocumentInfo *doc_info) | ||
1645 | 209 | { | ||
1646 | 210 | g_return_val_if_fail (doc_info != NULL, NULL); | ||
1647 | 211 | |||
1648 | 212 | return (const char *) doc_info->revision; | ||
1649 | 213 | } | ||
1650 | 214 | |||
1651 | 215 | /* | ||
1652 | 216 | * CouchDBStructField | ||
1653 | 217 | */ | ||
1654 | 218 | GType | ||
1655 | 219 | couchdb_struct_field_get_type (void) | ||
1656 | 220 | { | ||
1657 | 221 | static GType object_type = 0; | ||
1658 | 222 | |||
1659 | 223 | if (G_UNLIKELY (!object_type)) | ||
1660 | 224 | object_type = g_boxed_type_register_static (g_intern_static_string ("CouchDBStructField"), | ||
1661 | 225 | (GBoxedCopyFunc) couchdb_struct_field_ref, | ||
1662 | 226 | (GBoxedFreeFunc) couchdb_struct_field_unref); | ||
1663 | 227 | |||
1664 | 228 | return object_type; | ||
1665 | 229 | } | ||
1666 | 230 | |||
1667 | 231 | CouchDBStructField * | ||
1668 | 232 | couchdb_struct_field_new (void) | ||
1669 | 233 | { | ||
1670 | 234 | CouchDBStructField *sf; | ||
1671 | 235 | |||
1672 | 236 | sf = g_slice_new (CouchDBStructField); | ||
1673 | 237 | sf->ref_count = 1; | ||
1674 | 238 | sf->json_object = json_object_new (); | ||
1675 | 239 | sf->uuid = NULL; | ||
1676 | 240 | |||
1677 | 241 | return sf; | ||
1678 | 242 | } | ||
1679 | 243 | |||
1680 | 244 | CouchDBStructField * | ||
1681 | 245 | couchdb_struct_field_new_from_string (const char *str) | ||
1682 | 246 | { | ||
1683 | 247 | JsonParser *parser; | ||
1684 | 248 | GError *error = NULL; | ||
1685 | 249 | CouchDBStructField *sf = NULL; | ||
1686 | 250 | |||
1687 | 251 | g_return_val_if_fail (str != NULL, NULL); | ||
1688 | 252 | |||
1689 | 253 | parser = json_parser_new (); | ||
1690 | 254 | if (json_parser_load_from_data (parser, str, strlen (str), &error)) { | ||
1691 | 255 | JsonNode *node = json_parser_get_root (parser); | ||
1692 | 256 | |||
1693 | 257 | if (json_node_get_node_type (node) == JSON_NODE_OBJECT) | ||
1694 | 258 | sf = couchdb_struct_field_new_from_json_object (json_node_get_object (node)); | ||
1695 | 259 | } else { | ||
1696 | 260 | g_warning ("Could not parse string: %s", error->message); | ||
1697 | 261 | g_error_free (error); | ||
1698 | 262 | } | ||
1699 | 263 | |||
1700 | 264 | g_object_unref (G_OBJECT (parser)); | ||
1701 | 265 | |||
1702 | 266 | return sf; | ||
1703 | 267 | } | ||
1704 | 268 | |||
1705 | 269 | CouchDBStructField * | ||
1706 | 270 | couchdb_struct_field_new_from_json_object (JsonObject *json_object) | ||
1707 | 271 | { | ||
1708 | 272 | CouchDBStructField *sf; | ||
1709 | 273 | |||
1710 | 274 | sf = g_slice_new (CouchDBStructField); | ||
1711 | 275 | sf->ref_count = 1; | ||
1712 | 276 | sf->json_object = json_object_ref (json_object); | ||
1713 | 277 | sf->uuid = NULL; | ||
1714 | 278 | |||
1715 | 279 | return sf; | ||
1716 | 280 | } | ||
1717 | 281 | |||
1718 | 282 | CouchDBStructField * | ||
1719 | 283 | couchdb_struct_field_ref (CouchDBStructField *sf) | ||
1720 | 284 | { | ||
1721 | 285 | g_return_val_if_fail (sf != NULL, NULL); | ||
1722 | 286 | g_return_val_if_fail (sf->ref_count > 0, NULL); | ||
1723 | 287 | |||
1724 | 288 | g_atomic_int_exchange_and_add (&sf->ref_count, 1); | ||
1725 | 289 | |||
1726 | 290 | return sf; | ||
1727 | 291 | } | ||
1728 | 292 | |||
1729 | 293 | void | ||
1730 | 294 | couchdb_struct_field_unref (CouchDBStructField *sf) | ||
1731 | 295 | { | ||
1732 | 296 | gint old_ref; | ||
1733 | 297 | |||
1734 | 298 | g_return_if_fail (sf != NULL); | ||
1735 | 299 | g_return_if_fail (sf->ref_count > 0); | ||
1736 | 300 | |||
1737 | 301 | old_ref = g_atomic_int_get (&sf->ref_count); | ||
1738 | 302 | if (old_ref > 1) | ||
1739 | 303 | g_atomic_int_compare_and_exchange (&sf->ref_count, old_ref, old_ref - 1); | ||
1740 | 304 | else { | ||
1741 | 305 | json_object_unref (sf->json_object); | ||
1742 | 306 | g_slice_free (CouchDBStructField, sf); | ||
1743 | 307 | } | ||
1744 | 308 | } | ||
1745 | 309 | |||
1746 | 310 | gboolean | ||
1747 | 311 | couchdb_struct_field_has_field (CouchDBStructField *sf, const char *field) | ||
1748 | 312 | { | ||
1749 | 313 | g_return_val_if_fail (sf != NULL, FALSE); | ||
1750 | 314 | g_return_val_if_fail (field != NULL, FALSE); | ||
1751 | 315 | |||
1752 | 316 | return json_object_has_member (sf->json_object, field); | ||
1753 | 317 | } | ||
1754 | 318 | |||
1755 | 319 | void | ||
1756 | 320 | couchdb_struct_field_remove_field (CouchDBStructField *sf, const char *field) | ||
1757 | 321 | { | ||
1758 | 322 | g_return_if_fail (sf != NULL); | ||
1759 | 323 | g_return_if_fail (field != NULL); | ||
1760 | 324 | |||
1761 | 325 | json_object_remove_member (sf->json_object, field); | ||
1762 | 326 | } | ||
1763 | 327 | |||
1764 | 328 | gboolean | ||
1765 | 329 | couchdb_struct_field_get_boolean_field (CouchDBStructField *sf, const char *field) | ||
1766 | 330 | { | ||
1767 | 331 | g_return_val_if_fail (sf != NULL, 0); | ||
1768 | 332 | g_return_val_if_fail (field != NULL, 0); | ||
1769 | 333 | |||
1770 | 334 | return json_object_get_boolean_member (sf->json_object, field); | ||
1771 | 335 | } | ||
1772 | 336 | |||
1773 | 337 | void | ||
1774 | 338 | couchdb_struct_field_set_boolean_field (CouchDBStructField *sf, const char *field, gboolean value) | ||
1775 | 339 | { | ||
1776 | 340 | g_return_if_fail (sf != NULL); | ||
1777 | 341 | g_return_if_fail (field != NULL); | ||
1778 | 342 | |||
1779 | 343 | json_object_set_boolean_member (sf->json_object, field, value); | ||
1780 | 344 | } | ||
1781 | 345 | |||
1782 | 346 | gdouble | ||
1783 | 347 | couchdb_struct_field_get_double_field (CouchDBStructField *sf, const char *field) | ||
1784 | 348 | { | ||
1785 | 349 | g_return_val_if_fail (sf != NULL, 0); | ||
1786 | 350 | g_return_val_if_fail (field != NULL, 0); | ||
1787 | 351 | |||
1788 | 352 | return json_object_get_double_member (sf->json_object, field); | ||
1789 | 353 | } | ||
1790 | 354 | |||
1791 | 355 | void | ||
1792 | 356 | couchdb_struct_field_set_double_field (CouchDBStructField *sf, const char *field, gdouble value) | ||
1793 | 357 | { | ||
1794 | 358 | g_return_if_fail (sf != NULL); | ||
1795 | 359 | g_return_if_fail (field != NULL); | ||
1796 | 360 | |||
1797 | 361 | json_object_set_double_member (sf->json_object, field, value); | ||
1798 | 362 | } | ||
1799 | 363 | |||
1800 | 364 | gint | ||
1801 | 365 | couchdb_struct_field_get_int_field (CouchDBStructField *sf, const char *field) | ||
1802 | 366 | { | ||
1803 | 367 | g_return_val_if_fail (sf != NULL, 0); | ||
1804 | 368 | g_return_val_if_fail (field != NULL, 0); | ||
1805 | 369 | |||
1806 | 370 | return json_object_get_int_member (sf->json_object, field); | ||
1807 | 371 | } | ||
1808 | 372 | |||
1809 | 373 | void | ||
1810 | 374 | couchdb_struct_field_set_int_field (CouchDBStructField *sf, const char *field, gint value) | ||
1811 | 375 | { | ||
1812 | 376 | g_return_if_fail (sf != NULL); | ||
1813 | 377 | g_return_if_fail (field != NULL); | ||
1814 | 378 | |||
1815 | 379 | json_object_set_int_member (sf->json_object, field, value); | ||
1816 | 380 | } | ||
1817 | 381 | |||
1818 | 382 | const char * | ||
1819 | 383 | couchdb_struct_field_get_string_field (CouchDBStructField *sf, const char *field) | ||
1820 | 384 | { | ||
1821 | 385 | g_return_val_if_fail (sf != NULL, NULL); | ||
1822 | 386 | g_return_val_if_fail (field != NULL, NULL); | ||
1823 | 387 | |||
1824 | 388 | return json_object_get_string_member (sf->json_object, field); | ||
1825 | 389 | } | ||
1826 | 390 | |||
1827 | 391 | void | ||
1828 | 392 | couchdb_struct_field_set_string_field (CouchDBStructField *sf, const char *field, const char *value) | ||
1829 | 393 | { | ||
1830 | 394 | g_return_if_fail (sf != NULL); | ||
1831 | 395 | g_return_if_fail (field != NULL); | ||
1832 | 396 | |||
1833 | 397 | if (value) | ||
1834 | 398 | json_object_set_string_member (sf->json_object, field, value); | ||
1835 | 399 | else { | ||
1836 | 400 | /* Remove the field if the value is NULL */ | ||
1837 | 401 | couchdb_struct_field_remove_field (sf, field); | ||
1838 | 402 | } | ||
1839 | 403 | } | ||
1840 | 404 | |||
1841 | 405 | CouchDBStructField * | ||
1842 | 406 | couchdb_struct_field_get_struct_field (CouchDBStructField *sf, const char *field) | ||
1843 | 407 | { | ||
1844 | 408 | g_return_val_if_fail (sf != NULL, NULL); | ||
1845 | 409 | g_return_val_if_fail (field != NULL, NULL); | ||
1846 | 410 | |||
1847 | 411 | return couchdb_struct_field_new_from_json_object ( | ||
1848 | 412 | json_object_get_object_member (sf->json_object, field)); | ||
1849 | 413 | } | ||
1850 | 414 | |||
1851 | 415 | void | ||
1852 | 416 | couchdb_struct_field_set_struct_field (CouchDBStructField *sf, const char *field, CouchDBStructField *value) | ||
1853 | 417 | { | ||
1854 | 418 | g_return_if_fail (sf != NULL); | ||
1855 | 419 | g_return_if_fail (field != NULL); | ||
1856 | 420 | g_return_if_fail (value != NULL); | ||
1857 | 421 | |||
1858 | 422 | json_object_set_object_member (sf->json_object, field, json_object_ref (value->json_object)); | ||
1859 | 423 | } | ||
1860 | 424 | |||
1861 | 425 | const char * | ||
1862 | 426 | couchdb_struct_field_get_uuid (CouchDBStructField *sf) | ||
1863 | 427 | { | ||
1864 | 428 | g_return_val_if_fail (sf != NULL, NULL); | ||
1865 | 429 | |||
1866 | 430 | return (const char *) sf->uuid; | ||
1867 | 431 | } | ||
1868 | 432 | |||
1869 | 433 | void | ||
1870 | 434 | couchdb_struct_field_set_uuid (CouchDBStructField *sf, const char *uuid) | ||
1871 | 435 | { | ||
1872 | 436 | g_return_if_fail (sf != NULL); | ||
1873 | 437 | |||
1874 | 438 | if (sf->uuid) | ||
1875 | 439 | g_free (sf->uuid); | ||
1876 | 440 | |||
1877 | 441 | sf->uuid = g_strdup (uuid); | ||
1878 | 442 | } | ||
1879 | 443 | |||
1880 | 444 | char * | ||
1881 | 445 | couchdb_struct_field_to_string (CouchDBStructField *sf) | ||
1882 | 446 | { | ||
1883 | 447 | JsonNode *node; | ||
1884 | 448 | JsonGenerator *generator; | ||
1885 | 449 | gsize size; | ||
1886 | 450 | char *str = NULL; | ||
1887 | 451 | |||
1888 | 452 | g_return_val_if_fail (sf != NULL, NULL); | ||
1889 | 453 | |||
1890 | 454 | node = json_node_new (JSON_NODE_OBJECT); | ||
1891 | 455 | json_node_set_object (node, sf->json_object); | ||
1892 | 456 | |||
1893 | 457 | generator = json_generator_new (); | ||
1894 | 458 | json_generator_set_root (generator, node); | ||
1895 | 459 | |||
1896 | 460 | str = json_generator_to_data (generator, &size); | ||
1897 | 461 | g_object_unref (G_OBJECT (generator)); | ||
1898 | 462 | |||
1899 | 463 | json_node_free (node); | ||
1900 | 464 | |||
1901 | 465 | return str; | ||
1902 | 466 | } | ||
1903 | 467 | 0 | ||
1904 | === added file 'couchdb-glib/couchdb-types.h' | |||
1905 | --- couchdb-glib/couchdb-types.h 1970-01-01 00:00:00 +0000 | |||
1906 | +++ couchdb-glib/couchdb-types.h 2009-10-06 18:10:22 +0000 | |||
1907 | @@ -0,0 +1,39 @@ | |||
1908 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
1909 | 2 | /* | ||
1910 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
1911 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
1912 | 5 | * | ||
1913 | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
1914 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
1915 | 8 | * | ||
1916 | 9 | * This library is free software; you can redistribute it and/or | ||
1917 | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
1918 | 11 | * License as published by the Free Software Foundation. | ||
1919 | 12 | * | ||
1920 | 13 | * This program is distributed in the hope that it will be useful, | ||
1921 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1922 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1923 | 16 | * General Public License for more details. | ||
1924 | 17 | * | ||
1925 | 18 | * You should have received a copy of the GNU Lesser General Public | ||
1926 | 19 | * License along with this library; if not, write to the | ||
1927 | 20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1928 | 21 | * Boston, MA 02110-1301, USA. | ||
1929 | 22 | */ | ||
1930 | 23 | |||
1931 | 24 | #ifndef __COUCHDB_TYPES_H__ | ||
1932 | 25 | #define __COUCHDB_TYPES_H__ | ||
1933 | 26 | |||
1934 | 27 | #include <glib.h> | ||
1935 | 28 | |||
1936 | 29 | G_BEGIN_DECLS | ||
1937 | 30 | |||
1938 | 31 | typedef struct _CouchDBDocument CouchDBDocument; | ||
1939 | 32 | typedef struct _CouchDB CouchDB; | ||
1940 | 33 | typedef struct _CouchDBDatabaseInfo CouchDBDatabaseInfo; | ||
1941 | 34 | typedef struct _CouchDBDocumentInfo CouchDBDocumentInfo; | ||
1942 | 35 | typedef struct _CouchDBStructField CouchDBStructField; | ||
1943 | 36 | |||
1944 | 37 | G_END_DECLS | ||
1945 | 38 | |||
1946 | 39 | #endif /* __COUCHDB_TYPES_H__ */ | ||
1947 | 0 | 40 | ||
1948 | === removed file 'couchdb-glib/couchdb-types.h' | |||
1949 | --- couchdb-glib/couchdb-types.h 2009-08-19 16:43:24 +0000 | |||
1950 | +++ couchdb-glib/couchdb-types.h 1970-01-01 00:00:00 +0000 | |||
1951 | @@ -1,89 +0,0 @@ | |||
1952 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
1953 | 2 | /* | ||
1954 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
1955 | 4 | * | ||
1956 | 5 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
1957 | 6 | * | ||
1958 | 7 | * This library is free software; you can redistribute it and/or | ||
1959 | 8 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
1960 | 9 | * License as published by the Free Software Foundation. | ||
1961 | 10 | * | ||
1962 | 11 | * This program is distributed in the hope that it will be useful, | ||
1963 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1964 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
1965 | 14 | * General Public License for more details. | ||
1966 | 15 | * | ||
1967 | 16 | * You should have received a copy of the GNU Lesser General Public | ||
1968 | 17 | * License along with this library; if not, write to the | ||
1969 | 18 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
1970 | 19 | * Boston, MA 02110-1301, USA. | ||
1971 | 20 | */ | ||
1972 | 21 | |||
1973 | 22 | #ifndef __COUCHDB_TYPES_H__ | ||
1974 | 23 | #define __COUCHDB_TYPES_H__ | ||
1975 | 24 | |||
1976 | 25 | #include <glib-object.h> | ||
1977 | 26 | |||
1978 | 27 | #define COUCHDB_TYPE_DATABASE_INFO (couchdb_database_info_get_type ()) | ||
1979 | 28 | #define COUCHDB_TYPE_DOCUMENT_INFO (couchdb_document_info_get_type ()) | ||
1980 | 29 | #define COUCHDB_TYPE_STRUCT_FIELD (couchdb_struct_field_get_type ()) | ||
1981 | 30 | |||
1982 | 31 | /* | ||
1983 | 32 | * CouchDBDatabaseInfo | ||
1984 | 33 | */ | ||
1985 | 34 | typedef struct _CouchDBDatabaseInfo CouchDBDatabaseInfo; | ||
1986 | 35 | |||
1987 | 36 | GType couchdb_database_info_get_type (void); | ||
1988 | 37 | CouchDBDatabaseInfo *couchdb_database_info_ref (CouchDBDatabaseInfo *dbinfo); | ||
1989 | 38 | void couchdb_database_info_unref (CouchDBDatabaseInfo *dbinfo); | ||
1990 | 39 | |||
1991 | 40 | const char *couchdb_database_info_get_dbname (CouchDBDatabaseInfo *dbinfo); | ||
1992 | 41 | gint couchdb_database_info_get_documents_count (CouchDBDatabaseInfo *dbinfo); | ||
1993 | 42 | gint couchdb_database_info_get_deleted_documents_count (CouchDBDatabaseInfo *dbinfo); | ||
1994 | 43 | gint couchdb_database_info_get_update_sequence (CouchDBDatabaseInfo *dbinfo); | ||
1995 | 44 | gboolean couchdb_database_info_is_compact_running (CouchDBDatabaseInfo *dbinfo); | ||
1996 | 45 | gint couchdb_database_info_get_disk_size (CouchDBDatabaseInfo *dbinfo); | ||
1997 | 46 | |||
1998 | 47 | /* | ||
1999 | 48 | * CouchDBDocumentInfo | ||
2000 | 49 | */ | ||
2001 | 50 | typedef struct _CouchDBDocumentInfo CouchDBDocumentInfo; | ||
2002 | 51 | |||
2003 | 52 | GType couchdb_document_info_get_type (void); | ||
2004 | 53 | CouchDBDocumentInfo *couchdb_document_info_ref (CouchDBDocumentInfo *doc_info); | ||
2005 | 54 | void couchdb_document_info_unref (CouchDBDocumentInfo *doc_info); | ||
2006 | 55 | |||
2007 | 56 | const char *couchdb_document_info_get_docid (CouchDBDocumentInfo *doc_info); | ||
2008 | 57 | const char *couchdb_document_info_get_revision (CouchDBDocumentInfo *doc_info); | ||
2009 | 58 | |||
2010 | 59 | /* | ||
2011 | 60 | * CouchDBStructField | ||
2012 | 61 | */ | ||
2013 | 62 | typedef struct _CouchDBStructField CouchDBStructField; | ||
2014 | 63 | |||
2015 | 64 | GType couchdb_struct_field_get_type (void); | ||
2016 | 65 | CouchDBStructField *couchdb_struct_field_new (void); | ||
2017 | 66 | CouchDBStructField *couchdb_struct_field_new_from_string (const char *str); | ||
2018 | 67 | CouchDBStructField *couchdb_struct_field_ref (CouchDBStructField *sf); | ||
2019 | 68 | void couchdb_struct_field_unref (CouchDBStructField *sf); | ||
2020 | 69 | |||
2021 | 70 | gboolean couchdb_struct_field_has_field (CouchDBStructField *sf, const char *field); | ||
2022 | 71 | void couchdb_struct_field_remove_field (CouchDBStructField *sf, const char *field); | ||
2023 | 72 | |||
2024 | 73 | gboolean couchdb_struct_field_get_boolean_field (CouchDBStructField *sf, const char *field); | ||
2025 | 74 | void couchdb_struct_field_set_boolean_field (CouchDBStructField *sf, const char *field, gboolean value); | ||
2026 | 75 | gdouble couchdb_struct_field_get_double_field (CouchDBStructField *sf, const char *field); | ||
2027 | 76 | void couchdb_struct_field_set_double_field (CouchDBStructField *sf, const char *field, gdouble value); | ||
2028 | 77 | gint couchdb_struct_field_get_int_field (CouchDBStructField *sf, const char *field); | ||
2029 | 78 | void couchdb_struct_field_set_int_field (CouchDBStructField *sf, const char *field, gint value); | ||
2030 | 79 | const char *couchdb_struct_field_get_string_field (CouchDBStructField *sf, const char *field); | ||
2031 | 80 | void couchdb_struct_field_set_string_field (CouchDBStructField *sf, const char *field, const char *value); | ||
2032 | 81 | CouchDBStructField *couchdb_struct_field_get_struct_field (CouchDBStructField *sf, const char *field); | ||
2033 | 82 | void couchdb_struct_field_set_struct_field (CouchDBStructField *sf, const char *field, CouchDBStructField *value); | ||
2034 | 83 | |||
2035 | 84 | const char *couchdb_struct_field_get_uuid (CouchDBStructField *sf); | ||
2036 | 85 | void couchdb_struct_field_set_uuid (CouchDBStructField *sf, const char *uuid); | ||
2037 | 86 | |||
2038 | 87 | char *couchdb_struct_field_to_string (CouchDBStructField *sf); | ||
2039 | 88 | |||
2040 | 89 | #endif | ||
2041 | 90 | 0 | ||
2042 | === modified file 'couchdb-glib/couchdb.c' | |||
2043 | --- couchdb-glib/couchdb.c 2009-09-21 22:34:56 +0000 | |||
2044 | +++ couchdb-glib/couchdb.c 2009-10-06 18:10:22 +0000 | |||
2045 | @@ -1,8 +1,10 @@ | |||
2046 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
2047 | 2 | /* | 2 | /* |
2048 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) |
2049 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
2050 | 4 | * | 5 | * |
2051 | 5 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> |
2052 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
2053 | 6 | * | 8 | * |
2054 | 7 | * This library is free software; you can redistribute it and/or | 9 | * This library is free software; you can redistribute it and/or |
2055 | 8 | * modify it under the terms of version 2 of the GNU Lesser General Public | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public |
2056 | @@ -21,11 +23,32 @@ | |||
2057 | 21 | 23 | ||
2058 | 22 | #include <libsoup/soup-logger.h> | 24 | #include <libsoup/soup-logger.h> |
2059 | 23 | #include <libsoup/soup-gnome.h> | 25 | #include <libsoup/soup-gnome.h> |
2062 | 24 | #include <json-glib/json-glib.h> | 26 | #include <libsoup/soup-message.h> |
2063 | 25 | #include "couchdb-glib.h" | 27 | #include "couchdb.h" |
2064 | 28 | #include "couchdb-document-info.h" | ||
2065 | 26 | #include "couchdb-marshal.h" | 29 | #include "couchdb-marshal.h" |
2066 | 27 | #include "dbwatch.h" | 30 | #include "dbwatch.h" |
2067 | 28 | #include "utils.h" | 31 | #include "utils.h" |
2068 | 32 | #include <string.h> | ||
2069 | 33 | #ifdef HAVE_OAUTH | ||
2070 | 34 | #include <time.h> | ||
2071 | 35 | #include "oauth.h" | ||
2072 | 36 | #endif | ||
2073 | 37 | |||
2074 | 38 | struct _CouchDB { | ||
2075 | 39 | GObject parent; | ||
2076 | 40 | |||
2077 | 41 | char *hostname; | ||
2078 | 42 | SoupSession *http_session; | ||
2079 | 43 | |||
2080 | 44 | GHashTable *db_watchlist; | ||
2081 | 45 | |||
2082 | 46 | gboolean oauth_enabled; | ||
2083 | 47 | char *oauth_consumer_key; | ||
2084 | 48 | char *oauth_consumer_secret; | ||
2085 | 49 | char *oauth_token_key; | ||
2086 | 50 | char *oauth_token_secret; | ||
2087 | 51 | }; | ||
2088 | 29 | 52 | ||
2089 | 30 | G_DEFINE_TYPE(CouchDB, couchdb, G_TYPE_OBJECT) | 53 | G_DEFINE_TYPE(CouchDB, couchdb, G_TYPE_OBJECT) |
2090 | 31 | 54 | ||
2091 | @@ -49,12 +72,14 @@ | |||
2092 | 49 | g_free (couchdb->hostname); | 72 | g_free (couchdb->hostname); |
2093 | 50 | g_object_unref (couchdb->http_session); | 73 | g_object_unref (couchdb->http_session); |
2094 | 51 | 74 | ||
2101 | 52 | #ifdef HAVE_OAUTH | 75 | if (couchdb->oauth_consumer_key) |
2102 | 53 | g_free (couchdb->oauth_consumer_key); | 76 | g_free (couchdb->oauth_consumer_key); |
2103 | 54 | g_free (couchdb->oauth_consumer_secret); | 77 | if (couchdb->oauth_consumer_secret) |
2104 | 55 | g_free (couchdb->oauth_token_key); | 78 | g_free (couchdb->oauth_consumer_secret); |
2105 | 56 | g_free (couchdb->oauth_token_secret); | 79 | if (couchdb->oauth_token_key) |
2106 | 57 | #endif | 80 | g_free (couchdb->oauth_token_key); |
2107 | 81 | if (couchdb->oauth_token_secret) | ||
2108 | 82 | g_free (couchdb->oauth_token_secret); | ||
2109 | 58 | 83 | ||
2110 | 59 | G_OBJECT_CLASS (couchdb_parent_class)->finalize (object); | 84 | G_OBJECT_CLASS (couchdb_parent_class)->finalize (object); |
2111 | 60 | } | 85 | } |
2112 | @@ -135,6 +160,13 @@ | |||
2113 | 135 | couchdb->http_session = soup_session_sync_new_with_options ( | 160 | couchdb->http_session = soup_session_sync_new_with_options ( |
2114 | 136 | SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_GNOME_FEATURES_2_26, | 161 | SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_GNOME_FEATURES_2_26, |
2115 | 137 | NULL); | 162 | NULL); |
2116 | 163 | |||
2117 | 164 | couchdb->oauth_consumer_key = NULL; | ||
2118 | 165 | couchdb->oauth_consumer_secret = NULL; | ||
2119 | 166 | couchdb->oauth_token_key = NULL; | ||
2120 | 167 | couchdb->oauth_token_secret = NULL; | ||
2121 | 168 | couchdb->oauth_enabled = FALSE; | ||
2122 | 169 | |||
2123 | 138 | soup_session_add_feature_by_type (couchdb->http_session, SOUP_TYPE_LOGGER); | 170 | soup_session_add_feature_by_type (couchdb->http_session, SOUP_TYPE_LOGGER); |
2124 | 139 | 171 | ||
2125 | 140 | return couchdb; | 172 | return couchdb; |
2126 | @@ -159,8 +191,8 @@ | |||
2127 | 159 | 191 | ||
2128 | 160 | /* Prepare request */ | 192 | /* Prepare request */ |
2129 | 161 | url = g_strdup_printf ("%s/_all_dbs", couchdb->hostname); | 193 | url = g_strdup_printf ("%s/_all_dbs", couchdb->hostname); |
2132 | 162 | parser = send_message_and_parse (couchdb, SOUP_METHOD_GET, url, NULL, error); | 194 | parser = json_parser_new (); |
2133 | 163 | if (parser) { | 195 | if (couchdb_send_message (couchdb, SOUP_METHOD_GET, url, NULL, parser, error)) { |
2134 | 164 | JsonNode *root_node; | 196 | JsonNode *root_node; |
2135 | 165 | 197 | ||
2136 | 166 | root_node = json_parser_get_root (parser); | 198 | root_node = json_parser_get_root (parser); |
2137 | @@ -173,10 +205,9 @@ | |||
2138 | 173 | dblist, | 205 | dblist, |
2139 | 174 | g_strdup (json_node_get_string ((JsonNode *) sl->data))); | 206 | g_strdup (json_node_get_string ((JsonNode *) sl->data))); |
2140 | 175 | } | 207 | } |
2144 | 176 | } | 208 | } |
2142 | 177 | |||
2143 | 178 | g_object_unref (G_OBJECT (parser)); | ||
2145 | 179 | } | 209 | } |
2146 | 210 | g_object_unref (G_OBJECT (parser)); | ||
2147 | 180 | 211 | ||
2148 | 181 | /* Free memory */ | 212 | /* Free memory */ |
2149 | 182 | g_free (url); | 213 | g_free (url); |
2150 | @@ -195,8 +226,8 @@ | |||
2151 | 195 | g_return_val_if_fail (dbname != NULL, NULL); | 226 | g_return_val_if_fail (dbname != NULL, NULL); |
2152 | 196 | 227 | ||
2153 | 197 | url = g_strdup_printf ("%s/%s/", couchdb->hostname, dbname); | 228 | url = g_strdup_printf ("%s/%s/", couchdb->hostname, dbname); |
2156 | 198 | parser = send_message_and_parse (couchdb, SOUP_METHOD_GET, url, NULL, error); | 229 | parser = json_parser_new (); |
2157 | 199 | if (parser) { | 230 | if (couchdb_send_message (couchdb, SOUP_METHOD_GET, url, NULL, parser, error)) { |
2158 | 200 | JsonNode *root_node; | 231 | JsonNode *root_node; |
2159 | 201 | 232 | ||
2160 | 202 | root_node = json_parser_get_root (parser); | 233 | root_node = json_parser_get_root (parser); |
2161 | @@ -210,9 +241,8 @@ | |||
2162 | 210 | json_object_get_boolean_member (object, "compact_running"), | 241 | json_object_get_boolean_member (object, "compact_running"), |
2163 | 211 | json_object_get_int_member (object, "disk_size")); | 242 | json_object_get_int_member (object, "disk_size")); |
2164 | 212 | } | 243 | } |
2165 | 213 | |||
2166 | 214 | g_object_unref (G_OBJECT (parser)); | ||
2167 | 215 | } | 244 | } |
2168 | 245 | g_object_unref (G_OBJECT (parser)); | ||
2169 | 216 | 246 | ||
2170 | 217 | return result; | 247 | return result; |
2171 | 218 | } | 248 | } |
2172 | @@ -228,18 +258,17 @@ | |||
2173 | 228 | g_return_val_if_fail (dbname != NULL, FALSE); | 258 | g_return_val_if_fail (dbname != NULL, FALSE); |
2174 | 229 | 259 | ||
2175 | 230 | url = g_strdup_printf ("%s/%s/", couchdb->hostname, dbname); | 260 | url = g_strdup_printf ("%s/%s/", couchdb->hostname, dbname); |
2178 | 231 | parser = send_message_and_parse (couchdb, SOUP_METHOD_PUT, url, NULL, error); | 261 | parser = json_parser_new (); |
2179 | 232 | if (parser) { | 262 | if (couchdb_send_message (couchdb, SOUP_METHOD_PUT, url, NULL, parser, error)) { |
2180 | 233 | JsonNode *root_node; | 263 | JsonNode *root_node; |
2181 | 234 | 264 | ||
2182 | 235 | root_node = json_parser_get_root (parser); | 265 | root_node = json_parser_get_root (parser); |
2183 | 236 | if (json_node_get_node_type (root_node) == JSON_NODE_OBJECT) | 266 | if (json_node_get_node_type (root_node) == JSON_NODE_OBJECT) |
2184 | 237 | result = json_object_get_boolean_member ( | 267 | result = json_object_get_boolean_member ( |
2188 | 238 | json_node_get_object (root_node), "ok"); | 268 | json_node_get_object (root_node), "ok"); |
2186 | 239 | |||
2187 | 240 | g_object_unref (G_OBJECT (parser)); | ||
2189 | 241 | } | 269 | } |
2191 | 242 | 270 | ||
2192 | 271 | g_object_unref (G_OBJECT (parser)); | ||
2193 | 243 | g_free (url); | 272 | g_free (url); |
2194 | 244 | 273 | ||
2195 | 245 | if (result) | 274 | if (result) |
2196 | @@ -259,17 +288,16 @@ | |||
2197 | 259 | g_return_val_if_fail (dbname != NULL, FALSE); | 288 | g_return_val_if_fail (dbname != NULL, FALSE); |
2198 | 260 | 289 | ||
2199 | 261 | url = g_strdup_printf ("%s/%s/", couchdb->hostname, dbname); | 290 | url = g_strdup_printf ("%s/%s/", couchdb->hostname, dbname); |
2202 | 262 | parser = send_message_and_parse (couchdb, SOUP_METHOD_DELETE, url, NULL, error); | 291 | parser = json_parser_new (); |
2203 | 263 | if (parser) { | 292 | if (couchdb_send_message (couchdb, SOUP_METHOD_DELETE, url, NULL, parser, error)) { |
2204 | 264 | JsonNode *root_node; | 293 | JsonNode *root_node; |
2205 | 265 | 294 | ||
2206 | 266 | root_node = json_parser_get_root (parser); | 295 | root_node = json_parser_get_root (parser); |
2207 | 267 | if (json_node_get_node_type (root_node) == JSON_NODE_OBJECT) | 296 | if (json_node_get_node_type (root_node) == JSON_NODE_OBJECT) |
2208 | 268 | result = json_object_get_boolean_member ( | 297 | result = json_object_get_boolean_member ( |
2212 | 269 | json_node_get_object (root_node), "ok"); | 298 | json_node_get_object (root_node), "ok"); |
2210 | 270 | |||
2211 | 271 | g_object_unref (G_OBJECT (parser)); | ||
2213 | 272 | } | 299 | } |
2214 | 300 | g_object_unref (G_OBJECT (parser)); | ||
2215 | 273 | 301 | ||
2216 | 274 | g_free (url); | 302 | g_free (url); |
2217 | 275 | 303 | ||
2218 | @@ -304,8 +332,8 @@ | |||
2219 | 304 | g_return_val_if_fail (dbname != NULL, NULL); | 332 | g_return_val_if_fail (dbname != NULL, NULL); |
2220 | 305 | 333 | ||
2221 | 306 | url = g_strdup_printf ("%s/%s/_all_docs", couchdb->hostname, dbname); | 334 | url = g_strdup_printf ("%s/%s/_all_docs", couchdb->hostname, dbname); |
2224 | 307 | parser = send_message_and_parse (couchdb, SOUP_METHOD_GET, url, NULL, error); | 335 | parser = json_parser_new (); |
2225 | 308 | if (parser) { | 336 | if (couchdb_send_message (couchdb, SOUP_METHOD_GET, url, NULL, parser, error)) { |
2226 | 309 | JsonNode *root_node; | 337 | JsonNode *root_node; |
2227 | 310 | 338 | ||
2228 | 311 | root_node = json_parser_get_root (parser); | 339 | root_node = json_parser_get_root (parser); |
2229 | @@ -332,7 +360,7 @@ | |||
2230 | 332 | } | 360 | } |
2231 | 333 | } | 361 | } |
2232 | 334 | } | 362 | } |
2234 | 335 | 363 | g_object_unref (G_OBJECT (parser)); | |
2235 | 336 | g_free (url); | 364 | g_free (url); |
2236 | 337 | 365 | ||
2237 | 338 | return doclist; | 366 | return doclist; |
2238 | @@ -423,3 +451,158 @@ | |||
2239 | 423 | return FALSE; | 451 | return FALSE; |
2240 | 424 | #endif | 452 | #endif |
2241 | 425 | } | 453 | } |
2242 | 454 | |||
2243 | 455 | gboolean | ||
2244 | 456 | couchdb_is_oauth_enabled (CouchDB *couchdb) | ||
2245 | 457 | { | ||
2246 | 458 | g_return_val_if_fail (COUCHDB_IS (couchdb), FALSE); | ||
2247 | 459 | |||
2248 | 460 | return couchdb->oauth_enabled; | ||
2249 | 461 | } | ||
2250 | 462 | |||
2251 | 463 | |||
2252 | 464 | static void | ||
2253 | 465 | couchdb_add_oauth_signature (CouchDB *couchdb, SoupMessage *http_message, const char *method, const char *url) | ||
2254 | 466 | { | ||
2255 | 467 | /* This method is a no-op if we are configured without OAUTH */ | ||
2256 | 468 | #ifdef HAVE_OAUTH | ||
2257 | 469 | char *signed_url; | ||
2258 | 470 | |||
2259 | 471 | signed_url = oauth_sign_url2 (url, NULL, OA_HMAC, method, | ||
2260 | 472 | couchdb->oauth_consumer_key, | ||
2261 | 473 | couchdb->oauth_consumer_secret, | ||
2262 | 474 | couchdb->oauth_token_key, | ||
2263 | 475 | couchdb->oauth_token_secret); | ||
2264 | 476 | if (signed_url != NULL) { | ||
2265 | 477 | char **parsed_url; | ||
2266 | 478 | GString *header = NULL; | ||
2267 | 479 | |||
2268 | 480 | /* Get the OAuth signature from the signed URL */ | ||
2269 | 481 | parsed_url = g_strsplit (signed_url, "?", 2); | ||
2270 | 482 | if (parsed_url != NULL) { | ||
2271 | 483 | gchar **params; | ||
2272 | 484 | int i; | ||
2273 | 485 | |||
2274 | 486 | params = g_strsplit (parsed_url[1], "&", 0); | ||
2275 | 487 | #ifdef DEBUG_OAUTH | ||
2276 | 488 | g_debug ("Parsing %s", parsed_url[1]); | ||
2277 | 489 | #endif | ||
2278 | 490 | for (i = 0; params[i] != NULL; i++) { | ||
2279 | 491 | gchar **url_param; | ||
2280 | 492 | |||
2281 | 493 | /* Don't include non-OAuth URL parameters in OAuth header */ | ||
2282 | 494 | if (!g_str_has_prefix (params[i], "oauth_")) | ||
2283 | 495 | continue; | ||
2284 | 496 | |||
2285 | 497 | #ifdef DEBUG_OAUTH | ||
2286 | 498 | g_debug ("%s\n", params[i]); | ||
2287 | 499 | #endif | ||
2288 | 500 | url_param = g_strsplit (params[i], "=", 2); | ||
2289 | 501 | if (url_param == NULL) | ||
2290 | 502 | continue; | ||
2291 | 503 | |||
2292 | 504 | if (header != NULL) | ||
2293 | 505 | header = g_string_append (header, ", "); | ||
2294 | 506 | else | ||
2295 | 507 | header = g_string_new ("OAuth "); | ||
2296 | 508 | |||
2297 | 509 | header = g_string_append (header, url_param[0]); | ||
2298 | 510 | header = g_string_append (header, "=\""); | ||
2299 | 511 | header = g_string_append (header, url_param[1]); | ||
2300 | 512 | header = g_string_append (header, "\""); | ||
2301 | 513 | |||
2302 | 514 | g_strfreev (url_param); | ||
2303 | 515 | } | ||
2304 | 516 | |||
2305 | 517 | if (params) | ||
2306 | 518 | g_strfreev (params); | ||
2307 | 519 | |||
2308 | 520 | g_strfreev (parsed_url); | ||
2309 | 521 | } | ||
2310 | 522 | |||
2311 | 523 | if (header != NULL) { | ||
2312 | 524 | soup_message_headers_append (http_message->request_headers, "Authorization", header->str); | ||
2313 | 525 | |||
2314 | 526 | g_string_free (header, TRUE); | ||
2315 | 527 | } | ||
2316 | 528 | |||
2317 | 529 | free (signed_url); | ||
2318 | 530 | } | ||
2319 | 531 | #endif /* HAVE_OAUTH */ | ||
2320 | 532 | } | ||
2321 | 533 | |||
2322 | 534 | static gboolean | ||
2323 | 535 | parse_json_response (CouchDB *couchdb, JsonParser *json_parser, SoupMessage *http_message, GError **error) | ||
2324 | 536 | { | ||
2325 | 537 | SoupBuffer *buffer; | ||
2326 | 538 | GString *str = NULL; | ||
2327 | 539 | goffset offset = 0; | ||
2328 | 540 | gboolean success = TRUE; | ||
2329 | 541 | |||
2330 | 542 | while ((buffer = soup_message_body_get_chunk (http_message->response_body, offset))) { | ||
2331 | 543 | if (!str) | ||
2332 | 544 | str = g_string_new (""); | ||
2333 | 545 | g_string_append_len (str, buffer->data, buffer->length); | ||
2334 | 546 | |||
2335 | 547 | offset += buffer->length; | ||
2336 | 548 | soup_buffer_free (buffer); | ||
2337 | 549 | } | ||
2338 | 550 | |||
2339 | 551 | if (str && str->len > 0) { | ||
2340 | 552 | g_debug ("Response body: %s", str->str); | ||
2341 | 553 | if (!json_parser_load_from_data (json_parser, | ||
2342 | 554 | (const gchar *) str->str, | ||
2343 | 555 | str->len, | ||
2344 | 556 | error)) { | ||
2345 | 557 | g_object_unref (G_OBJECT (json_parser)); | ||
2346 | 558 | g_set_error (error, COUCHDB_ERROR, -1, "Invalid JSON response"); | ||
2347 | 559 | success = FALSE; | ||
2348 | 560 | } | ||
2349 | 561 | |||
2350 | 562 | g_string_free (str, TRUE); | ||
2351 | 563 | } | ||
2352 | 564 | |||
2353 | 565 | return success; | ||
2354 | 566 | } | ||
2355 | 567 | |||
2356 | 568 | static void | ||
2357 | 569 | debug_print_headers (const char *name, const char *value, gpointer user_data) | ||
2358 | 570 | { | ||
2359 | 571 | g_print ("\t%s: %s\n", name, value); | ||
2360 | 572 | } | ||
2361 | 573 | |||
2362 | 574 | gboolean | ||
2363 | 575 | couchdb_send_message (CouchDB *couchdb, const char *method, const char *url, const char *body, JsonParser *parser, GError **error) | ||
2364 | 576 | { | ||
2365 | 577 | SoupMessage *http_message; | ||
2366 | 578 | guint status; | ||
2367 | 579 | |||
2368 | 580 | g_return_val_if_fail (COUCHDB_IS (couchdb), FALSE); | ||
2369 | 581 | g_return_val_if_fail (method != NULL, FALSE); | ||
2370 | 582 | g_return_val_if_fail (error == NULL || *error == NULL, FALSE); | ||
2371 | 583 | |||
2372 | 584 | http_message = soup_message_new (method, url); | ||
2373 | 585 | if (body != NULL) { | ||
2374 | 586 | soup_message_set_request (http_message, "application/json", SOUP_MEMORY_COPY, | ||
2375 | 587 | body, strlen (body)); | ||
2376 | 588 | } | ||
2377 | 589 | |||
2378 | 590 | if (couchdb_is_oauth_enabled (couchdb)) | ||
2379 | 591 | couchdb_add_oauth_signature (couchdb, http_message, method, url); | ||
2380 | 592 | |||
2381 | 593 | |||
2382 | 594 | g_debug ("Sending %s to %s... with headers\n: ", method, url); | ||
2383 | 595 | soup_message_headers_foreach (http_message->request_headers, | ||
2384 | 596 | (SoupMessageHeadersForeachFunc) debug_print_headers, | ||
2385 | 597 | NULL); | ||
2386 | 598 | |||
2387 | 599 | status = soup_session_send_message (couchdb->http_session, http_message); | ||
2388 | 600 | if (SOUP_STATUS_IS_SUCCESSFUL (status)) { | ||
2389 | 601 | if (parser != NULL) | ||
2390 | 602 | parse_json_response (couchdb, parser, http_message, error); | ||
2391 | 603 | return TRUE; | ||
2392 | 604 | } else { | ||
2393 | 605 | g_set_error (error, COUCHDB_ERROR, status, "%s", http_message->reason_phrase); | ||
2394 | 606 | return FALSE; | ||
2395 | 607 | } | ||
2396 | 608 | } | ||
2397 | 426 | 609 | ||
2398 | === added file 'couchdb-glib/couchdb.h' | |||
2399 | --- couchdb-glib/couchdb.h 1970-01-01 00:00:00 +0000 | |||
2400 | +++ couchdb-glib/couchdb.h 2009-10-06 18:10:22 +0000 | |||
2401 | @@ -0,0 +1,84 @@ | |||
2402 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ | ||
2403 | 2 | /* | ||
2404 | 3 | * Copyright (C) 2009 Canonical Services Ltd (www.canonical.com) | ||
2405 | 4 | * 2009 Mikkel Kamstrup Erlandsen | ||
2406 | 5 | * | ||
2407 | 6 | * Authors: Rodrigo Moya <rodrigo.moya@canonical.com> | ||
2408 | 7 | * Mikkel Kamstrup Erlandsen <mikkel.kamstrup@gmail.com> | ||
2409 | 8 | * | ||
2410 | 9 | * This library is free software; you can redistribute it and/or | ||
2411 | 10 | * modify it under the terms of version 2 of the GNU Lesser General Public | ||
2412 | 11 | * License as published by the Free Software Foundation. | ||
2413 | 12 | * | ||
2414 | 13 | * This program is distributed in the hope that it will be useful, | ||
2415 | 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2416 | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
2417 | 16 | * General Public License for more details. | ||
2418 | 17 | * | ||
2419 | 18 | * You should have received a copy of the GNU Lesser General Public | ||
2420 | 19 | * License along with this library; if not, write to the | ||
2421 | 20 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
2422 | 21 | * Boston, MA 02110-1301, USA. | ||
2423 | 22 | */ | ||
2424 | 23 | |||
2425 | 24 | #ifndef __COUCHDB_H__ | ||
2426 | 25 | #define __COUCHDB_H__ | ||
2427 | 26 | |||
2428 | 27 | #include <glib.h> | ||
2429 | 28 | #include <glib-object.h> | ||
2430 | 29 | #include <json-glib/json-glib.h> | ||
2431 | 30 | #include "couchdb-types.h" | ||
2432 | 31 | #include "couchdb-database-info.h" | ||
2433 | 32 | |||
2434 | 33 | G_BEGIN_DECLS | ||
2435 | 34 | |||
2436 | 35 | #define COUCHDB_TYPE (couchdb_get_type ()) | ||
2437 | 36 | #define COUCHDB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COUCHDB_TYPE, CouchDB)) | ||
2438 | 37 | #define COUCHDB_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COUCHDB_TYPE)) | ||
2439 | 38 | #define COUCHDB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COUCHDB_TYPE, CouchDBClass)) | ||
2440 | 39 | #define COUCHDB_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE)) | ||
2441 | 40 | #define COUCHDB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE, CouchDBClass)) | ||
2442 | 41 | |||
2443 | 42 | typedef struct { | ||
2444 | 43 | GObjectClass parent_class; | ||
2445 | 44 | |||
2446 | 45 | void (* database_created) (CouchDB *couchdb, const char *dbname); | ||
2447 | 46 | void (* database_deleted) (CouchDB *couchdb, const char *dbname); | ||
2448 | 47 | |||
2449 | 48 | void (* document_created) (CouchDB *couchdb, const char *dbname, CouchDBDocument *document); | ||
2450 | 49 | void (* document_updated) (CouchDB *couchdb, const char *dbname, CouchDBDocument *document); | ||
2451 | 50 | void (* document_deleted) (CouchDB *couchdb, const char *dbname, const char *docid); | ||
2452 | 51 | } CouchDBClass; | ||
2453 | 52 | |||
2454 | 53 | GType couchdb_get_type (void); | ||
2455 | 54 | CouchDB *couchdb_new (const char *hostname); | ||
2456 | 55 | |||
2457 | 56 | const char *couchdb_get_hostname (CouchDB *couchdb); | ||
2458 | 57 | |||
2459 | 58 | GSList *couchdb_list_databases (CouchDB *couchdb, GError **error); | ||
2460 | 59 | void couchdb_free_database_list (GSList *dblist); | ||
2461 | 60 | |||
2462 | 61 | CouchDBDatabaseInfo *couchdb_get_database_info (CouchDB *couchdb, const char *dbname, GError **error); | ||
2463 | 62 | |||
2464 | 63 | gboolean couchdb_create_database (CouchDB *couchdb, const char *dbname, GError **error); | ||
2465 | 64 | gboolean couchdb_delete_database (CouchDB *couchdb, const char *dbname, GError **error); | ||
2466 | 65 | |||
2467 | 66 | void couchdb_listen_for_changes (CouchDB *couchdb, const char *dbname); | ||
2468 | 67 | |||
2469 | 68 | gboolean couchdb_enable_oauth (CouchDB *couchdb, | ||
2470 | 69 | const char *consumer_key, | ||
2471 | 70 | const char *consumer_secret, | ||
2472 | 71 | const char *token_key, | ||
2473 | 72 | const char *token_secret); | ||
2474 | 73 | void couchdb_disable_oauth (CouchDB *couchdb); | ||
2475 | 74 | |||
2476 | 75 | gboolean couchdb_is_oauth_enabled (CouchDB *couchdb); | ||
2477 | 76 | |||
2478 | 77 | gboolean couchdb_send_message (CouchDB *couchdb, const char *method, const char *url, const char *body, JsonParser *parser, GError **error); | ||
2479 | 78 | |||
2480 | 79 | GSList *couchdb_list_documents (CouchDB *couchdb, const char *dbname, GError **error); | ||
2481 | 80 | void couchdb_free_document_list (GSList *doclist); | ||
2482 | 81 | |||
2483 | 82 | G_END_DECLS | ||
2484 | 83 | |||
2485 | 84 | #endif /* __COUCHDB_H__ */ | ||
2486 | 0 | 85 | ||
2487 | === modified file 'couchdb-glib/dbwatch.c' | |||
2488 | --- couchdb-glib/dbwatch.c 2009-08-31 15:48:46 +0000 | |||
2489 | +++ couchdb-glib/dbwatch.c 2009-10-06 18:10:22 +0000 | |||
2490 | @@ -19,7 +19,8 @@ | |||
2491 | 19 | * Boston, MA 02110-1301, USA. | 19 | * Boston, MA 02110-1301, USA. |
2492 | 20 | */ | 20 | */ |
2493 | 21 | 21 | ||
2495 | 22 | #include "couchdb-glib.h" | 22 | #include <libsoup/soup-method.h> |
2496 | 23 | #include "couchdb-document.h" | ||
2497 | 23 | #include "dbwatch.h" | 24 | #include "dbwatch.h" |
2498 | 24 | #include "utils.h" | 25 | #include "utils.h" |
2499 | 25 | 26 | ||
2500 | @@ -78,11 +79,11 @@ | |||
2501 | 78 | DBWatch *watch = (DBWatch *) user_data; | 79 | DBWatch *watch = (DBWatch *) user_data; |
2502 | 79 | 80 | ||
2503 | 80 | url = g_strdup_printf ("%s/%s/_changes?since=%d", | 81 | url = g_strdup_printf ("%s/%s/_changes?since=%d", |
2505 | 81 | watch->couchdb->hostname, | 82 | couchdb_get_hostname (watch->couchdb), |
2506 | 82 | watch->dbname, | 83 | watch->dbname, |
2507 | 83 | watch->last_update_seq); | 84 | watch->last_update_seq); |
2510 | 84 | parser = send_message_and_parse (watch->couchdb, SOUP_METHOD_GET, url, NULL, &error); | 85 | parser = json_parser_new (); |
2511 | 85 | if (parser != NULL) { | 86 | if (couchdb_send_message (watch->couchdb, SOUP_METHOD_GET, url, NULL, parser, &error)) { |
2512 | 86 | JsonNode *root_node; | 87 | JsonNode *root_node; |
2513 | 87 | 88 | ||
2514 | 88 | root_node = json_parser_get_root (parser); | 89 | root_node = json_parser_get_root (parser); |
2515 | @@ -102,12 +103,11 @@ | |||
2516 | 102 | 103 | ||
2517 | 103 | if (json_object_has_member (root_object, "last_seq")) | 104 | if (json_object_has_member (root_object, "last_seq")) |
2518 | 104 | watch->last_update_seq = json_object_get_int_member (root_object, "last_seq"); | 105 | watch->last_update_seq = json_object_get_int_member (root_object, "last_seq"); |
2522 | 105 | } | 106 | } |
2520 | 106 | |||
2521 | 107 | g_object_unref (G_OBJECT (parser)); | ||
2523 | 108 | } | 107 | } |
2524 | 109 | 108 | ||
2525 | 110 | /* Free memory */ | 109 | /* Free memory */ |
2526 | 110 | g_object_unref (G_OBJECT (parser)); | ||
2527 | 111 | g_free (url); | 111 | g_free (url); |
2528 | 112 | } | 112 | } |
2529 | 113 | 113 | ||
2530 | 114 | 114 | ||
2531 | === modified file 'couchdb-glib/dbwatch.h' | |||
2532 | --- couchdb-glib/dbwatch.h 2009-08-31 15:48:46 +0000 | |||
2533 | +++ couchdb-glib/dbwatch.h 2009-10-06 18:10:22 +0000 | |||
2534 | @@ -22,6 +22,8 @@ | |||
2535 | 22 | #ifndef __DBWATCH_H__ | 22 | #ifndef __DBWATCH_H__ |
2536 | 23 | #define __DBWATCH_H__ | 23 | #define __DBWATCH_H__ |
2537 | 24 | 24 | ||
2538 | 25 | #include <glib.h> | ||
2539 | 26 | #include "couchdb.h" | ||
2540 | 25 | #include "utils.h" | 27 | #include "utils.h" |
2541 | 26 | 28 | ||
2542 | 27 | typedef struct { | 29 | typedef struct { |
2543 | @@ -34,4 +36,4 @@ | |||
2544 | 34 | DBWatch *dbwatch_new (CouchDB *couchdb, const gchar *dbname, gint update_seq); | 36 | DBWatch *dbwatch_new (CouchDB *couchdb, const gchar *dbname, gint update_seq); |
2545 | 35 | void dbwatch_free (DBWatch *watch); | 37 | void dbwatch_free (DBWatch *watch); |
2546 | 36 | 38 | ||
2548 | 37 | #endif | 39 | #endif /* __DBWATCH_H__ */ |
2549 | 38 | 40 | ||
2550 | === modified file 'couchdb-glib/utils.c' | |||
2551 | --- couchdb-glib/utils.c 2009-09-09 14:53:00 +0000 | |||
2552 | +++ couchdb-glib/utils.c 2009-10-06 18:10:22 +0000 | |||
2553 | @@ -24,46 +24,6 @@ | |||
2554 | 24 | #include <libsoup/soup-session-async.h> | 24 | #include <libsoup/soup-session-async.h> |
2555 | 25 | #include "couchdb-glib.h" | 25 | #include "couchdb-glib.h" |
2556 | 26 | #include "utils.h" | 26 | #include "utils.h" |
2557 | 27 | #ifdef HAVE_OAUTH | ||
2558 | 28 | #include <time.h> | ||
2559 | 29 | #include "oauth.h" | ||
2560 | 30 | #endif | ||
2561 | 31 | |||
2562 | 32 | static JsonParser * | ||
2563 | 33 | parse_json_response (SoupMessage *http_message, GError **error) | ||
2564 | 34 | { | ||
2565 | 35 | SoupBuffer *buffer; | ||
2566 | 36 | GString *str = NULL; | ||
2567 | 37 | goffset offset = 0; | ||
2568 | 38 | JsonParser *json_parser = NULL; | ||
2569 | 39 | |||
2570 | 40 | while ((buffer = soup_message_body_get_chunk (http_message->response_body, offset))) { | ||
2571 | 41 | if (!str) | ||
2572 | 42 | str = g_string_new (""); | ||
2573 | 43 | g_string_append_len (str, buffer->data, buffer->length); | ||
2574 | 44 | |||
2575 | 45 | offset += buffer->length; | ||
2576 | 46 | soup_buffer_free (buffer); | ||
2577 | 47 | } | ||
2578 | 48 | |||
2579 | 49 | if (str && str->len > 0) { | ||
2580 | 50 | g_debug ("Response body: %s", str->str); | ||
2581 | 51 | json_parser = json_parser_new (); | ||
2582 | 52 | if (!json_parser_load_from_data (json_parser, | ||
2583 | 53 | (const gchar *) str->str, | ||
2584 | 54 | str->len, | ||
2585 | 55 | error)) { | ||
2586 | 56 | g_object_unref (G_OBJECT (json_parser)); | ||
2587 | 57 | json_parser = NULL; | ||
2588 | 58 | |||
2589 | 59 | g_set_error (error, COUCHDB_ERROR, -1, "Invalid JSON response"); | ||
2590 | 60 | } | ||
2591 | 61 | |||
2592 | 62 | g_string_free (str, TRUE); | ||
2593 | 63 | } | ||
2594 | 64 | |||
2595 | 65 | return json_parser; | ||
2596 | 66 | } | ||
2597 | 67 | 27 | ||
2598 | 68 | GQuark | 28 | GQuark |
2599 | 69 | couchdb_error_quark (void) | 29 | couchdb_error_quark (void) |
2600 | @@ -76,110 +36,6 @@ | |||
2601 | 76 | return error; | 36 | return error; |
2602 | 77 | } | 37 | } |
2603 | 78 | 38 | ||
2604 | 79 | #ifdef HAVE_OAUTH | ||
2605 | 80 | static void | ||
2606 | 81 | add_oauth_signature (CouchDB *couchdb, SoupMessage *http_message, const char *method, const char *url) | ||
2607 | 82 | { | ||
2608 | 83 | char *signed_url; | ||
2609 | 84 | |||
2610 | 85 | signed_url = oauth_sign_url2 (url, NULL, OA_HMAC, method, | ||
2611 | 86 | couchdb->oauth_consumer_key, | ||
2612 | 87 | couchdb->oauth_consumer_secret, | ||
2613 | 88 | couchdb->oauth_token_key, | ||
2614 | 89 | couchdb->oauth_token_secret); | ||
2615 | 90 | if (signed_url != NULL) { | ||
2616 | 91 | char **parsed_url; | ||
2617 | 92 | GString *header = NULL; | ||
2618 | 93 | |||
2619 | 94 | /* Get the OAuth signature from the signed URL */ | ||
2620 | 95 | parsed_url = g_strsplit (signed_url, "?", 2); | ||
2621 | 96 | if (parsed_url != NULL) { | ||
2622 | 97 | gchar **params; | ||
2623 | 98 | int i; | ||
2624 | 99 | |||
2625 | 100 | params = g_strsplit (parsed_url[1], "&", 0); | ||
2626 | 101 | #ifdef DEBUG_OAUTH | ||
2627 | 102 | g_debug ("Parsing %s", parsed_url[1]); | ||
2628 | 103 | #endif | ||
2629 | 104 | for (i = 0; params[i] != NULL; i++) { | ||
2630 | 105 | gchar **url_param; | ||
2631 | 106 | |||
2632 | 107 | #ifdef DEBUG_OAUTH | ||
2633 | 108 | g_debug ("%s\n", params[i]); | ||
2634 | 109 | #endif | ||
2635 | 110 | url_param = g_strsplit (params[i], "=", 2); | ||
2636 | 111 | if (url_param == NULL) | ||
2637 | 112 | continue; | ||
2638 | 113 | |||
2639 | 114 | if (header != NULL) | ||
2640 | 115 | header = g_string_append (header, ", "); | ||
2641 | 116 | else | ||
2642 | 117 | header = g_string_new ("OAuth "); | ||
2643 | 118 | |||
2644 | 119 | header = g_string_append (header, url_param[0]); | ||
2645 | 120 | header = g_string_append (header, "=\""); | ||
2646 | 121 | header = g_string_append (header, url_param[1]); | ||
2647 | 122 | header = g_string_append (header, "\""); | ||
2648 | 123 | |||
2649 | 124 | g_strfreev (url_param); | ||
2650 | 125 | } | ||
2651 | 126 | |||
2652 | 127 | if (params) | ||
2653 | 128 | g_strfreev (params); | ||
2654 | 129 | |||
2655 | 130 | g_strfreev (parsed_url); | ||
2656 | 131 | } | ||
2657 | 132 | |||
2658 | 133 | if (header != NULL) { | ||
2659 | 134 | soup_message_headers_append (http_message->request_headers, "Authorization", header->str); | ||
2660 | 135 | |||
2661 | 136 | g_string_free (header, TRUE); | ||
2662 | 137 | } | ||
2663 | 138 | |||
2664 | 139 | free (signed_url); | ||
2665 | 140 | } | ||
2666 | 141 | } | ||
2667 | 142 | #endif | ||
2668 | 143 | |||
2669 | 144 | static void | ||
2670 | 145 | debug_print_headers (const char *name, const char *value, gpointer user_data) | ||
2671 | 146 | { | ||
2672 | 147 | g_print ("\t%s: %s\n", name, value); | ||
2673 | 148 | } | ||
2674 | 149 | |||
2675 | 150 | JsonParser * | ||
2676 | 151 | send_message_and_parse (CouchDB *couchdb, const char *method, const char *url, const char *body, GError **error) | ||
2677 | 152 | { | ||
2678 | 153 | SoupMessage *http_message; | ||
2679 | 154 | guint status; | ||
2680 | 155 | JsonParser *parser = NULL; | ||
2681 | 156 | |||
2682 | 157 | http_message = soup_message_new (method, url); | ||
2683 | 158 | if (body != NULL) { | ||
2684 | 159 | soup_message_set_request (http_message, "application/json", SOUP_MEMORY_COPY, | ||
2685 | 160 | body, strlen (body)); | ||
2686 | 161 | } | ||
2687 | 162 | |||
2688 | 163 | #ifdef HAVE_OAUTH | ||
2689 | 164 | if (couchdb->oauth_enabled) | ||
2690 | 165 | add_oauth_signature (couchdb, http_message, method, url); | ||
2691 | 166 | #endif | ||
2692 | 167 | |||
2693 | 168 | g_debug ("Sending %s to %s... with headers\n: ", method, url); | ||
2694 | 169 | soup_message_headers_foreach (http_message->request_headers, | ||
2695 | 170 | (SoupMessageHeadersForeachFunc) debug_print_headers, | ||
2696 | 171 | NULL); | ||
2697 | 172 | |||
2698 | 173 | status = soup_session_send_message (couchdb->http_session, http_message); | ||
2699 | 174 | if (SOUP_STATUS_IS_SUCCESSFUL (status)) { | ||
2700 | 175 | parser = parse_json_response (http_message, error); | ||
2701 | 176 | } else { | ||
2702 | 177 | g_set_error (error, COUCHDB_ERROR, status, "%s", http_message->reason_phrase); | ||
2703 | 178 | } | ||
2704 | 179 | |||
2705 | 180 | return parser; | ||
2706 | 181 | } | ||
2707 | 182 | |||
2708 | 183 | char * | 39 | char * |
2709 | 184 | generate_uuid (void) | 40 | generate_uuid (void) |
2710 | 185 | { | 41 | { |
2711 | 186 | 42 | ||
2712 | === modified file 'couchdb-glib/utils.h' | |||
2713 | --- couchdb-glib/utils.h 2009-09-09 14:53:00 +0000 | |||
2714 | +++ couchdb-glib/utils.h 2009-10-06 18:10:22 +0000 | |||
2715 | @@ -22,85 +22,14 @@ | |||
2716 | 22 | #ifndef __UTILS_H__ | 22 | #ifndef __UTILS_H__ |
2717 | 23 | #define __UTILS_H__ | 23 | #define __UTILS_H__ |
2718 | 24 | 24 | ||
2719 | 25 | #include <glib.h> | ||
2720 | 26 | #include <json-glib/json-glib.h> | ||
2721 | 25 | #include "config.h" | 27 | #include "config.h" |
2790 | 26 | #include <libsoup/soup-session-async.h> | 28 | #include "couchdb.h" |
2723 | 27 | #include <json-glib/json-glib.h> | ||
2724 | 28 | |||
2725 | 29 | struct _CouchDB { | ||
2726 | 30 | GObject parent; | ||
2727 | 31 | |||
2728 | 32 | char *hostname; | ||
2729 | 33 | SoupSession *http_session; | ||
2730 | 34 | |||
2731 | 35 | GHashTable *db_watchlist; | ||
2732 | 36 | |||
2733 | 37 | #ifdef HAVE_OAUTH | ||
2734 | 38 | gboolean oauth_enabled; | ||
2735 | 39 | char *oauth_consumer_key; | ||
2736 | 40 | char *oauth_consumer_secret; | ||
2737 | 41 | char *oauth_token_key; | ||
2738 | 42 | char *oauth_token_secret; | ||
2739 | 43 | #endif | ||
2740 | 44 | }; | ||
2741 | 45 | |||
2742 | 46 | struct _CouchDBDocument { | ||
2743 | 47 | GObject parent; | ||
2744 | 48 | |||
2745 | 49 | CouchDB *couchdb; | ||
2746 | 50 | char *dbname; | ||
2747 | 51 | JsonNode *root_node; | ||
2748 | 52 | }; | ||
2749 | 53 | |||
2750 | 54 | struct _CouchDBDatabaseInfo { | ||
2751 | 55 | gint ref_count; | ||
2752 | 56 | |||
2753 | 57 | char *dbname; | ||
2754 | 58 | gint doc_count; | ||
2755 | 59 | gint doc_del_count; | ||
2756 | 60 | gint update_seq; | ||
2757 | 61 | gboolean compact_running; | ||
2758 | 62 | gint disk_size; | ||
2759 | 63 | }; | ||
2760 | 64 | |||
2761 | 65 | CouchDBDatabaseInfo *couchdb_database_info_new (const char *dbname, | ||
2762 | 66 | gint doc_count, | ||
2763 | 67 | gint doc_del_count, | ||
2764 | 68 | gint update_seq, | ||
2765 | 69 | gboolean compact_running, | ||
2766 | 70 | gint disk_size); | ||
2767 | 71 | |||
2768 | 72 | struct _CouchDBDocumentInfo { | ||
2769 | 73 | gint ref_count; | ||
2770 | 74 | |||
2771 | 75 | char *docid; | ||
2772 | 76 | char *revision; | ||
2773 | 77 | }; | ||
2774 | 78 | |||
2775 | 79 | CouchDBDocumentInfo *couchdb_document_info_new (const char *docid, const char *revision); | ||
2776 | 80 | |||
2777 | 81 | struct _CouchDBStructField { | ||
2778 | 82 | gint ref_count; | ||
2779 | 83 | JsonObject *json_object; | ||
2780 | 84 | |||
2781 | 85 | /* Extra data needed for some specific StructField's */ | ||
2782 | 86 | char *uuid; /* the UUID of this item */ | ||
2783 | 87 | }; | ||
2784 | 88 | |||
2785 | 89 | CouchDBStructField *couchdb_struct_field_new_from_json_object (JsonObject *json_object); | ||
2786 | 90 | |||
2787 | 91 | /* | ||
2788 | 92 | * Utility functions | ||
2789 | 93 | */ | ||
2791 | 94 | 29 | ||
2792 | 95 | #define COUCHDB_ERROR couchdb_error_quark() | 30 | #define COUCHDB_ERROR couchdb_error_quark() |
2793 | 96 | GQuark couchdb_error_quark (void); | 31 | GQuark couchdb_error_quark (void); |
2794 | 97 | 32 | ||
2802 | 98 | JsonParser *send_message_and_parse (CouchDB *couchdb, | 33 | char* generate_uuid (void); |
2796 | 99 | const char *method, | ||
2797 | 100 | const char *url, | ||
2798 | 101 | const char *body, | ||
2799 | 102 | GError **error); | ||
2800 | 103 | |||
2801 | 104 | char *generate_uuid (void); | ||
2803 | 105 | 34 | ||
2804 | 106 | #endif | 35 | #endif |
2805 | 107 | 36 | ||
2806 | === modified file 'debian/control' | |||
2807 | --- debian/control 2009-08-11 15:04:39 +0000 | |||
2808 | +++ debian/control 2009-10-06 18:10:22 +0000 | |||
2809 | @@ -27,3 +27,15 @@ | |||
2810 | 27 | Ubuntu One. | 27 | Ubuntu One. |
2811 | 28 | . | 28 | . |
2812 | 29 | This package contains the development files. | 29 | This package contains the development files. |
2813 | 30 | |||
2814 | 31 | Package: libcouchdb-glib-doc | ||
2815 | 32 | Section: doc | ||
2816 | 33 | Architecture: any | ||
2817 | 34 | Depends: ${misc:Depends} | ||
2818 | 35 | Description: API documentation for GLib-based API for CouchDB | ||
2819 | 36 | CouchDB-GLib is a GLib-based API to access CouchDB servers | ||
2820 | 37 | (http://couchdb.apache.org), a replication/synchronization | ||
2821 | 38 | database of JSON documents, used in online services like | ||
2822 | 39 | Ubuntu One. | ||
2823 | 40 | . | ||
2824 | 41 | This package contains the API documentation for the couchdb-glib library | ||
2825 | 30 | 42 | ||
2826 | === added file 'debian/libcouchdb-glib-doc.install' | |||
2827 | --- debian/libcouchdb-glib-doc.install 1970-01-01 00:00:00 +0000 | |||
2828 | +++ debian/libcouchdb-glib-doc.install 2009-10-06 18:10:22 +0000 | |||
2829 | @@ -0,0 +1,1 @@ | |||
2830 | 1 | debian/tmp/usr/share/gtk-doc | ||
2831 | 0 | 2 | ||
2832 | === modified file 'debian/rules' | |||
2833 | --- debian/rules 2009-07-20 12:11:54 +0000 | |||
2834 | +++ debian/rules 2009-10-06 18:10:22 +0000 | |||
2835 | @@ -2,3 +2,5 @@ | |||
2836 | 2 | 2 | ||
2837 | 3 | include /usr/share/cdbs/1/rules/debhelper.mk | 3 | include /usr/share/cdbs/1/rules/debhelper.mk |
2838 | 4 | include /usr/share/cdbs/1/class/gnome.mk | 4 | include /usr/share/cdbs/1/class/gnome.mk |
2839 | 5 | include /usr/share/cdbs/1/rules/utils.mk | ||
2840 | 6 | |||
2841 | 5 | 7 | ||
2842 | === added directory 'doc' | |||
2843 | === added file 'doc/Makefile.am' | |||
2844 | --- doc/Makefile.am 1970-01-01 00:00:00 +0000 | |||
2845 | +++ doc/Makefile.am 2009-10-06 18:10:22 +0000 | |||
2846 | @@ -0,0 +1,4 @@ | |||
2847 | 1 | # Include to make 'make check' work with GTest | ||
2848 | 2 | #include $(top_srcdir)/Makefile.decl | ||
2849 | 3 | |||
2850 | 4 | SUBDIRS = reference | ||
2851 | 0 | 5 | ||
2852 | === added directory 'doc/reference' | |||
2853 | === added file 'doc/reference/Makefile.am' | |||
2854 | --- doc/reference/Makefile.am 1970-01-01 00:00:00 +0000 | |||
2855 | +++ doc/reference/Makefile.am 2009-10-06 18:10:22 +0000 | |||
2856 | @@ -0,0 +1,67 @@ | |||
2857 | 1 | ## Process this file with automake to produce Makefile.in | ||
2858 | 2 | |||
2859 | 3 | # Dummy targets we need to make distcheck and check pass | ||
2860 | 4 | test test-report perf-report full-report: | ||
2861 | 5 | ## Ignore | ||
2862 | 6 | |||
2863 | 7 | # automake requirements | ||
2864 | 8 | AUTOMAKE_OPTIONS = 1.7 | ||
2865 | 9 | |||
2866 | 10 | # The name of the module | ||
2867 | 11 | DOC_MODULE=couchdb-glib | ||
2868 | 12 | |||
2869 | 13 | # The top-level SGML file. You can change this if you want to. | ||
2870 | 14 | DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml | ||
2871 | 15 | |||
2872 | 16 | # The directory containing the source code. Relative to $(srcdir). | ||
2873 | 17 | DOC_SOURCE_DIR=../.. | ||
2874 | 18 | |||
2875 | 19 | # Extra options to pass to gtkdoc-scangobj. Not normally needed. | ||
2876 | 20 | SCANGOBJ_OPTIONS= | ||
2877 | 21 | |||
2878 | 22 | # Extra options to supply to gtkdoc-scan. | ||
2879 | 23 | # Fx --rebuild-types --rebuild-sections | ||
2880 | 24 | SCAN_OPTIONS= | ||
2881 | 25 | |||
2882 | 26 | # Extra options to supply to gtkdoc-mkdb. | ||
2883 | 27 | MKDB_OPTIONS=--sgml-mode --output-format=xml --ignore-files=trio | ||
2884 | 28 | |||
2885 | 29 | # Extra options to supply to gtkdoc-fixref. Not normally needed. | ||
2886 | 30 | FIXXREF_OPTIONS= | ||
2887 | 31 | |||
2888 | 32 | # Used for dependencies. The docs will be rebuilt if any of these change. | ||
2889 | 33 | HFILE_GLOB=$(top_srcdir)/couchdb-glib/couchdb*.h | ||
2890 | 34 | CFILE_GLOB=$(top_srcdir)/couchdb-glib/couchdb*.c | ||
2891 | 35 | |||
2892 | 36 | # Header files to ignore when scanning. | ||
2893 | 37 | IGNORE_HFILES= \ | ||
2894 | 38 | xmalloc.h \ | ||
2895 | 39 | dbwatch.h \ | ||
2896 | 40 | oauth.h \ | ||
2897 | 41 | utils.h \ | ||
2898 | 42 | xmalloc.h \ | ||
2899 | 43 | config.h | ||
2900 | 44 | |||
2901 | 45 | # Images to copy into HTML directory. | ||
2902 | 46 | HTML_IMAGES= | ||
2903 | 47 | |||
2904 | 48 | # Extra SGML files that are included by $(DOC_MAIN_SGML_FILE). | ||
2905 | 49 | content_files = | ||
2906 | 50 | |||
2907 | 51 | # CFLAGS and LDFLAGS for compiling gtkdoc-scangobj with your library. | ||
2908 | 52 | INCLUDES=-I$(top_srcdir)/couchdb-glib \ | ||
2909 | 53 | $(COUCHDB_GLIB_CFLAGS) | ||
2910 | 54 | |||
2911 | 55 | GTKDOC_LIBS=$(COUCHDB_GLIB_LIBS) \ | ||
2912 | 56 | $(top_builddir)/couchdb-glib/libcouchdb-glib-1.0.la | ||
2913 | 57 | |||
2914 | 58 | # This includes the standard gtk-doc make rules, copied by gtkdocize. | ||
2915 | 59 | include $(top_srcdir)/gtk-doc.make | ||
2916 | 60 | |||
2917 | 61 | # Other files to distribute | ||
2918 | 62 | # e.g. EXTRA_DIST += version.xml.in | ||
2919 | 63 | EXTRA_DIST += \ | ||
2920 | 64 | couchdb-glib.types \ | ||
2921 | 65 | couchdb-glib-docs.sgml | ||
2922 | 66 | # couchdb-glib-sections.txt | ||
2923 | 67 | |||
2924 | 0 | 68 | ||
2925 | === added file 'doc/reference/couchdb-glib-docs.sgml' | |||
2926 | --- doc/reference/couchdb-glib-docs.sgml 1970-01-01 00:00:00 +0000 | |||
2927 | +++ doc/reference/couchdb-glib-docs.sgml 2009-10-06 18:10:22 +0000 | |||
2928 | @@ -0,0 +1,19 @@ | |||
2929 | 1 | <?xml version="1.0"?> | ||
2930 | 2 | <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" | ||
2931 | 3 | "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> | ||
2932 | 4 | <book id="index" xmlns:xi="http://www.w3.org/2003/XInclude"> | ||
2933 | 5 | <bookinfo> | ||
2934 | 6 | <title>Reference Manual for CouchDB GLib Bindings</title> | ||
2935 | 7 | </bookinfo> | ||
2936 | 8 | |||
2937 | 9 | <chapter> | ||
2938 | 10 | <title>Core API</title> | ||
2939 | 11 | <xi:include href="xml/couchdb.xml"/> | ||
2940 | 12 | <xi:include href="xml/couchdb-document.xml"/> | ||
2941 | 13 | <xi:include href="xml/couchdb-document-contact.xml"/> | ||
2942 | 14 | <xi:include href="xml/couchdb-document-info.xml"/> | ||
2943 | 15 | <xi:include href="xml/couchdb-database-info.xml"/> | ||
2944 | 16 | <xi:include href="xml/couchdb-struct-field.xml"/> | ||
2945 | 17 | </chapter> | ||
2946 | 18 | |||
2947 | 19 | </book> | ||
2948 | 0 | 20 | ||
2949 | === added file 'doc/reference/couchdb-glib.types' | |||
2950 | --- doc/reference/couchdb-glib.types 1970-01-01 00:00:00 +0000 | |||
2951 | +++ doc/reference/couchdb-glib.types 2009-10-06 18:10:22 +0000 | |||
2952 | @@ -0,0 +1,6 @@ | |||
2953 | 1 | couchdb_get_type | ||
2954 | 2 | couchdb_database_info_get_type | ||
2955 | 3 | couchdb_document_get_type | ||
2956 | 4 | couchdb_document_info_get_type | ||
2957 | 5 | couchdb_struct_field_get_type | ||
2958 | 6 | |||
2959 | 0 | 7 | ||
2960 | === modified file 'tests/test-couchdb-glib.c' | |||
2961 | --- tests/test-couchdb-glib.c 2009-08-31 15:48:46 +0000 | |||
2962 | +++ tests/test-couchdb-glib.c 2009-10-06 18:10:22 +0000 | |||
2963 | @@ -31,7 +31,12 @@ | |||
2964 | 31 | GSList *dblist; | 31 | GSList *dblist; |
2965 | 32 | 32 | ||
2966 | 33 | dblist = couchdb_list_databases (couchdb, &error); | 33 | dblist = couchdb_list_databases (couchdb, &error); |
2968 | 34 | g_assert (error == NULL); | 34 | if (error != NULL) { |
2969 | 35 | /* A critical will abort the test case */ | ||
2970 | 36 | g_critical ("Error listing databases: %s", error->message); | ||
2971 | 37 | g_error_free (error); | ||
2972 | 38 | error = NULL; | ||
2973 | 39 | } | ||
2974 | 35 | 40 | ||
2975 | 36 | while (dblist != NULL) { | 41 | while (dblist != NULL) { |
2976 | 37 | CouchDBDatabaseInfo *dbinfo; | 42 | CouchDBDatabaseInfo *dbinfo; |
2977 | @@ -112,7 +117,10 @@ | |||
2978 | 112 | 117 | ||
2979 | 113 | /* Create database */ | 118 | /* Create database */ |
2980 | 114 | couchdb_create_database (couchdb, dbname, &error); | 119 | couchdb_create_database (couchdb, dbname, &error); |
2982 | 115 | g_assert (error == NULL); | 120 | if (error) { |
2983 | 121 | g_critical ("Error creating database '%s': %s", dbname, error->message); | ||
2984 | 122 | g_error_free (error); | ||
2985 | 123 | } | ||
2986 | 116 | 124 | ||
2987 | 117 | couchdb_listen_for_changes (couchdb, dbname); | 125 | couchdb_listen_for_changes (couchdb, dbname); |
2988 | 118 | 126 | ||
2989 | @@ -184,7 +192,9 @@ | |||
2990 | 184 | g_test_init (&argc, &argv, NULL); | 192 | g_test_init (&argc, &argv, NULL); |
2991 | 185 | 193 | ||
2992 | 186 | /* Initialize data needed for all tests */ | 194 | /* Initialize data needed for all tests */ |
2994 | 187 | couchdb = couchdb_new (NULL); | 195 | couchdb = argc > 1 ? couchdb_new (argv[1]) : couchdb_new (NULL); |
2995 | 196 | g_printf ("Connecting to CouchDB at %s\n", couchdb_get_hostname (couchdb)); | ||
2996 | 197 | |||
2997 | 188 | if (!couchdb) { | 198 | if (!couchdb) { |
2998 | 189 | g_print ("Could not create CouchDB object\n"); | 199 | g_print ("Could not create CouchDB object\n"); |
2999 | 190 | return -1; | 200 | return -1; |
3000 | 191 | 201 | ||
3001 | === modified file 'tests/test-list-databases.c' | |||
3002 | --- tests/test-list-databases.c 2009-07-27 21:52:04 +0000 | |||
3003 | +++ tests/test-list-databases.c 2009-10-06 18:10:22 +0000 | |||
3004 | @@ -32,14 +32,21 @@ | |||
3005 | 32 | g_type_init (); | 32 | g_type_init (); |
3006 | 33 | g_thread_init (NULL); | 33 | g_thread_init (NULL); |
3007 | 34 | 34 | ||
3010 | 35 | /* initialize CouchDB */ | 35 | /* Initialize CouchDB */ |
3011 | 36 | couchdb = couchdb_new (NULL); | 36 | couchdb = argc > 1 ? couchdb_new (argv[1]) : couchdb_new (NULL); |
3012 | 37 | g_printf ("Connecting to CouchDB at %s\n", couchdb_get_hostname (couchdb)); | ||
3013 | 38 | |||
3014 | 37 | if (!couchdb) { | 39 | if (!couchdb) { |
3015 | 38 | g_print ("Could not create CouchDB object\n"); | 40 | g_print ("Could not create CouchDB object\n"); |
3016 | 39 | return -1; | 41 | return -1; |
3017 | 40 | } | 42 | } |
3018 | 41 | 43 | ||
3019 | 42 | dblist = couchdb_list_databases (couchdb, &error); | 44 | dblist = couchdb_list_databases (couchdb, &error); |
3020 | 45 | if (error != NULL) { | ||
3021 | 46 | g_critical ("Error listing databases: %s", error->message); | ||
3022 | 47 | g_error_free (error); | ||
3023 | 48 | } | ||
3024 | 49 | |||
3025 | 43 | for (sl = dblist; sl != NULL; sl = sl->next) { | 50 | for (sl = dblist; sl != NULL; sl = sl->next) { |
3026 | 44 | CouchDBDatabaseInfo *dbinfo; | 51 | CouchDBDatabaseInfo *dbinfo; |
3027 | 45 | GSList *doclist; | 52 | GSList *doclist; |
So here's my source structure overhaul as discussed on: http:// groups. google. com/group/ desktop- couchdb/ browse_ thread/ thread/ 7bb2fe505537014 0
After manually extracting my OAUTH credentials from ~/.config/ desktop- couch/desktop- couchdb. ini I was able to run the unit tests successfully.
The big picture of what I've done:
* Enable gtk-doc for all public classes
* Shuffle the code for all public GObjects to be in <namespace> -<type> .{h,c} files
* Make all GObject instance struct declarations private (ie. declared in the .c file)
To facilitate this in needed some changes in the source code - on top of the massive refactoring.
In couchdb.{h,c}: send_message( ) replacing send_message_ and_parse( ) from util.*
* Don't make CouchDB struct depend on whether we are configured with OAUTH
* Move OAUTH related functionality from util.* here
* New method couchdb_
In couchdb-document.c:
* Change refs to internal API of CouchDB object's ->hostname to method calls
* Change refs to internal API of CouchDBStructField ->json_object to use method call
In couchdb- struct- field.* :
* Add method _get_json_object()
Future plans: I have a list of items I'd like to work on in the future - they might be better of discussed on the mailing list, but I put them here FYI: couchdb. ini, to make OAUTH "just work", like in the desktopcouch Python module
- Silent build rules
- Single header includes
- ? Get rid of CouchDBStructField ?
- Make 'make check' run unit tests
- Rename CouchDB class to CouchDBConnection
- Add method couchdb_send_async using a SoupSessionAsync underneath
- A .ini parser to extract OAUTH credentials from desktop-