1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/* sync-gridfs.h - libmong-client GridFS API
* Copyright 2011, 2012 Gergely Nagy <algernon@balabit.hu>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @file src/sync-gridfs.h
* MongoDB GridFS API.
*
* @addtogroup mongo_sync
* @{
*/
#ifndef LIBMONGO_SYNC_GRIDFS_H
#define LIBMONGO_SYNC_GRIDFS_H 1
#include <mongo-sync.h>
#include <mongo-sync-cursor.h>
#include <glib.h>
G_BEGIN_DECLS
/** @defgroup mongo_sync_gridfs_api Mongo GridFS API
*
* The GridFS API - and related modules, like @ref
* mongo_sync_gridfs_chunk_api and @ref mongo_sync_gridfs_stream_api -
* provide a conveneint way to work with GridFS, and files stored on
* it.
*
* This module implements the GridFS support functions, which allow
* one to connect to or create new GridFS instances, list or remove
* files, or retrieve metadata about files opened by one of the
* sub-modules.
*
* @addtogroup mongo_sync_gridfs_api
* @{
*/
/** Opaque GridFS object. */
typedef struct _mongo_sync_gridfs mongo_sync_gridfs;
/** Create a new GridFS object.
*
* @param conn is the MongoDB connection to base the filesystem object
* on.
* @param ns_prefix is the prefix the GridFS collections should be
* under.
*
* @returns A newly allocated GridFS object, or NULL on error.
*/
mongo_sync_gridfs *mongo_sync_gridfs_new (mongo_sync_connection *conn,
const gchar *ns_prefix);
/** Close and free a GridFS object.
*
* @param gfs is the GridFS object to free up.
* @param disconnect signals whether to free the underlying connection
* aswell.
*/
void mongo_sync_gridfs_free (mongo_sync_gridfs *gfs, gboolean disconnect);
/** Get the default chunk size of a GridFS object.
*
* @param gfs is the GridFS object to get the default chunk size of.
*
* @returns The chunk size in bytes, or -1 on error.
*/
gint32 mongo_sync_gridfs_get_chunk_size (mongo_sync_gridfs *gfs);
/** Set the default chunk size of a GridFS object.
*
* @param gfs is the GridFS object to set the default chunk size of.
* @param chunk_size is the desired default chunk size.
*
* @returns TRUE on success, FALSE otherwise.
*/
gboolean mongo_sync_gridfs_set_chunk_size (mongo_sync_gridfs *gfs,
gint32 chunk_size);
/** List GridFS files matching a query.
*
* Finds all files on a GridFS, based on a custom query.
*
* @param gfs is the GridFS to list files from.
* @param query is the custom query based on which files shall be
* sought. Passing a NULL query will find all files, without
* restriction.
*
* @returns A newly allocated cursor object, or NULL on error. It is
* the responsibility of the caller to free the returned cursor once
* it is no longer needed.
*/
mongo_sync_cursor *mongo_sync_gridfs_list (mongo_sync_gridfs *gfs,
const bson *query);
/** Delete files matching a query from GridFS.
*
* Finds all files on a GridFS, based on a custom query, and removes
* them.
*
* @param gfs is the GridFS to delete files from.
* @param query is the custom query based on which files shall be
* sought. Passing a NULL query will find all files, without
* restriction.
*
* @returns TRUE if all files were deleted successfully, FALSE
* otherwise.
*/
gboolean mongo_sync_gridfs_remove (mongo_sync_gridfs *gfs,
const bson *query);
/* Metadata */
/** Get the file ID of a GridFS file.
*
* @param gfile is the GridFS file to work with.
*
* @returns The ObjectID of the file, or NULL on error. The returned
* pointer points to an internal area, and should not be modified or
* freed, and is only valid as long as the file object is valid.
*/
const guint8 *mongo_sync_gridfs_file_get_id (gpointer gfile);
/** Get the length of a GridFS file.
*
* @param gfile is the GridFS file to work with.
*
* @returns The length of the file, or -1 on error.
*/
gint64 mongo_sync_gridfs_file_get_length (gpointer gfile);
/** Get the chunk size of a GridFS file.
*
* @param gfile is the GridFS file to work with.
*
* @returns The maximum size of the chunks of the file, or -1 on error.
*/
gint32 mongo_sync_gridfs_file_get_chunk_size (gpointer gfile);
/** Get the MD5 digest of a GridFS file.
*
* @param gfile is the GridFS file to work with.
*
* @returns The MD5 digest of the file, or NULL on error. The returned
* pointer points to an internal area, and should not be modified or
* freed, and is only valid as long as the file object is valid.
*/
const gchar *mongo_sync_gridfs_file_get_md5 (gpointer gfile);
/** Get the upload date of a GridFS file.
*
* @param gfile is the GridFS file to work with.
*
* @returns The upload date of the file, or -1 on error.
*/
gint64 mongo_sync_gridfs_file_get_date (gpointer gfile);
/** Get the full metadata of a GridFS file
*
* @param gfile is the GridFS file to work with.
*
* @returns A BSON object containing the full metadata, or NULL on
* error. The returned pointer points to an internal area, and should
* not be modified or freed, and is only valid as long as the file
* object is valid.
*/
const bson *mongo_sync_gridfs_file_get_metadata (gpointer gfile);
/** Get the number of chunks in a GridFS file.
*
* @param gfile is the GridFS file to work with.
*
* @returns The number of chunks in the GridFS file, or -1 on error.
*/
gint64 mongo_sync_gridfs_file_get_chunks (gpointer gfile);
/** @} */
G_END_DECLS
/** @} */
#endif
|