libmongo-client 0.1.4
|
00001 /* mongo-wire.h - libmongo-client's MongoDB wire protocoll implementation. 00002 * Copyright 2011 Gergely Nagy <algernon@balabit.hu> 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00021 #ifndef LIBMONGO_CLIENT_MONGO_WIRE_H 00022 #define LIBMONGO_CLIENT_MONGO_WIRE_H 1 00023 00024 #include <glib.h> 00025 00026 #include <bson.h> 00027 00028 G_BEGIN_DECLS 00029 00053 typedef struct 00054 { 00055 gint32 length; 00057 gint32 id; 00059 gint32 resp_to; 00061 gint32 opcode; 00063 } mongo_packet_header; 00064 00070 typedef struct _mongo_packet mongo_packet; 00071 00079 mongo_packet *mongo_wire_packet_new (void); 00080 00092 gboolean mongo_wire_packet_get_header (const mongo_packet *p, 00093 mongo_packet_header *header); 00094 00106 gboolean mongo_wire_packet_set_header (mongo_packet *p, 00107 const mongo_packet_header *header); 00108 00121 gint32 mongo_wire_packet_get_data (const mongo_packet *p, const guint8 **data); 00122 00137 gboolean mongo_wire_packet_set_data (mongo_packet *p, const guint8 *data, 00138 gint32 size); 00139 00146 void mongo_wire_packet_free (mongo_packet *p); 00147 00157 enum 00158 { 00160 MONGO_REPLY_FLAG_NO_CURSOR = 0x1, 00162 MONGO_REPLY_FLAG_QUERY_FAIL = 0x2, 00168 MONGO_REPLY_FLAG_AWAITCAPABLE = 0x8, 00169 }; 00170 00173 #pragma pack(1) 00174 typedef struct 00175 { 00176 gint32 flags; 00177 gint64 cursor_id; 00179 gint32 start; 00181 gint32 returned; 00182 } mongo_reply_packet_header; 00183 #pragma pack() 00184 00196 gboolean mongo_wire_reply_packet_get_header (const mongo_packet *p, 00197 mongo_reply_packet_header *hdr); 00198 00212 gboolean mongo_wire_reply_packet_get_data (const mongo_packet *p, 00213 const guint8 **data); 00214 00227 gboolean mongo_wire_reply_packet_get_nth_document (const mongo_packet *p, 00228 gint32 n, 00229 bson **doc); 00230 00246 enum 00247 { 00249 MONGO_WIRE_FLAG_UPDATE_UPSERT = 0x1, 00252 MONGO_WIRE_FLAG_UPDATE_MULTI = 0x2, 00253 }; 00254 00270 mongo_packet *mongo_wire_cmd_update (gint32 id, const gchar *ns, 00271 gint32 flags, const bson *selector, 00272 const bson *update); 00273 00286 mongo_packet *mongo_wire_cmd_insert (gint32 id, const gchar *ns, ...) 00287 G_GNUC_NULL_TERMINATED; 00288 00301 mongo_packet *mongo_wire_cmd_insert_n (gint32 id, const gchar *ns, gint32 n, 00302 const bson **docs); 00303 00307 enum 00308 { 00310 MONGO_WIRE_FLAG_QUERY_TAILABLE_CURSOR = 1 << 1, 00312 MONGO_WIRE_FLAG_QUERY_SLAVE_OK = 1 << 2, 00314 MONGO_WIRE_FLAG_QUERY_NO_CURSOR_TIMEOUT = 1 << 4, 00318 MONGO_WIRE_FLAG_QUERY_AWAIT_DATA = 1 << 5, 00323 MONGO_WIRE_FLAG_QUERY_EXHAUST = 1 << 6, 00328 MONGO_WIRE_FLAG_QUERY_PARTIAL_RESULTS = 1 << 7 00329 }; 00330 00351 mongo_packet *mongo_wire_cmd_query (gint32 id, const gchar *ns, gint32 flags, 00352 gint32 skip, gint32 ret, const bson *query, 00353 const bson *sel); 00354 00367 mongo_packet *mongo_wire_cmd_get_more (gint32 id, const gchar *ns, 00368 gint32 ret, gint64 cursor_id); 00369 00372 enum 00373 { 00375 MONGO_WIRE_FLAG_DELETE_SINGLE = 0x1 00376 }; 00377 00391 mongo_packet *mongo_wire_cmd_delete (gint32 id, const gchar *ns, 00392 gint32 flags, const bson *sel); 00393 00406 mongo_packet *mongo_wire_cmd_kill_cursors (gint32 id, gint32 n, ...); 00407 00423 mongo_packet *mongo_wire_cmd_custom (gint32 id, const gchar *db, 00424 gint32 flags, 00425 const bson *command); 00426 00431 G_END_DECLS 00432 00433 #endif