Compare commits
1 Commits
nightly-x8
...
nightly-ar
| Author | SHA1 | Date | |
|---|---|---|---|
| 165b829fb7 |
BIN
bin/Hypo71PC
BIN
bin/Hypo71PC
Binary file not shown.
BIN
bin/dlsv2inv
BIN
bin/dlsv2inv
Binary file not shown.
28
bin/extr_file
Executable file
28
bin/extr_file
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env seiscomp-python
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
import sys
|
||||||
|
from seiscomp import mseedlite as mseed
|
||||||
|
|
||||||
|
open_files = {}
|
||||||
|
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print("Usage: extr_file FILE")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
for rec in mseed.Input(open(sys.argv[1], "rb")):
|
||||||
|
oname = "%s.%s.%s.%s" % (rec.sta, rec.net, rec.loc, rec.cha)
|
||||||
|
|
||||||
|
if oname not in open_files:
|
||||||
|
postfix = ".D.%04d.%03d.%02d%02d" % (rec.begin_time.year,
|
||||||
|
rec.begin_time.timetuple()[7], rec.begin_time.hour,
|
||||||
|
rec.begin_time.minute)
|
||||||
|
|
||||||
|
open_files[oname] = open(oname + postfix, "ab")
|
||||||
|
|
||||||
|
ofile = open_files[oname]
|
||||||
|
ofile.write(rec.header + rec.data)
|
||||||
|
|
||||||
|
for oname in open_files:
|
||||||
|
open_files[oname].close()
|
||||||
|
|
||||||
BIN
bin/fdsnxml2inv
BIN
bin/fdsnxml2inv
Binary file not shown.
105
bin/inv2dlsv
Executable file
105
bin/inv2dlsv
Executable file
@ -0,0 +1,105 @@
|
|||||||
|
#!/usr/bin/env seiscomp-python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
############################################################################
|
||||||
|
# Copyright (C) GFZ Potsdam #
|
||||||
|
# All rights reserved. #
|
||||||
|
# #
|
||||||
|
# GNU Affero General Public License Usage #
|
||||||
|
# This file may be used under the terms of the GNU Affero #
|
||||||
|
# Public License version 3.0 as published by the Free Software Foundation #
|
||||||
|
# and appearing in the file LICENSE included in the packaging of this #
|
||||||
|
# file. Please review the following information to ensure the GNU Affero #
|
||||||
|
# Public License version 3.0 requirements will be met: #
|
||||||
|
# https://www.gnu.org/licenses/agpl-3.0.html. #
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import io
|
||||||
|
from seiscomp.legacy.fseed import *
|
||||||
|
from seiscomp.legacy.db.seiscomp3 import sc3wrap
|
||||||
|
from seiscomp.legacy.db.seiscomp3.inventory import Inventory
|
||||||
|
import seiscomp.datamodel
|
||||||
|
import seiscomp.io
|
||||||
|
|
||||||
|
ORGANIZATION = "EIDA"
|
||||||
|
|
||||||
|
|
||||||
|
def iterinv(obj):
|
||||||
|
return (j for i in obj.values() for j in i.values())
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if len(sys.argv) < 1 or len(sys.argv) > 3:
|
||||||
|
print("Usage inv2dlsv [in_xml [out_dataless]]", file=sys.stderr)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
if len(sys.argv) > 1:
|
||||||
|
inFile = sys.argv[1]
|
||||||
|
else:
|
||||||
|
inFile = "-"
|
||||||
|
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
out = sys.argv[2]
|
||||||
|
else:
|
||||||
|
out = ""
|
||||||
|
|
||||||
|
sc3wrap.dbQuery = None
|
||||||
|
|
||||||
|
ar = seiscomp.io.XMLArchive()
|
||||||
|
if not ar.open(inFile):
|
||||||
|
raise IOError(inFile + ": unable to open")
|
||||||
|
|
||||||
|
obj = ar.readObject()
|
||||||
|
if obj is None:
|
||||||
|
raise TypeError(inFile + ": invalid format")
|
||||||
|
|
||||||
|
sc3inv = seiscomp.datamodel.Inventory.Cast(obj)
|
||||||
|
if sc3inv is None:
|
||||||
|
raise TypeError(inFile + ": invalid format")
|
||||||
|
|
||||||
|
inv = Inventory(sc3inv)
|
||||||
|
inv.load_stations("*", "*", "*", "*")
|
||||||
|
inv.load_instruments()
|
||||||
|
|
||||||
|
vol = SEEDVolume(inv, ORGANIZATION, "", resp_dict=False)
|
||||||
|
|
||||||
|
for net in iterinv(inv.network):
|
||||||
|
for sta in iterinv(net.station):
|
||||||
|
for loc in iterinv(sta.sensorLocation):
|
||||||
|
for strm in iterinv(loc.stream):
|
||||||
|
try:
|
||||||
|
vol.add_chan(
|
||||||
|
net.code,
|
||||||
|
sta.code,
|
||||||
|
loc.code,
|
||||||
|
strm.code,
|
||||||
|
strm.start,
|
||||||
|
strm.end,
|
||||||
|
)
|
||||||
|
|
||||||
|
except SEEDError as exc:
|
||||||
|
print(
|
||||||
|
f"Error ({net.code},{sta.code},{loc.code},{strm.code}): {str(exc)}",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
|
||||||
|
if not out or out == "-":
|
||||||
|
output = io.BytesIO()
|
||||||
|
vol.output(output)
|
||||||
|
stdout = sys.stdout.buffer if hasattr(sys.stdout, "buffer") else sys.stdout
|
||||||
|
stdout.write(output.getvalue())
|
||||||
|
stdout.flush()
|
||||||
|
output.close()
|
||||||
|
else:
|
||||||
|
with open(sys.argv[2], "wb") as fd:
|
||||||
|
vol.output(fd)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
sys.exit(main())
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {str(e)}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
BIN
bin/invextr
BIN
bin/invextr
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
bin/sc32inv
Symbolic link
1
bin/sc32inv
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
scml2inv
|
||||||
BIN
bin/scanloc
BIN
bin/scanloc
Binary file not shown.
BIN
bin/scardac
BIN
bin/scardac
Binary file not shown.
BIN
bin/scautoloc
BIN
bin/scautoloc
Binary file not shown.
BIN
bin/scautopick
BIN
bin/scautopick
Binary file not shown.
BIN
bin/scchkcfg
BIN
bin/scchkcfg
Binary file not shown.
BIN
bin/scconfig
BIN
bin/scconfig
Binary file not shown.
BIN
bin/scdispatch
BIN
bin/scdispatch
Binary file not shown.
84
bin/scdumpobject
Executable file
84
bin/scdumpobject
Executable file
@ -0,0 +1,84 @@
|
|||||||
|
#!/usr/bin/env seiscomp-python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
############################################################################
|
||||||
|
# Copyright (C) GFZ Potsdam #
|
||||||
|
# All rights reserved. #
|
||||||
|
# #
|
||||||
|
# GNU Affero General Public License Usage #
|
||||||
|
# This file may be used under the terms of the GNU Affero #
|
||||||
|
# Public License version 3.0 as published by the Free Software Foundation #
|
||||||
|
# and appearing in the file LICENSE included in the packaging of this #
|
||||||
|
# file. Please review the following information to ensure the GNU Affero #
|
||||||
|
# Public License version 3.0 requirements will be met: #
|
||||||
|
# https://www.gnu.org/licenses/agpl-3.0.html. #
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import seiscomp.client, seiscomp.datamodel, seiscomp.io
|
||||||
|
|
||||||
|
|
||||||
|
class ObjectDumper(seiscomp.client.Application):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
seiscomp.client.Application.__init__(self, len(sys.argv), sys.argv)
|
||||||
|
self.setMessagingEnabled(True)
|
||||||
|
self.setDatabaseEnabled(True, False)
|
||||||
|
self.setMessagingUsername("")
|
||||||
|
|
||||||
|
def createCommandLineDescription(self):
|
||||||
|
seiscomp.client.Application.createCommandLineDescription(self)
|
||||||
|
self.commandline().addGroup("Dump")
|
||||||
|
self.commandline().addStringOption("Dump", "public-id,P", "publicID")
|
||||||
|
|
||||||
|
def loadEventParametersObject(self, publicID):
|
||||||
|
for tp in (
|
||||||
|
seiscomp.datamodel.Pick,
|
||||||
|
seiscomp.datamodel.Amplitude,
|
||||||
|
seiscomp.datamodel.Origin,
|
||||||
|
seiscomp.datamodel.Event,
|
||||||
|
seiscomp.datamodel.FocalMechanism,
|
||||||
|
seiscomp.datamodel.Magnitude,
|
||||||
|
seiscomp.datamodel.StationMagnitude,
|
||||||
|
):
|
||||||
|
|
||||||
|
obj = self.query().loadObject(tp.TypeInfo(), publicID)
|
||||||
|
obj = tp.Cast(obj)
|
||||||
|
if obj:
|
||||||
|
ep = seiscomp.datamodel.EventParameters()
|
||||||
|
ep.add(obj)
|
||||||
|
return ep
|
||||||
|
|
||||||
|
def loadInventoryObject(self, publicID):
|
||||||
|
for tp in (
|
||||||
|
seiscomp.datamodel.Network,
|
||||||
|
seiscomp.datamodel.Station,
|
||||||
|
seiscomp.datamodel.Sensor,
|
||||||
|
seiscomp.datamodel.SensorLocation,
|
||||||
|
seiscomp.datamodel.Stream,
|
||||||
|
):
|
||||||
|
|
||||||
|
obj = self.query().loadObject(tp.TypeInfo(), publicID)
|
||||||
|
obj = tp.Cast(obj)
|
||||||
|
if obj:
|
||||||
|
return obj
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
publicID = self.commandline().optionString("public-id")
|
||||||
|
obj = self.loadEventParametersObject(publicID)
|
||||||
|
if obj is None:
|
||||||
|
obj = self.loadInventoryObject(publicID)
|
||||||
|
if obj is None:
|
||||||
|
raise ValueError("unknown object '" + publicID + "'")
|
||||||
|
|
||||||
|
# dump formatted XML archive to stdout
|
||||||
|
ar = seiscomp.io.XMLArchive()
|
||||||
|
ar.setFormattedOutput(True)
|
||||||
|
ar.create("-")
|
||||||
|
ar.writeObject(obj)
|
||||||
|
ar.close()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = ObjectDumper()
|
||||||
|
app()
|
||||||
BIN
bin/scevent
BIN
bin/scevent
Binary file not shown.
BIN
bin/scheli
BIN
bin/scheli
Binary file not shown.
BIN
bin/scimex
BIN
bin/scimex
Binary file not shown.
BIN
bin/scimport
BIN
bin/scimport
Binary file not shown.
BIN
bin/scmapcut
BIN
bin/scmapcut
Binary file not shown.
BIN
bin/scmaster
BIN
bin/scmaster
Binary file not shown.
BIN
bin/scorg2nll
BIN
bin/scorg2nll
Binary file not shown.
BIN
bin/scplot
BIN
bin/scplot
Binary file not shown.
BIN
bin/scquery
BIN
bin/scquery
Binary file not shown.
BIN
bin/screloc
BIN
bin/screloc
Binary file not shown.
BIN
bin/screpick
BIN
bin/screpick
Binary file not shown.
BIN
bin/scrttv
BIN
bin/scrttv
Binary file not shown.
BIN
bin/scshowevent
BIN
bin/scshowevent
Binary file not shown.
BIN
bin/scsmdump
BIN
bin/scsmdump
Binary file not shown.
BIN
bin/scwfas
BIN
bin/scwfas
Binary file not shown.
BIN
bin/scwfparam
BIN
bin/scwfparam
Binary file not shown.
BIN
bin/scxmldump
BIN
bin/scxmldump
Binary file not shown.
BIN
bin/scxmlmerge
BIN
bin/scxmlmerge
Binary file not shown.
BIN
bin/slarchive
BIN
bin/slarchive
Binary file not shown.
BIN
bin/slinktool
BIN
bin/slinktool
Binary file not shown.
BIN
bin/tau_remodl
BIN
bin/tau_remodl
Binary file not shown.
BIN
bin/tau_setbrn
BIN
bin/tau_setbrn
Binary file not shown.
BIN
bin/timeout
BIN
bin/timeout
Binary file not shown.
BIN
bin/trylock
BIN
bin/trylock
Binary file not shown.
BIN
bin/waitlock
BIN
bin/waitlock
Binary file not shown.
16
etc/descriptions/inv2dlsv.xml
Normal file
16
etc/descriptions/inv2dlsv.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<seiscomp>
|
||||||
|
<module name="inv2dlsv" category="Inventory" standalone="true">
|
||||||
|
<description>Converts SC3 inventory XML to dataless SEED.</description>
|
||||||
|
<command-line>
|
||||||
|
<synopsis>
|
||||||
|
inv2dlsv [in_xml [out_dataless]]
|
||||||
|
</synopsis>
|
||||||
|
<description>
|
||||||
|
If in_xml is not given, stdin is used. If out_dataless is not given,
|
||||||
|
stdout is used.
|
||||||
|
</description>
|
||||||
|
</command-line>
|
||||||
|
</module>
|
||||||
|
</seiscomp>
|
||||||
|
|
||||||
18
include/libbson-1.0/bson.h
Normal file
18
include/libbson-1.0/bson.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-present MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Including bson.h is superseded. Use bson/bson.h instead. */
|
||||||
|
#include "bson/bson.h"
|
||||||
295
include/libbson-1.0/bson/bcon.h
Normal file
295
include/libbson-1.0/bson/bcon.h
Normal file
@ -0,0 +1,295 @@
|
|||||||
|
/*
|
||||||
|
* @file bcon.h
|
||||||
|
* @brief BCON (BSON C Object Notation) Declarations
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
/* Copyright 2009-2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BCON_H_
|
||||||
|
#define BCON_H_
|
||||||
|
|
||||||
|
#include "bson/bson.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#define BCON_STACK_MAX 100
|
||||||
|
|
||||||
|
#define BCON_ENSURE_DECLARE(fun, type) \
|
||||||
|
static BSON_INLINE type bcon_ensure_##fun (type _t) \
|
||||||
|
{ \
|
||||||
|
return _t; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define BCON_ENSURE(fun, val) bcon_ensure_##fun (val)
|
||||||
|
|
||||||
|
#define BCON_ENSURE_STORAGE(fun, val) bcon_ensure_##fun (&(val))
|
||||||
|
|
||||||
|
BCON_ENSURE_DECLARE (const_char_ptr, const char *)
|
||||||
|
BCON_ENSURE_DECLARE (const_char_ptr_ptr, const char **)
|
||||||
|
BCON_ENSURE_DECLARE (double, double)
|
||||||
|
BCON_ENSURE_DECLARE (double_ptr, double *)
|
||||||
|
BCON_ENSURE_DECLARE (const_bson_ptr, const bson_t *)
|
||||||
|
BCON_ENSURE_DECLARE (bson_ptr, bson_t *)
|
||||||
|
BCON_ENSURE_DECLARE (subtype, bson_subtype_t)
|
||||||
|
BCON_ENSURE_DECLARE (subtype_ptr, bson_subtype_t *)
|
||||||
|
BCON_ENSURE_DECLARE (const_uint8_ptr, const uint8_t *)
|
||||||
|
BCON_ENSURE_DECLARE (const_uint8_ptr_ptr, const uint8_t **)
|
||||||
|
BCON_ENSURE_DECLARE (uint32, uint32_t)
|
||||||
|
BCON_ENSURE_DECLARE (uint32_ptr, uint32_t *)
|
||||||
|
BCON_ENSURE_DECLARE (const_oid_ptr, const bson_oid_t *)
|
||||||
|
BCON_ENSURE_DECLARE (const_oid_ptr_ptr, const bson_oid_t **)
|
||||||
|
BCON_ENSURE_DECLARE (int32, int32_t)
|
||||||
|
BCON_ENSURE_DECLARE (int32_ptr, int32_t *)
|
||||||
|
BCON_ENSURE_DECLARE (int64, int64_t)
|
||||||
|
BCON_ENSURE_DECLARE (int64_ptr, int64_t *)
|
||||||
|
BCON_ENSURE_DECLARE (const_decimal128_ptr, const bson_decimal128_t *)
|
||||||
|
BCON_ENSURE_DECLARE (bool, bool)
|
||||||
|
BCON_ENSURE_DECLARE (bool_ptr, bool *)
|
||||||
|
BCON_ENSURE_DECLARE (bson_type, bson_type_t)
|
||||||
|
BCON_ENSURE_DECLARE (bson_iter_ptr, bson_iter_t *)
|
||||||
|
BCON_ENSURE_DECLARE (const_bson_iter_ptr, const bson_iter_t *)
|
||||||
|
|
||||||
|
#define BCON_UTF8(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_UTF8, BCON_ENSURE (const_char_ptr, (_val))
|
||||||
|
#define BCON_DOUBLE(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_DOUBLE, BCON_ENSURE (double, (_val))
|
||||||
|
#define BCON_DOCUMENT(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_DOCUMENT, BCON_ENSURE (const_bson_ptr, (_val))
|
||||||
|
#define BCON_ARRAY(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_ARRAY, BCON_ENSURE (const_bson_ptr, (_val))
|
||||||
|
#define BCON_BIN(_subtype, _binary, _length) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_BIN, BCON_ENSURE (subtype, (_subtype)), \
|
||||||
|
BCON_ENSURE (const_uint8_ptr, (_binary)), \
|
||||||
|
BCON_ENSURE (uint32, (_length))
|
||||||
|
#define BCON_UNDEFINED BCON_MAGIC, BCON_TYPE_UNDEFINED
|
||||||
|
#define BCON_OID(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_OID, BCON_ENSURE (const_oid_ptr, (_val))
|
||||||
|
#define BCON_BOOL(_val) BCON_MAGIC, BCON_TYPE_BOOL, BCON_ENSURE (bool, (_val))
|
||||||
|
#define BCON_DATE_TIME(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_DATE_TIME, BCON_ENSURE (int64, (_val))
|
||||||
|
#define BCON_NULL BCON_MAGIC, BCON_TYPE_NULL
|
||||||
|
#define BCON_REGEX(_regex, _flags) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_REGEX, BCON_ENSURE (const_char_ptr, (_regex)), \
|
||||||
|
BCON_ENSURE (const_char_ptr, (_flags))
|
||||||
|
#define BCON_DBPOINTER(_collection, _oid) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_DBPOINTER, \
|
||||||
|
BCON_ENSURE (const_char_ptr, (_collection)), \
|
||||||
|
BCON_ENSURE (const_oid_ptr, (_oid))
|
||||||
|
#define BCON_CODE(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_CODE, BCON_ENSURE (const_char_ptr, (_val))
|
||||||
|
#define BCON_SYMBOL(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_SYMBOL, BCON_ENSURE (const_char_ptr, (_val))
|
||||||
|
#define BCON_CODEWSCOPE(_js, _scope) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_CODEWSCOPE, BCON_ENSURE (const_char_ptr, (_js)), \
|
||||||
|
BCON_ENSURE (const_bson_ptr, (_scope))
|
||||||
|
#define BCON_INT32(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_INT32, BCON_ENSURE (int32, (_val))
|
||||||
|
#define BCON_TIMESTAMP(_timestamp, _increment) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_TIMESTAMP, BCON_ENSURE (int32, (_timestamp)), \
|
||||||
|
BCON_ENSURE (int32, (_increment))
|
||||||
|
#define BCON_INT64(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_INT64, BCON_ENSURE (int64, (_val))
|
||||||
|
#define BCON_DECIMAL128(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_DECIMAL128, BCON_ENSURE (const_decimal128_ptr, (_val))
|
||||||
|
#define BCON_MAXKEY BCON_MAGIC, BCON_TYPE_MAXKEY
|
||||||
|
#define BCON_MINKEY BCON_MAGIC, BCON_TYPE_MINKEY
|
||||||
|
#define BCON(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_BCON, BCON_ENSURE (const_bson_ptr, (_val))
|
||||||
|
#define BCON_ITER(_val) \
|
||||||
|
BCON_MAGIC, BCON_TYPE_ITER, BCON_ENSURE (const_bson_iter_ptr, (_val))
|
||||||
|
|
||||||
|
#define BCONE_UTF8(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_UTF8, BCON_ENSURE_STORAGE (const_char_ptr_ptr, (_val))
|
||||||
|
#define BCONE_DOUBLE(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_DOUBLE, BCON_ENSURE_STORAGE (double_ptr, (_val))
|
||||||
|
#define BCONE_DOCUMENT(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_DOCUMENT, BCON_ENSURE_STORAGE (bson_ptr, (_val))
|
||||||
|
#define BCONE_ARRAY(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_ARRAY, BCON_ENSURE_STORAGE (bson_ptr, (_val))
|
||||||
|
#define BCONE_BIN(subtype, binary, length) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_BIN, BCON_ENSURE_STORAGE (subtype_ptr, (subtype)), \
|
||||||
|
BCON_ENSURE_STORAGE (const_uint8_ptr_ptr, (binary)), \
|
||||||
|
BCON_ENSURE_STORAGE (uint32_ptr, (length))
|
||||||
|
#define BCONE_UNDEFINED BCONE_MAGIC, BCON_TYPE_UNDEFINED
|
||||||
|
#define BCONE_OID(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_OID, BCON_ENSURE_STORAGE (const_oid_ptr_ptr, (_val))
|
||||||
|
#define BCONE_BOOL(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_BOOL, BCON_ENSURE_STORAGE (bool_ptr, (_val))
|
||||||
|
#define BCONE_DATE_TIME(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_DATE_TIME, BCON_ENSURE_STORAGE (int64_ptr, (_val))
|
||||||
|
#define BCONE_NULL BCONE_MAGIC, BCON_TYPE_NULL
|
||||||
|
#define BCONE_REGEX(_regex, _flags) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_REGEX, \
|
||||||
|
BCON_ENSURE_STORAGE (const_char_ptr_ptr, (_regex)), \
|
||||||
|
BCON_ENSURE_STORAGE (const_char_ptr_ptr, (_flags))
|
||||||
|
#define BCONE_DBPOINTER(_collection, _oid) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_DBPOINTER, \
|
||||||
|
BCON_ENSURE_STORAGE (const_char_ptr_ptr, (_collection)), \
|
||||||
|
BCON_ENSURE_STORAGE (const_oid_ptr_ptr, (_oid))
|
||||||
|
#define BCONE_CODE(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_CODE, BCON_ENSURE_STORAGE (const_char_ptr_ptr, (_val))
|
||||||
|
#define BCONE_SYMBOL(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_SYMBOL, \
|
||||||
|
BCON_ENSURE_STORAGE (const_char_ptr_ptr, (_val))
|
||||||
|
#define BCONE_CODEWSCOPE(_js, _scope) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_CODEWSCOPE, \
|
||||||
|
BCON_ENSURE_STORAGE (const_char_ptr_ptr, (_js)), \
|
||||||
|
BCON_ENSURE_STORAGE (bson_ptr, (_scope))
|
||||||
|
#define BCONE_INT32(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_INT32, BCON_ENSURE_STORAGE (int32_ptr, (_val))
|
||||||
|
#define BCONE_TIMESTAMP(_timestamp, _increment) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_TIMESTAMP, \
|
||||||
|
BCON_ENSURE_STORAGE (int32_ptr, (_timestamp)), \
|
||||||
|
BCON_ENSURE_STORAGE (int32_ptr, (_increment))
|
||||||
|
#define BCONE_INT64(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_INT64, BCON_ENSURE_STORAGE (int64_ptr, (_val))
|
||||||
|
#define BCONE_DECIMAL128(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_DECIMAL128, \
|
||||||
|
BCON_ENSURE_STORAGE (const_decimal128_ptr, (_val))
|
||||||
|
#define BCONE_MAXKEY BCONE_MAGIC, BCON_TYPE_MAXKEY
|
||||||
|
#define BCONE_MINKEY BCONE_MAGIC, BCON_TYPE_MINKEY
|
||||||
|
#define BCONE_SKIP(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_SKIP, BCON_ENSURE (bson_type, (_val))
|
||||||
|
#define BCONE_ITER(_val) \
|
||||||
|
BCONE_MAGIC, BCON_TYPE_ITER, BCON_ENSURE_STORAGE (bson_iter_ptr, (_val))
|
||||||
|
|
||||||
|
#define BCON_MAGIC bson_bcon_magic ()
|
||||||
|
#define BCONE_MAGIC bson_bcone_magic ()
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BCON_TYPE_UTF8,
|
||||||
|
BCON_TYPE_DOUBLE,
|
||||||
|
BCON_TYPE_DOCUMENT,
|
||||||
|
BCON_TYPE_ARRAY,
|
||||||
|
BCON_TYPE_BIN,
|
||||||
|
BCON_TYPE_UNDEFINED,
|
||||||
|
BCON_TYPE_OID,
|
||||||
|
BCON_TYPE_BOOL,
|
||||||
|
BCON_TYPE_DATE_TIME,
|
||||||
|
BCON_TYPE_NULL,
|
||||||
|
BCON_TYPE_REGEX,
|
||||||
|
BCON_TYPE_DBPOINTER,
|
||||||
|
BCON_TYPE_CODE,
|
||||||
|
BCON_TYPE_SYMBOL,
|
||||||
|
BCON_TYPE_CODEWSCOPE,
|
||||||
|
BCON_TYPE_INT32,
|
||||||
|
BCON_TYPE_TIMESTAMP,
|
||||||
|
BCON_TYPE_INT64,
|
||||||
|
BCON_TYPE_DECIMAL128,
|
||||||
|
BCON_TYPE_MAXKEY,
|
||||||
|
BCON_TYPE_MINKEY,
|
||||||
|
BCON_TYPE_BCON,
|
||||||
|
BCON_TYPE_ARRAY_START,
|
||||||
|
BCON_TYPE_ARRAY_END,
|
||||||
|
BCON_TYPE_DOC_START,
|
||||||
|
BCON_TYPE_DOC_END,
|
||||||
|
BCON_TYPE_END,
|
||||||
|
BCON_TYPE_RAW,
|
||||||
|
BCON_TYPE_SKIP,
|
||||||
|
BCON_TYPE_ITER,
|
||||||
|
BCON_TYPE_ERROR,
|
||||||
|
} bcon_type_t;
|
||||||
|
|
||||||
|
typedef struct bcon_append_ctx_frame {
|
||||||
|
int i;
|
||||||
|
bool is_array;
|
||||||
|
bson_t bson;
|
||||||
|
} bcon_append_ctx_frame_t;
|
||||||
|
|
||||||
|
typedef struct bcon_extract_ctx_frame {
|
||||||
|
int i;
|
||||||
|
bool is_array;
|
||||||
|
bson_iter_t iter;
|
||||||
|
} bcon_extract_ctx_frame_t;
|
||||||
|
|
||||||
|
typedef struct _bcon_append_ctx_t {
|
||||||
|
bcon_append_ctx_frame_t stack[BCON_STACK_MAX];
|
||||||
|
int n;
|
||||||
|
} bcon_append_ctx_t;
|
||||||
|
|
||||||
|
typedef struct _bcon_extract_ctx_t {
|
||||||
|
bcon_extract_ctx_frame_t stack[BCON_STACK_MAX];
|
||||||
|
int n;
|
||||||
|
} bcon_extract_ctx_t;
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bcon_append (bson_t *bson, ...) BSON_GNUC_NULL_TERMINATED;
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bcon_append_ctx (bson_t *bson,
|
||||||
|
bcon_append_ctx_t *ctx,
|
||||||
|
...) BSON_GNUC_NULL_TERMINATED;
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bcon_append_ctx_va (bson_t *bson, bcon_append_ctx_t *ctx, va_list *va);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bcon_append_ctx_init (bcon_append_ctx_t *ctx);
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bcon_extract_ctx_init (bcon_extract_ctx_t *ctx);
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bcon_extract_ctx (bson_t *bson,
|
||||||
|
bcon_extract_ctx_t *ctx,
|
||||||
|
...) BSON_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bcon_extract_ctx_va (bson_t *bson, bcon_extract_ctx_t *ctx, va_list *ap);
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bcon_extract (bson_t *bson, ...) BSON_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bcon_extract_va (bson_t *bson,
|
||||||
|
bcon_extract_ctx_t *ctx,
|
||||||
|
...) BSON_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
|
BSON_EXPORT (bson_t *)
|
||||||
|
bcon_new (void *unused, ...) BSON_GNUC_NULL_TERMINATED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bcon_..() functions are all declared with __attribute__((sentinel)).
|
||||||
|
*
|
||||||
|
* From GCC manual for "sentinel": "A valid NULL in this context is defined as
|
||||||
|
* zero with any pointer type. If your system defines the NULL macro with an
|
||||||
|
* integer type then you need to add an explicit cast."
|
||||||
|
* Case in point: GCC on Solaris (at least)
|
||||||
|
*/
|
||||||
|
#define BCON_APPEND(_bson, ...) \
|
||||||
|
bcon_append ((_bson), __VA_ARGS__, (void *) NULL)
|
||||||
|
#define BCON_APPEND_CTX(_bson, _ctx, ...) \
|
||||||
|
bcon_append_ctx ((_bson), (_ctx), __VA_ARGS__, (void *) NULL)
|
||||||
|
|
||||||
|
#define BCON_EXTRACT(_bson, ...) \
|
||||||
|
bcon_extract ((_bson), __VA_ARGS__, (void *) NULL)
|
||||||
|
|
||||||
|
#define BCON_EXTRACT_CTX(_bson, _ctx, ...) \
|
||||||
|
bcon_extract ((_bson), (_ctx), __VA_ARGS__, (void *) NULL)
|
||||||
|
|
||||||
|
#define BCON_NEW(...) bcon_new (NULL, __VA_ARGS__, (void *) NULL)
|
||||||
|
|
||||||
|
BSON_EXPORT (const char *)
|
||||||
|
bson_bcon_magic (void) BSON_GNUC_PURE;
|
||||||
|
BSON_EXPORT (const char *)
|
||||||
|
bson_bcone_magic (void) BSON_GNUC_PURE;
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
105
include/libbson-1.0/bson/bson-atomic.h
Normal file
105
include/libbson-1.0/bson/bson-atomic.h
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2014 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_ATOMIC_H
|
||||||
|
#define BSON_ATOMIC_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-config.h"
|
||||||
|
#include "bson/bson-compat.h"
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__sun) && defined(__SVR4)
|
||||||
|
/* Solaris */
|
||||||
|
#include <atomic.h>
|
||||||
|
#define bson_atomic_int_add(p, v) \
|
||||||
|
atomic_add_32_nv ((volatile uint32_t *) p, (v))
|
||||||
|
#define bson_atomic_int64_add(p, v) \
|
||||||
|
atomic_add_64_nv ((volatile uint64_t *) p, (v))
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
/* MSVC/MinGW */
|
||||||
|
#define bson_atomic_int_add(p, v) \
|
||||||
|
(InterlockedExchangeAdd ((volatile LONG *) (p), (LONG) (v)) + (LONG) (v))
|
||||||
|
#define bson_atomic_int64_add(p, v) \
|
||||||
|
(InterlockedExchangeAdd64 ((volatile LONGLONG *) (p), (LONGLONG) (v)) + \
|
||||||
|
(LONGLONG) (v))
|
||||||
|
#else
|
||||||
|
#ifdef BSON_HAVE_ATOMIC_32_ADD_AND_FETCH
|
||||||
|
#define bson_atomic_int_add(p, v) __sync_add_and_fetch ((p), (v))
|
||||||
|
#else
|
||||||
|
#define __BSON_NEED_ATOMIC_32
|
||||||
|
#endif
|
||||||
|
#ifdef BSON_HAVE_ATOMIC_64_ADD_AND_FETCH
|
||||||
|
#if BSON_GNUC_IS_VERSION(4, 1)
|
||||||
|
/*
|
||||||
|
* GCC 4.1 on i386 can generate buggy 64-bit atomic increment.
|
||||||
|
* So we will work around with a fallback.
|
||||||
|
*
|
||||||
|
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40693
|
||||||
|
*/
|
||||||
|
#define __BSON_NEED_ATOMIC_64
|
||||||
|
#else
|
||||||
|
#define bson_atomic_int64_add(p, v) \
|
||||||
|
__sync_add_and_fetch ((volatile int64_t *) (p), (int64_t) (v))
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define __BSON_NEED_ATOMIC_64
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __BSON_NEED_ATOMIC_32
|
||||||
|
BSON_EXPORT (int32_t)
|
||||||
|
bson_atomic_int_add (volatile int32_t *p, int32_t n);
|
||||||
|
#endif
|
||||||
|
#ifdef __BSON_NEED_ATOMIC_64
|
||||||
|
BSON_EXPORT (int64_t)
|
||||||
|
bson_atomic_int64_add (volatile int64_t *p, int64_t n);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define bson_memory_barrier() MemoryBarrier ()
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#if BSON_GNUC_CHECK_VERSION(4, 1)
|
||||||
|
#define bson_memory_barrier() __sync_synchronize ()
|
||||||
|
#else
|
||||||
|
#warning "GCC Pre-4.1 discovered, using inline assembly for memory barrier."
|
||||||
|
#define bson_memory_barrier() __asm__ volatile("" ::: "memory")
|
||||||
|
#endif
|
||||||
|
#elif defined(__SUNPRO_C)
|
||||||
|
#include <mbarrier.h>
|
||||||
|
#define bson_memory_barrier() __machine_rw_barrier ()
|
||||||
|
#elif defined(__xlC__)
|
||||||
|
#define bson_memory_barrier() __sync ()
|
||||||
|
#else
|
||||||
|
#define __BSON_NEED_BARRIER 1
|
||||||
|
#warning "Unknown compiler, using lock for compiler barrier."
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_memory_barrier (void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_ATOMIC_H */
|
||||||
41
include/libbson-1.0/bson/bson-clock.h
Normal file
41
include/libbson-1.0/bson/bson-clock.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_CLOCK_H
|
||||||
|
#define BSON_CLOCK_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-compat.h"
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (int64_t)
|
||||||
|
bson_get_monotonic_time (void);
|
||||||
|
BSON_EXPORT (int)
|
||||||
|
bson_gettimeofday (struct timeval *tv);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_CLOCK_H */
|
||||||
177
include/libbson-1.0/bson/bson-compat.h
Normal file
177
include/libbson-1.0/bson/bson-compat.h
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_COMPAT_H
|
||||||
|
#define BSON_COMPAT_H
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__MINGW32__)
|
||||||
|
#if defined(__USE_MINGW_ANSI_STDIO)
|
||||||
|
#if __USE_MINGW_ANSI_STDIO < 1
|
||||||
|
#error "__USE_MINGW_ANSI_STDIO > 0 is required for correct PRI* macros"
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define __USE_MINGW_ANSI_STDIO 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "bson/bson-config.h"
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef BSON_OS_WIN32
|
||||||
|
#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600)
|
||||||
|
#undef _WIN32_WINNT
|
||||||
|
#endif
|
||||||
|
#ifndef _WIN32_WINNT
|
||||||
|
#define _WIN32_WINNT 0x0600
|
||||||
|
#endif
|
||||||
|
#ifndef NOMINMAX
|
||||||
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
|
#include <winsock2.h>
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#undef WIN32_LEAN_AND_MEAN
|
||||||
|
#else
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
#include <direct.h>
|
||||||
|
#include <io.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef BSON_OS_UNIX
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
#if !defined(_MSC_VER) || (_MSC_VER >= 1800)
|
||||||
|
#include <inttypes.h>
|
||||||
|
#endif
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#ifndef __cplusplus
|
||||||
|
/* benign redefinition of type */
|
||||||
|
#pragma warning(disable : 4142)
|
||||||
|
#ifndef _SSIZE_T_DEFINED
|
||||||
|
#define _SSIZE_T_DEFINED
|
||||||
|
typedef SSIZE_T ssize_t;
|
||||||
|
#endif
|
||||||
|
#ifndef _SIZE_T_DEFINED
|
||||||
|
#define _SIZE_T_DEFINED
|
||||||
|
typedef SIZE_T size_t;
|
||||||
|
#endif
|
||||||
|
#pragma warning(default : 4142)
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* MSVC++ does not include ssize_t, just size_t.
|
||||||
|
* So we need to synthesize that as well.
|
||||||
|
*/
|
||||||
|
#pragma warning(disable : 4142)
|
||||||
|
#ifndef _SSIZE_T_DEFINED
|
||||||
|
#define _SSIZE_T_DEFINED
|
||||||
|
typedef SSIZE_T ssize_t;
|
||||||
|
#endif
|
||||||
|
#pragma warning(default : 4142)
|
||||||
|
#endif
|
||||||
|
#ifndef PRIi32
|
||||||
|
#define PRIi32 "d"
|
||||||
|
#endif
|
||||||
|
#ifndef PRId32
|
||||||
|
#define PRId32 "d"
|
||||||
|
#endif
|
||||||
|
#ifndef PRIu32
|
||||||
|
#define PRIu32 "u"
|
||||||
|
#endif
|
||||||
|
#ifndef PRIi64
|
||||||
|
#define PRIi64 "I64i"
|
||||||
|
#endif
|
||||||
|
#ifndef PRId64
|
||||||
|
#define PRId64 "I64i"
|
||||||
|
#endif
|
||||||
|
#ifndef PRIu64
|
||||||
|
#define PRIu64 "I64u"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__MINGW32__) && !defined(INIT_ONCE_STATIC_INIT)
|
||||||
|
#define INIT_ONCE_STATIC_INIT RTL_RUN_ONCE_INIT
|
||||||
|
typedef RTL_RUN_ONCE INIT_ONCE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BSON_HAVE_STDBOOL_H
|
||||||
|
#include <stdbool.h>
|
||||||
|
#elif !defined(__bool_true_false_are_defined)
|
||||||
|
#ifndef __cplusplus
|
||||||
|
typedef signed char bool;
|
||||||
|
#define false 0
|
||||||
|
#define true 1
|
||||||
|
#endif
|
||||||
|
#define __bool_true_false_are_defined 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
|
||||||
|
#define bson_sync_synchronize() __sync_synchronize ()
|
||||||
|
#elif defined(__i386__) || defined(__i486__) || defined(__i586__) || \
|
||||||
|
defined(__i686__) || defined(__x86_64__)
|
||||||
|
#define bson_sync_synchronize() asm volatile("mfence" ::: "memory")
|
||||||
|
#else
|
||||||
|
#define bson_sync_synchronize() asm volatile("sync" ::: "memory")
|
||||||
|
#endif
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#define bson_sync_synchronize() MemoryBarrier ()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(va_copy) && defined(__va_copy)
|
||||||
|
#define va_copy(dst, src) __va_copy (dst, src)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(va_copy)
|
||||||
|
#define va_copy(dst, src) ((dst) = (src))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_COMPAT_H */
|
||||||
151
include/libbson-1.0/bson/bson-config.h
Normal file
151
include/libbson-1.0/bson/bson-config.h
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-present MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(BSON_INSIDE) && !defined(BSON_COMPILATION)
|
||||||
|
#error "Only <bson/bson.h> can be included directly."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BSON_CONFIG_H
|
||||||
|
#define BSON_CONFIG_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1234 for Little Endian, 4321 for Big Endian.
|
||||||
|
*/
|
||||||
|
#define BSON_BYTE_ORDER 1234
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if you have stdbool.h
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_STDBOOL_H 1
|
||||||
|
#if BSON_HAVE_STDBOOL_H != 1
|
||||||
|
# undef BSON_HAVE_STDBOOL_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 for POSIX-like systems, 2 for Windows.
|
||||||
|
*/
|
||||||
|
#define BSON_OS 1
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if we have access to GCC 32-bit atomic builtins.
|
||||||
|
* While this requires GCC 4.1+ in most cases, it is also architecture
|
||||||
|
* dependent. For example, some PPC or ARM systems may not have it even
|
||||||
|
* if it is a recent GCC version.
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_ATOMIC_32_ADD_AND_FETCH 1
|
||||||
|
#if BSON_HAVE_ATOMIC_32_ADD_AND_FETCH != 1
|
||||||
|
# undef BSON_HAVE_ATOMIC_32_ADD_AND_FETCH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Similarly, define to 1 if we have access to GCC 64-bit atomic builtins.
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_ATOMIC_64_ADD_AND_FETCH 1
|
||||||
|
#if BSON_HAVE_ATOMIC_64_ADD_AND_FETCH != 1
|
||||||
|
# undef BSON_HAVE_ATOMIC_64_ADD_AND_FETCH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if you have clock_gettime() available.
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_CLOCK_GETTIME 1
|
||||||
|
#if BSON_HAVE_CLOCK_GETTIME != 1
|
||||||
|
# undef BSON_HAVE_CLOCK_GETTIME
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if you have strings.h available on your platform.
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_STRINGS_H 1
|
||||||
|
#if BSON_HAVE_STRINGS_H != 1
|
||||||
|
# undef BSON_HAVE_STRINGS_H
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if you have strnlen available on your platform.
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_STRNLEN 1
|
||||||
|
#if BSON_HAVE_STRNLEN != 1
|
||||||
|
# undef BSON_HAVE_STRNLEN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if you have snprintf available on your platform.
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_SNPRINTF 1
|
||||||
|
#if BSON_HAVE_SNPRINTF != 1
|
||||||
|
# undef BSON_HAVE_SNPRINTF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if you have gmtime_r available on your platform.
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_GMTIME_R 1
|
||||||
|
#if BSON_HAVE_GMTIME_R != 1
|
||||||
|
# undef BSON_HAVE_GMTIME_R
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if you have reallocf available on your platform.
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_REALLOCF 0
|
||||||
|
#if BSON_HAVE_REALLOCF != 1
|
||||||
|
# undef BSON_HAVE_REALLOCF
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if you have struct timespec available on your platform.
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_TIMESPEC 1
|
||||||
|
#if BSON_HAVE_TIMESPEC != 1
|
||||||
|
# undef BSON_HAVE_TIMESPEC
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if you want extra aligned types in libbson
|
||||||
|
*/
|
||||||
|
#define BSON_EXTRA_ALIGN 0
|
||||||
|
#if BSON_EXTRA_ALIGN != 1
|
||||||
|
# undef BSON_EXTRA_ALIGN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define to 1 if you have SYS_gettid syscall
|
||||||
|
*/
|
||||||
|
#define BSON_HAVE_SYSCALL_TID 1
|
||||||
|
#if BSON_HAVE_SYSCALL_TID != 1
|
||||||
|
# undef BSON_HAVE_SYSCALL_TID
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BSON_HAVE_RAND_R 1
|
||||||
|
#if BSON_HAVE_RAND_R != 1
|
||||||
|
# undef BSON_HAVE_RAND_R
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_CONFIG_H */
|
||||||
42
include/libbson-1.0/bson/bson-context.h
Normal file
42
include/libbson-1.0/bson/bson-context.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_CONTEXT_H
|
||||||
|
#define BSON_CONTEXT_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bson_context_t *)
|
||||||
|
bson_context_new (bson_context_flags_t flags);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_context_destroy (bson_context_t *context);
|
||||||
|
BSON_EXPORT (bson_context_t *)
|
||||||
|
bson_context_get_default (void);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_CONTEXT_H */
|
||||||
64
include/libbson-1.0/bson/bson-decimal128.h
Normal file
64
include/libbson-1.0/bson/bson-decimal128.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_DECIMAL128_H
|
||||||
|
#define BSON_DECIMAL128_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-config.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSON_DECIMAL128_STRING:
|
||||||
|
*
|
||||||
|
* The length of a decimal128 string (with null terminator).
|
||||||
|
*
|
||||||
|
* 1 for the sign
|
||||||
|
* 35 for digits and radix
|
||||||
|
* 2 for exponent indicator and sign
|
||||||
|
* 4 for exponent digits
|
||||||
|
*/
|
||||||
|
#define BSON_DECIMAL128_STRING 43
|
||||||
|
#define BSON_DECIMAL128_INF "Infinity"
|
||||||
|
#define BSON_DECIMAL128_NAN "NaN"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_decimal128_to_string (const bson_decimal128_t *dec, char *str);
|
||||||
|
|
||||||
|
|
||||||
|
/* Note: @string must be ASCII characters only! */
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_decimal128_from_string (const char *string, bson_decimal128_t *dec);
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_decimal128_from_string_w_len (const char *string,
|
||||||
|
int len,
|
||||||
|
bson_decimal128_t *dec);
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_DECIMAL128_H */
|
||||||
227
include/libbson-1.0/bson/bson-endian.h
Normal file
227
include/libbson-1.0/bson/bson-endian.h
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_ENDIAN_H
|
||||||
|
#define BSON_ENDIAN_H
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__sun)
|
||||||
|
#include <sys/byteorder.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "bson/bson-config.h"
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-compat.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#define BSON_BIG_ENDIAN 4321
|
||||||
|
#define BSON_LITTLE_ENDIAN 1234
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__sun)
|
||||||
|
#define BSON_UINT16_SWAP_LE_BE(v) BSWAP_16 ((uint16_t) v)
|
||||||
|
#define BSON_UINT32_SWAP_LE_BE(v) BSWAP_32 ((uint32_t) v)
|
||||||
|
#define BSON_UINT64_SWAP_LE_BE(v) BSWAP_64 ((uint64_t) v)
|
||||||
|
#elif defined(__clang__) && defined(__clang_major__) && \
|
||||||
|
defined(__clang_minor__) && (__clang_major__ >= 3) && \
|
||||||
|
(__clang_minor__ >= 1)
|
||||||
|
#if __has_builtin(__builtin_bswap16)
|
||||||
|
#define BSON_UINT16_SWAP_LE_BE(v) __builtin_bswap16 (v)
|
||||||
|
#endif
|
||||||
|
#if __has_builtin(__builtin_bswap32)
|
||||||
|
#define BSON_UINT32_SWAP_LE_BE(v) __builtin_bswap32 (v)
|
||||||
|
#endif
|
||||||
|
#if __has_builtin(__builtin_bswap64)
|
||||||
|
#define BSON_UINT64_SWAP_LE_BE(v) __builtin_bswap64 (v)
|
||||||
|
#endif
|
||||||
|
#elif defined(__GNUC__) && (__GNUC__ >= 4)
|
||||||
|
#if __GNUC__ > 4 || (defined(__GNUC_MINOR__) && __GNUC_MINOR__ >= 3)
|
||||||
|
#define BSON_UINT32_SWAP_LE_BE(v) __builtin_bswap32 ((uint32_t) v)
|
||||||
|
#define BSON_UINT64_SWAP_LE_BE(v) __builtin_bswap64 ((uint64_t) v)
|
||||||
|
#endif
|
||||||
|
#if __GNUC__ > 4 || (defined(__GNUC_MINOR__) && __GNUC_MINOR__ >= 8)
|
||||||
|
#define BSON_UINT16_SWAP_LE_BE(v) __builtin_bswap16 ((uint32_t) v)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_UINT16_SWAP_LE_BE
|
||||||
|
#define BSON_UINT16_SWAP_LE_BE(v) __bson_uint16_swap_slow ((uint16_t) v)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_UINT32_SWAP_LE_BE
|
||||||
|
#define BSON_UINT32_SWAP_LE_BE(v) __bson_uint32_swap_slow ((uint32_t) v)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_UINT64_SWAP_LE_BE
|
||||||
|
#define BSON_UINT64_SWAP_LE_BE(v) __bson_uint64_swap_slow ((uint64_t) v)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if BSON_BYTE_ORDER == BSON_LITTLE_ENDIAN
|
||||||
|
#define BSON_UINT16_FROM_LE(v) ((uint16_t) v)
|
||||||
|
#define BSON_UINT16_TO_LE(v) ((uint16_t) v)
|
||||||
|
#define BSON_UINT16_FROM_BE(v) BSON_UINT16_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT16_TO_BE(v) BSON_UINT16_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT32_FROM_LE(v) ((uint32_t) v)
|
||||||
|
#define BSON_UINT32_TO_LE(v) ((uint32_t) v)
|
||||||
|
#define BSON_UINT32_FROM_BE(v) BSON_UINT32_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT32_TO_BE(v) BSON_UINT32_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT64_FROM_LE(v) ((uint64_t) v)
|
||||||
|
#define BSON_UINT64_TO_LE(v) ((uint64_t) v)
|
||||||
|
#define BSON_UINT64_FROM_BE(v) BSON_UINT64_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT64_TO_BE(v) BSON_UINT64_SWAP_LE_BE (v)
|
||||||
|
#define BSON_DOUBLE_FROM_LE(v) ((double) v)
|
||||||
|
#define BSON_DOUBLE_TO_LE(v) ((double) v)
|
||||||
|
#elif BSON_BYTE_ORDER == BSON_BIG_ENDIAN
|
||||||
|
#define BSON_UINT16_FROM_LE(v) BSON_UINT16_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT16_TO_LE(v) BSON_UINT16_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT16_FROM_BE(v) ((uint16_t) v)
|
||||||
|
#define BSON_UINT16_TO_BE(v) ((uint16_t) v)
|
||||||
|
#define BSON_UINT32_FROM_LE(v) BSON_UINT32_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT32_TO_LE(v) BSON_UINT32_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT32_FROM_BE(v) ((uint32_t) v)
|
||||||
|
#define BSON_UINT32_TO_BE(v) ((uint32_t) v)
|
||||||
|
#define BSON_UINT64_FROM_LE(v) BSON_UINT64_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT64_TO_LE(v) BSON_UINT64_SWAP_LE_BE (v)
|
||||||
|
#define BSON_UINT64_FROM_BE(v) ((uint64_t) v)
|
||||||
|
#define BSON_UINT64_TO_BE(v) ((uint64_t) v)
|
||||||
|
#define BSON_DOUBLE_FROM_LE(v) (__bson_double_swap_slow (v))
|
||||||
|
#define BSON_DOUBLE_TO_LE(v) (__bson_double_swap_slow (v))
|
||||||
|
#else
|
||||||
|
#error "The endianness of target architecture is unknown."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* __bson_uint16_swap_slow --
|
||||||
|
*
|
||||||
|
* Fallback endianness conversion for 16-bit integers.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* The endian swapped version.
|
||||||
|
*
|
||||||
|
* Side effects:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static BSON_INLINE uint16_t
|
||||||
|
__bson_uint16_swap_slow (uint16_t v) /* IN */
|
||||||
|
{
|
||||||
|
return ((v & 0x00FF) << 8) | ((v & 0xFF00) >> 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* __bson_uint32_swap_slow --
|
||||||
|
*
|
||||||
|
* Fallback endianness conversion for 32-bit integers.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* The endian swapped version.
|
||||||
|
*
|
||||||
|
* Side effects:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static BSON_INLINE uint32_t
|
||||||
|
__bson_uint32_swap_slow (uint32_t v) /* IN */
|
||||||
|
{
|
||||||
|
return ((v & 0x000000FFU) << 24) | ((v & 0x0000FF00U) << 8) |
|
||||||
|
((v & 0x00FF0000U) >> 8) | ((v & 0xFF000000U) >> 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* __bson_uint64_swap_slow --
|
||||||
|
*
|
||||||
|
* Fallback endianness conversion for 64-bit integers.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* The endian swapped version.
|
||||||
|
*
|
||||||
|
* Side effects:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
static BSON_INLINE uint64_t
|
||||||
|
__bson_uint64_swap_slow (uint64_t v) /* IN */
|
||||||
|
{
|
||||||
|
return ((v & 0x00000000000000FFULL) << 56) |
|
||||||
|
((v & 0x000000000000FF00ULL) << 40) |
|
||||||
|
((v & 0x0000000000FF0000ULL) << 24) |
|
||||||
|
((v & 0x00000000FF000000ULL) << 8) |
|
||||||
|
((v & 0x000000FF00000000ULL) >> 8) |
|
||||||
|
((v & 0x0000FF0000000000ULL) >> 24) |
|
||||||
|
((v & 0x00FF000000000000ULL) >> 40) |
|
||||||
|
((v & 0xFF00000000000000ULL) >> 56);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* __bson_double_swap_slow --
|
||||||
|
*
|
||||||
|
* Fallback endianness conversion for double floating point.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* The endian swapped version.
|
||||||
|
*
|
||||||
|
* Side effects:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
BSON_STATIC_ASSERT2 (sizeof_uint64_t, sizeof (double) == sizeof (uint64_t));
|
||||||
|
|
||||||
|
static BSON_INLINE double
|
||||||
|
__bson_double_swap_slow (double v) /* IN */
|
||||||
|
{
|
||||||
|
uint64_t uv;
|
||||||
|
|
||||||
|
memcpy (&uv, &v, sizeof (v));
|
||||||
|
uv = BSON_UINT64_SWAP_LE_BE (uv);
|
||||||
|
memcpy (&v, &uv, sizeof (v));
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_ENDIAN_H */
|
||||||
50
include/libbson-1.0/bson/bson-error.h
Normal file
50
include/libbson-1.0/bson/bson-error.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_ERROR_H
|
||||||
|
#define BSON_ERROR_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-compat.h"
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#define BSON_ERROR_JSON 1
|
||||||
|
#define BSON_ERROR_READER 2
|
||||||
|
#define BSON_ERROR_INVALID 3
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_set_error (bson_error_t *error,
|
||||||
|
uint32_t domain,
|
||||||
|
uint32_t code,
|
||||||
|
const char *format,
|
||||||
|
...) BSON_GNUC_PRINTF (4, 5);
|
||||||
|
BSON_EXPORT (char *)
|
||||||
|
bson_strerror_r (int err_code, char *buf, size_t buflen);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_ERROR_H */
|
||||||
547
include/libbson-1.0/bson/bson-iter.h
Normal file
547
include/libbson-1.0/bson/bson-iter.h
Normal file
@ -0,0 +1,547 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_ITER_H
|
||||||
|
#define BSON_ITER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson.h"
|
||||||
|
#include "bson/bson-endian.h"
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_DOUBLE(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_DOUBLE)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_UTF8(iter) (bson_iter_type ((iter)) == BSON_TYPE_UTF8)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_DOCUMENT(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_DOCUMENT)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_ARRAY(iter) (bson_iter_type ((iter)) == BSON_TYPE_ARRAY)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_BINARY(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_BINARY)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_UNDEFINED(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_UNDEFINED)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_OID(iter) (bson_iter_type ((iter)) == BSON_TYPE_OID)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_BOOL(iter) (bson_iter_type ((iter)) == BSON_TYPE_BOOL)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_DATE_TIME(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_DATE_TIME)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_NULL(iter) (bson_iter_type ((iter)) == BSON_TYPE_NULL)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_REGEX(iter) (bson_iter_type ((iter)) == BSON_TYPE_REGEX)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_DBPOINTER(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_DBPOINTER)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_CODE(iter) (bson_iter_type ((iter)) == BSON_TYPE_CODE)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_SYMBOL(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_SYMBOL)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_CODEWSCOPE(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_CODEWSCOPE)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_INT32(iter) (bson_iter_type ((iter)) == BSON_TYPE_INT32)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_TIMESTAMP(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_TIMESTAMP)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_INT64(iter) (bson_iter_type ((iter)) == BSON_TYPE_INT64)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_DECIMAL128(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_DECIMAL128)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_MAXKEY(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_MAXKEY)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_MINKEY(iter) \
|
||||||
|
(bson_iter_type ((iter)) == BSON_TYPE_MINKEY)
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_INT(iter) \
|
||||||
|
(BSON_ITER_HOLDS_INT32 (iter) || BSON_ITER_HOLDS_INT64 (iter))
|
||||||
|
|
||||||
|
#define BSON_ITER_HOLDS_NUMBER(iter) \
|
||||||
|
(BSON_ITER_HOLDS_INT (iter) || BSON_ITER_HOLDS_DOUBLE (iter))
|
||||||
|
|
||||||
|
#define BSON_ITER_IS_KEY(iter, key) \
|
||||||
|
(0 == strcmp ((key), bson_iter_key ((iter))))
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (const bson_value_t *)
|
||||||
|
bson_iter_value (bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_utf8_len_unsafe:
|
||||||
|
* @iter: a bson_iter_t.
|
||||||
|
*
|
||||||
|
* Returns the length of a string currently pointed to by @iter. This performs
|
||||||
|
* no validation so the is responsible for knowing the BSON is valid. Calling
|
||||||
|
* bson_validate() is one way to do this ahead of time.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE uint32_t
|
||||||
|
bson_iter_utf8_len_unsafe (const bson_iter_t *iter)
|
||||||
|
{
|
||||||
|
int32_t val;
|
||||||
|
|
||||||
|
memcpy (&val, iter->raw + iter->d1, sizeof (val));
|
||||||
|
val = BSON_UINT32_FROM_LE (val);
|
||||||
|
return BSON_MAX (0, val - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_array (const bson_iter_t *iter,
|
||||||
|
uint32_t *array_len,
|
||||||
|
const uint8_t **array);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_binary (const bson_iter_t *iter,
|
||||||
|
bson_subtype_t *subtype,
|
||||||
|
uint32_t *binary_len,
|
||||||
|
const uint8_t **binary);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (const char *)
|
||||||
|
bson_iter_code (const bson_iter_t *iter, uint32_t *length);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_code_unsafe:
|
||||||
|
* @iter: A bson_iter_t.
|
||||||
|
* @length: A location for the length of the resulting string.
|
||||||
|
*
|
||||||
|
* Like bson_iter_code() but performs no integrity checks.
|
||||||
|
*
|
||||||
|
* Returns: A string that should not be modified or freed.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE const char *
|
||||||
|
bson_iter_code_unsafe (const bson_iter_t *iter, uint32_t *length)
|
||||||
|
{
|
||||||
|
*length = bson_iter_utf8_len_unsafe (iter);
|
||||||
|
return (const char *) (iter->raw + iter->d2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (const char *)
|
||||||
|
bson_iter_codewscope (const bson_iter_t *iter,
|
||||||
|
uint32_t *length,
|
||||||
|
uint32_t *scope_len,
|
||||||
|
const uint8_t **scope);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_dbpointer (const bson_iter_t *iter,
|
||||||
|
uint32_t *collection_len,
|
||||||
|
const char **collection,
|
||||||
|
const bson_oid_t **oid);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_document (const bson_iter_t *iter,
|
||||||
|
uint32_t *document_len,
|
||||||
|
const uint8_t **document);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (double)
|
||||||
|
bson_iter_double (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
BSON_EXPORT (double)
|
||||||
|
bson_iter_as_double (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_double_unsafe:
|
||||||
|
* @iter: A bson_iter_t.
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_double() but does not perform an integrity checking.
|
||||||
|
*
|
||||||
|
* Returns: A double.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE double
|
||||||
|
bson_iter_double_unsafe (const bson_iter_t *iter)
|
||||||
|
{
|
||||||
|
double val;
|
||||||
|
|
||||||
|
memcpy (&val, iter->raw + iter->d1, sizeof (val));
|
||||||
|
return BSON_DOUBLE_FROM_LE (val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_init (bson_iter_t *iter, const bson_t *bson);
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_init_from_data (bson_iter_t *iter,
|
||||||
|
const uint8_t *data,
|
||||||
|
size_t length);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_init_find (bson_iter_t *iter, const bson_t *bson, const char *key);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_init_find_w_len (bson_iter_t *iter,
|
||||||
|
const bson_t *bson,
|
||||||
|
const char *key,
|
||||||
|
int keylen);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_init_find_case (bson_iter_t *iter,
|
||||||
|
const bson_t *bson,
|
||||||
|
const char *key);
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_init_from_data_at_offset (bson_iter_t *iter,
|
||||||
|
const uint8_t *data,
|
||||||
|
size_t length,
|
||||||
|
uint32_t offset,
|
||||||
|
uint32_t keylen);
|
||||||
|
|
||||||
|
BSON_EXPORT (int32_t)
|
||||||
|
bson_iter_int32 (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_int32_unsafe:
|
||||||
|
* @iter: A bson_iter_t.
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_int32() but with no integrity checking.
|
||||||
|
*
|
||||||
|
* Returns: A 32-bit signed integer.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE int32_t
|
||||||
|
bson_iter_int32_unsafe (const bson_iter_t *iter)
|
||||||
|
{
|
||||||
|
int32_t val;
|
||||||
|
|
||||||
|
memcpy (&val, iter->raw + iter->d1, sizeof (val));
|
||||||
|
return BSON_UINT32_FROM_LE (val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (int64_t)
|
||||||
|
bson_iter_int64 (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (int64_t)
|
||||||
|
bson_iter_as_int64 (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_int64_unsafe:
|
||||||
|
* @iter: a bson_iter_t.
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_int64() but without integrity checking.
|
||||||
|
*
|
||||||
|
* Returns: A 64-bit signed integer.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE int64_t
|
||||||
|
bson_iter_int64_unsafe (const bson_iter_t *iter)
|
||||||
|
{
|
||||||
|
int64_t val;
|
||||||
|
|
||||||
|
memcpy (&val, iter->raw + iter->d1, sizeof (val));
|
||||||
|
return BSON_UINT64_FROM_LE (val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_find (bson_iter_t *iter, const char *key);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_find_w_len (bson_iter_t *iter, const char *key, int keylen);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_find_case (bson_iter_t *iter, const char *key);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_find_descendant (bson_iter_t *iter,
|
||||||
|
const char *dotkey,
|
||||||
|
bson_iter_t *descendant);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_next (bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (const bson_oid_t *)
|
||||||
|
bson_iter_oid (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_oid_unsafe:
|
||||||
|
* @iter: A #bson_iter_t.
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_oid() but performs no integrity checks.
|
||||||
|
*
|
||||||
|
* Returns: A #bson_oid_t that should not be modified or freed.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE const bson_oid_t *
|
||||||
|
bson_iter_oid_unsafe (const bson_iter_t *iter)
|
||||||
|
{
|
||||||
|
return (const bson_oid_t *) (iter->raw + iter->d1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_decimal128 (const bson_iter_t *iter, bson_decimal128_t *dec);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_decimal128_unsafe:
|
||||||
|
* @iter: A #bson_iter_t.
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_decimal128() but performs no integrity checks.
|
||||||
|
*
|
||||||
|
* Returns: A #bson_decimal128_t.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE void
|
||||||
|
bson_iter_decimal128_unsafe (const bson_iter_t *iter, bson_decimal128_t *dec)
|
||||||
|
{
|
||||||
|
uint64_t low_le;
|
||||||
|
uint64_t high_le;
|
||||||
|
|
||||||
|
memcpy (&low_le, iter->raw + iter->d1, sizeof (low_le));
|
||||||
|
memcpy (&high_le, iter->raw + iter->d1 + 8, sizeof (high_le));
|
||||||
|
|
||||||
|
dec->low = BSON_UINT64_FROM_LE (low_le);
|
||||||
|
dec->high = BSON_UINT64_FROM_LE (high_le);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (const char *)
|
||||||
|
bson_iter_key (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
BSON_EXPORT (uint32_t)
|
||||||
|
bson_iter_key_len (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_key_unsafe:
|
||||||
|
* @iter: A bson_iter_t.
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_key() but performs no integrity checking.
|
||||||
|
*
|
||||||
|
* Returns: A string that should not be modified or freed.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE const char *
|
||||||
|
bson_iter_key_unsafe (const bson_iter_t *iter)
|
||||||
|
{
|
||||||
|
return (const char *) (iter->raw + iter->key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (const char *)
|
||||||
|
bson_iter_utf8 (const bson_iter_t *iter, uint32_t *length);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_utf8_unsafe:
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_utf8() but performs no integrity checking.
|
||||||
|
*
|
||||||
|
* Returns: A string that should not be modified or freed.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE const char *
|
||||||
|
bson_iter_utf8_unsafe (const bson_iter_t *iter, size_t *length)
|
||||||
|
{
|
||||||
|
*length = bson_iter_utf8_len_unsafe (iter);
|
||||||
|
return (const char *) (iter->raw + iter->d2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (char *)
|
||||||
|
bson_iter_dup_utf8 (const bson_iter_t *iter, uint32_t *length);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (int64_t)
|
||||||
|
bson_iter_date_time (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (time_t)
|
||||||
|
bson_iter_time_t (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_time_t_unsafe:
|
||||||
|
* @iter: A bson_iter_t.
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_time_t() but performs no integrity checking.
|
||||||
|
*
|
||||||
|
* Returns: A time_t containing the number of seconds since UNIX epoch
|
||||||
|
* in UTC.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE time_t
|
||||||
|
bson_iter_time_t_unsafe (const bson_iter_t *iter)
|
||||||
|
{
|
||||||
|
return (time_t) (bson_iter_int64_unsafe (iter) / 1000UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_timeval (const bson_iter_t *iter, struct timeval *tv);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_timeval_unsafe:
|
||||||
|
* @iter: A bson_iter_t.
|
||||||
|
* @tv: A struct timeval.
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_timeval() but performs no integrity checking.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE void
|
||||||
|
bson_iter_timeval_unsafe (const bson_iter_t *iter, struct timeval *tv)
|
||||||
|
{
|
||||||
|
int64_t value = bson_iter_int64_unsafe (iter);
|
||||||
|
#ifdef BSON_OS_WIN32
|
||||||
|
tv->tv_sec = (long) (value / 1000);
|
||||||
|
#else
|
||||||
|
tv->tv_sec = (suseconds_t) (value / 1000);
|
||||||
|
#endif
|
||||||
|
tv->tv_usec = (value % 1000) * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_timestamp (const bson_iter_t *iter,
|
||||||
|
uint32_t *timestamp,
|
||||||
|
uint32_t *increment);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_bool (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_bool_unsafe:
|
||||||
|
* @iter: A bson_iter_t.
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_bool() but performs no integrity checking.
|
||||||
|
*
|
||||||
|
* Returns: true or false.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE bool
|
||||||
|
bson_iter_bool_unsafe (const bson_iter_t *iter)
|
||||||
|
{
|
||||||
|
char val;
|
||||||
|
|
||||||
|
memcpy (&val, iter->raw + iter->d1, 1);
|
||||||
|
return !!val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_as_bool (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (const char *)
|
||||||
|
bson_iter_regex (const bson_iter_t *iter, const char **options);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (const char *)
|
||||||
|
bson_iter_symbol (const bson_iter_t *iter, uint32_t *length);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bson_type_t)
|
||||||
|
bson_iter_type (const bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_type_unsafe:
|
||||||
|
* @iter: A bson_iter_t.
|
||||||
|
*
|
||||||
|
* Similar to bson_iter_type() but performs no integrity checking.
|
||||||
|
*
|
||||||
|
* Returns: A bson_type_t.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE bson_type_t
|
||||||
|
bson_iter_type_unsafe (const bson_iter_t *iter)
|
||||||
|
{
|
||||||
|
return (bson_type_t) (iter->raw + iter->type)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_recurse (const bson_iter_t *iter, bson_iter_t *child);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_overwrite_int32 (bson_iter_t *iter, int32_t value);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_overwrite_int64 (bson_iter_t *iter, int64_t value);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_overwrite_double (bson_iter_t *iter, double value);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_overwrite_decimal128 (bson_iter_t *iter, bson_decimal128_t *value);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_overwrite_bool (bson_iter_t *iter, bool value);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_overwrite_oid (bson_iter_t *iter, const bson_oid_t *value);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_overwrite_timestamp (bson_iter_t *iter,
|
||||||
|
uint32_t timestamp,
|
||||||
|
uint32_t increment);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_iter_overwrite_date_time (bson_iter_t *iter, int64_t value);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_iter_visit_all (bson_iter_t *iter,
|
||||||
|
const bson_visitor_t *visitor,
|
||||||
|
void *data);
|
||||||
|
|
||||||
|
BSON_EXPORT (uint32_t)
|
||||||
|
bson_iter_offset (bson_iter_t *iter);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_ITER_H */
|
||||||
73
include/libbson-1.0/bson/bson-json.h
Normal file
73
include/libbson-1.0/bson/bson-json.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_JSON_H
|
||||||
|
#define BSON_JSON_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _bson_json_reader_t bson_json_reader_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BSON_JSON_ERROR_READ_CORRUPT_JS = 1,
|
||||||
|
BSON_JSON_ERROR_READ_INVALID_PARAM,
|
||||||
|
BSON_JSON_ERROR_READ_CB_FAILURE,
|
||||||
|
} bson_json_error_code_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef ssize_t (*bson_json_reader_cb) (void *handle,
|
||||||
|
uint8_t *buf,
|
||||||
|
size_t count);
|
||||||
|
typedef void (*bson_json_destroy_cb) (void *handle);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bson_json_reader_t *)
|
||||||
|
bson_json_reader_new (void *data,
|
||||||
|
bson_json_reader_cb cb,
|
||||||
|
bson_json_destroy_cb dcb,
|
||||||
|
bool allow_multiple,
|
||||||
|
size_t buf_size);
|
||||||
|
BSON_EXPORT (bson_json_reader_t *)
|
||||||
|
bson_json_reader_new_from_fd (int fd, bool close_on_destroy);
|
||||||
|
BSON_EXPORT (bson_json_reader_t *)
|
||||||
|
bson_json_reader_new_from_file (const char *filename, bson_error_t *error);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_json_reader_destroy (bson_json_reader_t *reader);
|
||||||
|
BSON_EXPORT (int)
|
||||||
|
bson_json_reader_read (bson_json_reader_t *reader,
|
||||||
|
bson_t *bson,
|
||||||
|
bson_error_t *error);
|
||||||
|
BSON_EXPORT (bson_json_reader_t *)
|
||||||
|
bson_json_data_reader_new (bool allow_multiple, size_t size);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_json_data_reader_ingest (bson_json_reader_t *reader,
|
||||||
|
const uint8_t *data,
|
||||||
|
size_t len);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_JSON_H */
|
||||||
41
include/libbson-1.0/bson/bson-keys.h
Normal file
41
include/libbson-1.0/bson/bson-keys.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_KEYS_H
|
||||||
|
#define BSON_KEYS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (size_t)
|
||||||
|
bson_uint32_to_string (uint32_t value,
|
||||||
|
const char **strptr,
|
||||||
|
char *str,
|
||||||
|
size_t size);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_KEYS_H */
|
||||||
293
include/libbson-1.0/bson/bson-macros.h
Normal file
293
include/libbson-1.0/bson/bson-macros.h
Normal file
@ -0,0 +1,293 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_MACROS_H
|
||||||
|
#define BSON_MACROS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include <algorithm>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "bson/bson-config.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if BSON_OS == 1
|
||||||
|
#define BSON_OS_UNIX
|
||||||
|
#elif BSON_OS == 2
|
||||||
|
#define BSON_OS_WIN32
|
||||||
|
#else
|
||||||
|
#error "Unknown operating system."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#define BSON_BEGIN_DECLS extern "C" {
|
||||||
|
#define BSON_END_DECLS }
|
||||||
|
#else
|
||||||
|
#define BSON_BEGIN_DECLS
|
||||||
|
#define BSON_END_DECLS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define BSON_GNUC_CHECK_VERSION(major, minor) \
|
||||||
|
((__GNUC__ > (major)) || \
|
||||||
|
((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor))))
|
||||||
|
#else
|
||||||
|
#define BSON_GNUC_CHECK_VERSION(major, minor) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define BSON_GNUC_IS_VERSION(major, minor) \
|
||||||
|
((__GNUC__ == (major)) && (__GNUC_MINOR__ == (minor)))
|
||||||
|
#else
|
||||||
|
#define BSON_GNUC_IS_VERSION(major, minor) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Decorate public functions:
|
||||||
|
* - if BSON_STATIC, we're compiling a program that uses libbson as a static
|
||||||
|
* library, don't decorate functions
|
||||||
|
* - else if BSON_COMPILATION, we're compiling a static or shared libbson, mark
|
||||||
|
* public functions for export from the shared lib (which has no effect on
|
||||||
|
* the static lib)
|
||||||
|
* - else, we're compiling a program that uses libbson as a shared library,
|
||||||
|
* mark public functions as DLL imports for Microsoft Visual C
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
/*
|
||||||
|
* Microsoft Visual C
|
||||||
|
*/
|
||||||
|
#ifdef BSON_STATIC
|
||||||
|
#define BSON_API
|
||||||
|
#elif defined(BSON_COMPILATION)
|
||||||
|
#define BSON_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define BSON_API __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#define BSON_CALL __cdecl
|
||||||
|
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
/*
|
||||||
|
* GCC
|
||||||
|
*/
|
||||||
|
#ifdef BSON_STATIC
|
||||||
|
#define BSON_API
|
||||||
|
#elif defined(BSON_COMPILATION)
|
||||||
|
#define BSON_API __attribute__ ((visibility ("default")))
|
||||||
|
#else
|
||||||
|
#define BSON_API
|
||||||
|
#endif
|
||||||
|
#define BSON_CALL
|
||||||
|
|
||||||
|
#else
|
||||||
|
/*
|
||||||
|
* Other compilers
|
||||||
|
*/
|
||||||
|
#define BSON_API
|
||||||
|
#define BSON_CALL
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BSON_EXPORT(type) BSON_API type BSON_CALL
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MIN
|
||||||
|
#define BSON_MIN MIN
|
||||||
|
#elif defined(__cplusplus)
|
||||||
|
#define BSON_MIN(a, b) ((std::min) (a, b))
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#define BSON_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
#else
|
||||||
|
#define BSON_MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MAX
|
||||||
|
#define BSON_MAX MAX
|
||||||
|
#elif defined(__cplusplus)
|
||||||
|
#define BSON_MAX(a, b) ((std::max) (a, b))
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#define BSON_MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
#else
|
||||||
|
#define BSON_MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ABS
|
||||||
|
#define BSON_ABS ABS
|
||||||
|
#else
|
||||||
|
#define BSON_ABS(a) (((a) < 0) ? ((a) * -1) : (a))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#ifdef _WIN64
|
||||||
|
#define BSON_ALIGN_OF_PTR 8
|
||||||
|
#else
|
||||||
|
#define BSON_ALIGN_OF_PTR 4
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define BSON_ALIGN_OF_PTR (sizeof (void *))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BSON_EXTRA_ALIGN
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define BSON_ALIGNED_BEGIN(_N) __declspec(align (_N))
|
||||||
|
#define BSON_ALIGNED_END(_N)
|
||||||
|
#else
|
||||||
|
#define BSON_ALIGNED_BEGIN(_N)
|
||||||
|
#define BSON_ALIGNED_END(_N) __attribute__ ((aligned (_N)))
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define BSON_ALIGNED_BEGIN(_N) __declspec(align (BSON_ALIGN_OF_PTR))
|
||||||
|
#define BSON_ALIGNED_END(_N)
|
||||||
|
#else
|
||||||
|
#define BSON_ALIGNED_BEGIN(_N)
|
||||||
|
#define BSON_ALIGNED_END(_N) \
|
||||||
|
__attribute__ ( \
|
||||||
|
(aligned ((_N) > BSON_ALIGN_OF_PTR ? BSON_ALIGN_OF_PTR : (_N))))
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define bson_str_empty(s) (!s[0])
|
||||||
|
#define bson_str_empty0(s) (!s || !s[0])
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#define BSON_FUNC __FUNCTION__
|
||||||
|
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L
|
||||||
|
#define BSON_FUNC __FUNCTION__
|
||||||
|
#else
|
||||||
|
#define BSON_FUNC __func__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BSON_ASSERT(test) \
|
||||||
|
do { \
|
||||||
|
if (!(BSON_LIKELY (test))) { \
|
||||||
|
fprintf (stderr, \
|
||||||
|
"%s:%d %s(): precondition failed: %s\n", \
|
||||||
|
__FILE__, \
|
||||||
|
__LINE__, \
|
||||||
|
BSON_FUNC, \
|
||||||
|
#test); \
|
||||||
|
abort (); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* obsolete macros, preserved for compatibility */
|
||||||
|
#define BSON_STATIC_ASSERT(s) BSON_STATIC_ASSERT_ (s, __LINE__)
|
||||||
|
#define BSON_STATIC_ASSERT_JOIN(a, b) BSON_STATIC_ASSERT_JOIN2 (a, b)
|
||||||
|
#define BSON_STATIC_ASSERT_JOIN2(a, b) a##b
|
||||||
|
#define BSON_STATIC_ASSERT_(s, l) \
|
||||||
|
typedef char BSON_STATIC_ASSERT_JOIN (static_assert_test_, \
|
||||||
|
__LINE__)[(s) ? 1 : -1]
|
||||||
|
|
||||||
|
/* modern macros */
|
||||||
|
#define BSON_STATIC_ASSERT2(_name, _s) \
|
||||||
|
BSON_STATIC_ASSERT2_ (_s, __LINE__, _name)
|
||||||
|
#define BSON_STATIC_ASSERT_JOIN3(_a, _b, _name) \
|
||||||
|
BSON_STATIC_ASSERT_JOIN4 (_a, _b, _name)
|
||||||
|
#define BSON_STATIC_ASSERT_JOIN4(_a, _b, _name) _a##_b##_name
|
||||||
|
#define BSON_STATIC_ASSERT2_(_s, _l, _name) \
|
||||||
|
typedef char BSON_STATIC_ASSERT_JOIN3 ( \
|
||||||
|
static_assert_test_, __LINE__, _name)[(_s) ? 1 : -1]
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define BSON_GNUC_PURE __attribute__ ((pure))
|
||||||
|
#define BSON_GNUC_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
|
||||||
|
#else
|
||||||
|
#define BSON_GNUC_PURE
|
||||||
|
#define BSON_GNUC_WARN_UNUSED_RESULT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if BSON_GNUC_CHECK_VERSION(4, 0) && !defined(_WIN32)
|
||||||
|
#define BSON_GNUC_NULL_TERMINATED __attribute__ ((sentinel))
|
||||||
|
#define BSON_GNUC_INTERNAL __attribute__ ((visibility ("hidden")))
|
||||||
|
#else
|
||||||
|
#define BSON_GNUC_NULL_TERMINATED
|
||||||
|
#define BSON_GNUC_INTERNAL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define BSON_LIKELY(x) __builtin_expect (!!(x), 1)
|
||||||
|
#define BSON_UNLIKELY(x) __builtin_expect (!!(x), 0)
|
||||||
|
#else
|
||||||
|
#define BSON_LIKELY(v) v
|
||||||
|
#define BSON_UNLIKELY(v) v
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
#define BSON_GNUC_PRINTF(f, v) __attribute__ ((format (printf, f, v)))
|
||||||
|
#elif BSON_GNUC_CHECK_VERSION(4, 4)
|
||||||
|
#define BSON_GNUC_PRINTF(f, v) __attribute__ ((format (gnu_printf, f, v)))
|
||||||
|
#else
|
||||||
|
#define BSON_GNUC_PRINTF(f, v)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(__LP64__) || defined(_LP64)
|
||||||
|
#define BSON_WORD_SIZE 64
|
||||||
|
#else
|
||||||
|
#define BSON_WORD_SIZE 32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#define BSON_INLINE __inline
|
||||||
|
#else
|
||||||
|
#define BSON_INLINE __inline__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define BSON_ENSURE_ARRAY_PARAM_SIZE(_n)
|
||||||
|
#define BSON_TYPEOF decltype
|
||||||
|
#else
|
||||||
|
#define BSON_ENSURE_ARRAY_PARAM_SIZE(_n) static(_n)
|
||||||
|
#define BSON_TYPEOF typeof
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if BSON_GNUC_CHECK_VERSION(3, 1)
|
||||||
|
#define BSON_GNUC_DEPRECATED __attribute__ ((__deprecated__))
|
||||||
|
#else
|
||||||
|
#define BSON_GNUC_DEPRECATED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if BSON_GNUC_CHECK_VERSION(4, 5)
|
||||||
|
#define BSON_GNUC_DEPRECATED_FOR(f) \
|
||||||
|
__attribute__ ((deprecated ("Use " #f " instead")))
|
||||||
|
#else
|
||||||
|
#define BSON_GNUC_DEPRECATED_FOR(f) BSON_GNUC_DEPRECATED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_MACROS_H */
|
||||||
89
include/libbson-1.0/bson/bson-md5.h
Normal file
89
include/libbson-1.0/bson/bson-md5.h
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgement in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
|
||||||
|
L. Peter Deutsch
|
||||||
|
ghost@aladdin.com
|
||||||
|
|
||||||
|
*/
|
||||||
|
/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
|
||||||
|
/*
|
||||||
|
Independent implementation of MD5 (RFC 1321).
|
||||||
|
|
||||||
|
This code implements the MD5 Algorithm defined in RFC 1321, whose
|
||||||
|
text is available at
|
||||||
|
http://www.ietf.org/rfc/rfc1321.txt
|
||||||
|
The code is derived from the text of the RFC, including the test suite
|
||||||
|
(section A.5) but excluding the rest of Appendix A. It does not include
|
||||||
|
any code or documentation that is identified in the RFC as being
|
||||||
|
copyrighted.
|
||||||
|
|
||||||
|
The original and principal author of md5.h is L. Peter Deutsch
|
||||||
|
<ghost@aladdin.com>. Other authors are noted in the change history
|
||||||
|
that follows (in reverse chronological order):
|
||||||
|
|
||||||
|
2002-04-13 lpd Removed support for non-ANSI compilers; removed
|
||||||
|
references to Ghostscript; clarified derivation from RFC 1321;
|
||||||
|
now handles byte order either statically or dynamically.
|
||||||
|
1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
|
||||||
|
1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
|
||||||
|
added conditionalization for C++ compilation from Martin
|
||||||
|
Purschke <purschke@bnl.gov>.
|
||||||
|
1999-05-03 lpd Original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The following MD5 implementation has been modified to use types as
|
||||||
|
* specified in libbson.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_MD5_H
|
||||||
|
#define BSON_MD5_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-endian.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t count[2]; /* message length in bits, lsw first */
|
||||||
|
uint32_t abcd[4]; /* digest buffer */
|
||||||
|
uint8_t buf[64]; /* accumulate block */
|
||||||
|
} bson_md5_t;
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_md5_init (bson_md5_t *pms) BSON_GNUC_DEPRECATED;
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_md5_append (bson_md5_t *pms,
|
||||||
|
const uint8_t *data,
|
||||||
|
uint32_t nbytes) BSON_GNUC_DEPRECATED;
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_md5_finish (bson_md5_t *pms, uint8_t digest[16]) BSON_GNUC_DEPRECATED;
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_MD5_H */
|
||||||
64
include/libbson-1.0/bson/bson-memory.h
Normal file
64
include/libbson-1.0/bson/bson-memory.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_MEMORY_H
|
||||||
|
#define BSON_MEMORY_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
typedef void *(*bson_realloc_func) (void *mem, size_t num_bytes, void *ctx);
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _bson_mem_vtable_t {
|
||||||
|
void *(*malloc) (size_t num_bytes);
|
||||||
|
void *(*calloc) (size_t n_members, size_t num_bytes);
|
||||||
|
void *(*realloc) (void *mem, size_t num_bytes);
|
||||||
|
void (*free) (void *mem);
|
||||||
|
void *padding[4];
|
||||||
|
} bson_mem_vtable_t;
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_mem_set_vtable (const bson_mem_vtable_t *vtable);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_mem_restore_vtable (void);
|
||||||
|
BSON_EXPORT (void *)
|
||||||
|
bson_malloc (size_t num_bytes);
|
||||||
|
BSON_EXPORT (void *)
|
||||||
|
bson_malloc0 (size_t num_bytes);
|
||||||
|
BSON_EXPORT (void *)
|
||||||
|
bson_realloc (void *mem, size_t num_bytes);
|
||||||
|
BSON_EXPORT (void *)
|
||||||
|
bson_realloc_ctx (void *mem, size_t num_bytes, void *ctx);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_free (void *mem);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_zero_free (void *mem, size_t size);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_MEMORY_H */
|
||||||
244
include/libbson-1.0/bson/bson-oid.h
Normal file
244
include/libbson-1.0/bson/bson-oid.h
Normal file
@ -0,0 +1,244 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_OID_H
|
||||||
|
#define BSON_OID_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "bson/bson-context.h"
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
#include "bson/bson-endian.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (int)
|
||||||
|
bson_oid_compare (const bson_oid_t *oid1, const bson_oid_t *oid2);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_oid_copy (const bson_oid_t *src, bson_oid_t *dst);
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_oid_equal (const bson_oid_t *oid1, const bson_oid_t *oid2);
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_oid_is_valid (const char *str, size_t length);
|
||||||
|
BSON_EXPORT (time_t)
|
||||||
|
bson_oid_get_time_t (const bson_oid_t *oid);
|
||||||
|
BSON_EXPORT (uint32_t)
|
||||||
|
bson_oid_hash (const bson_oid_t *oid);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_oid_init (bson_oid_t *oid, bson_context_t *context);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_oid_init_from_data (bson_oid_t *oid, const uint8_t *data);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_oid_init_from_string (bson_oid_t *oid, const char *str);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_oid_init_sequence (bson_oid_t *oid,
|
||||||
|
bson_context_t *context) BSON_GNUC_DEPRECATED;
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_oid_to_string (const bson_oid_t *oid, char str[25]);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_oid_compare_unsafe:
|
||||||
|
* @oid1: A bson_oid_t.
|
||||||
|
* @oid2: A bson_oid_t.
|
||||||
|
*
|
||||||
|
* Performs a qsort() style comparison between @oid1 and @oid2.
|
||||||
|
*
|
||||||
|
* This function is meant to be as fast as possible and therefore performs
|
||||||
|
* no argument validation. That is the callers responsibility.
|
||||||
|
*
|
||||||
|
* Returns: An integer < 0 if @oid1 is less than @oid2. Zero if they are equal.
|
||||||
|
* An integer > 0 if @oid1 is greater than @oid2.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE int
|
||||||
|
bson_oid_compare_unsafe (const bson_oid_t *oid1, const bson_oid_t *oid2)
|
||||||
|
{
|
||||||
|
return memcmp (oid1, oid2, sizeof *oid1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_oid_equal_unsafe:
|
||||||
|
* @oid1: A bson_oid_t.
|
||||||
|
* @oid2: A bson_oid_t.
|
||||||
|
*
|
||||||
|
* Checks the equality of @oid1 and @oid2.
|
||||||
|
*
|
||||||
|
* This function is meant to be as fast as possible and therefore performs
|
||||||
|
* no checks for argument validity. That is the callers responsibility.
|
||||||
|
*
|
||||||
|
* Returns: true if @oid1 and @oid2 are equal; otherwise false.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE bool
|
||||||
|
bson_oid_equal_unsafe (const bson_oid_t *oid1, const bson_oid_t *oid2)
|
||||||
|
{
|
||||||
|
return !memcmp (oid1, oid2, sizeof *oid1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_oid_hash_unsafe:
|
||||||
|
* @oid: A bson_oid_t.
|
||||||
|
*
|
||||||
|
* This function performs a DJB style hash upon the bytes contained in @oid.
|
||||||
|
* The result is a hash key suitable for use in a hashtable.
|
||||||
|
*
|
||||||
|
* This function is meant to be as fast as possible and therefore performs no
|
||||||
|
* validation of arguments. The caller is responsible to ensure they are
|
||||||
|
* passing valid arguments.
|
||||||
|
*
|
||||||
|
* Returns: A uint32_t containing a hash code.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE uint32_t
|
||||||
|
bson_oid_hash_unsafe (const bson_oid_t *oid)
|
||||||
|
{
|
||||||
|
uint32_t hash = 5381;
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof oid->bytes; i++) {
|
||||||
|
hash = ((hash << 5) + hash) + oid->bytes[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_oid_copy_unsafe:
|
||||||
|
* @src: A bson_oid_t to copy from.
|
||||||
|
* @dst: A bson_oid_t to copy into.
|
||||||
|
*
|
||||||
|
* Copies the contents of @src into @dst. This function is meant to be as
|
||||||
|
* fast as possible and therefore performs no argument checking. It is the
|
||||||
|
* callers responsibility to ensure they are passing valid data into the
|
||||||
|
* function.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE void
|
||||||
|
bson_oid_copy_unsafe (const bson_oid_t *src, bson_oid_t *dst)
|
||||||
|
{
|
||||||
|
memcpy (dst, src, sizeof *src);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_oid_parse_hex_char:
|
||||||
|
* @hex: A character to parse to its integer value.
|
||||||
|
*
|
||||||
|
* This function contains a jump table to return the integer value for a
|
||||||
|
* character containing a hexadecimal value (0-9, a-f, A-F). If the character
|
||||||
|
* is not a hexadecimal character then zero is returned.
|
||||||
|
*
|
||||||
|
* Returns: An integer between 0 and 15.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE uint8_t
|
||||||
|
bson_oid_parse_hex_char (char hex)
|
||||||
|
{
|
||||||
|
switch (hex) {
|
||||||
|
case '0':
|
||||||
|
return 0;
|
||||||
|
case '1':
|
||||||
|
return 1;
|
||||||
|
case '2':
|
||||||
|
return 2;
|
||||||
|
case '3':
|
||||||
|
return 3;
|
||||||
|
case '4':
|
||||||
|
return 4;
|
||||||
|
case '5':
|
||||||
|
return 5;
|
||||||
|
case '6':
|
||||||
|
return 6;
|
||||||
|
case '7':
|
||||||
|
return 7;
|
||||||
|
case '8':
|
||||||
|
return 8;
|
||||||
|
case '9':
|
||||||
|
return 9;
|
||||||
|
case 'a':
|
||||||
|
case 'A':
|
||||||
|
return 0xa;
|
||||||
|
case 'b':
|
||||||
|
case 'B':
|
||||||
|
return 0xb;
|
||||||
|
case 'c':
|
||||||
|
case 'C':
|
||||||
|
return 0xc;
|
||||||
|
case 'd':
|
||||||
|
case 'D':
|
||||||
|
return 0xd;
|
||||||
|
case 'e':
|
||||||
|
case 'E':
|
||||||
|
return 0xe;
|
||||||
|
case 'f':
|
||||||
|
case 'F':
|
||||||
|
return 0xf;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_oid_init_from_string_unsafe:
|
||||||
|
* @oid: A bson_oid_t to store the result.
|
||||||
|
* @str: A 24-character hexadecimal encoded string.
|
||||||
|
*
|
||||||
|
* Parses a string containing 24 hexadecimal encoded bytes into a bson_oid_t.
|
||||||
|
* This function is meant to be as fast as possible and inlined into your
|
||||||
|
* code. For that purpose, the function does not perform any sort of bounds
|
||||||
|
* checking and it is the callers responsibility to ensure they are passing
|
||||||
|
* valid input to the function.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE void
|
||||||
|
bson_oid_init_from_string_unsafe (bson_oid_t *oid, const char *str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < 12; i++) {
|
||||||
|
oid->bytes[i] = ((bson_oid_parse_hex_char (str[2 * i]) << 4) |
|
||||||
|
(bson_oid_parse_hex_char (str[2 * i + 1])));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_oid_get_time_t_unsafe:
|
||||||
|
* @oid: A bson_oid_t.
|
||||||
|
*
|
||||||
|
* Fetches the time @oid was generated.
|
||||||
|
*
|
||||||
|
* Returns: A time_t containing the UNIX timestamp of generation.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE time_t
|
||||||
|
bson_oid_get_time_t_unsafe (const bson_oid_t *oid)
|
||||||
|
{
|
||||||
|
uint32_t t;
|
||||||
|
|
||||||
|
memcpy (&t, oid, sizeof (t));
|
||||||
|
return BSON_UINT32_FROM_BE (t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_OID_H */
|
||||||
19
include/libbson-1.0/bson/bson-prelude.h
Normal file
19
include/libbson-1.0/bson/bson-prelude.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-present MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(BSON_INSIDE) && !defined(BSON_COMPILATION)
|
||||||
|
#error "Only <bson/bson.h> can be included directly."
|
||||||
|
#endif
|
||||||
117
include/libbson-1.0/bson/bson-reader.h
Normal file
117
include/libbson-1.0/bson/bson-reader.h
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_READER_H
|
||||||
|
#define BSON_READER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-compat.h"
|
||||||
|
#include "bson/bson-oid.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#define BSON_ERROR_READER_BADFD 1
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* bson_reader_read_func_t --
|
||||||
|
*
|
||||||
|
* This function is a callback used by bson_reader_t to read the
|
||||||
|
* next chunk of data from the underlying opaque file descriptor.
|
||||||
|
*
|
||||||
|
* This function is meant to operate similar to the read() function
|
||||||
|
* as part of libc on UNIX-like systems.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* @handle: The handle to read from.
|
||||||
|
* @buf: The buffer to read into.
|
||||||
|
* @count: The number of bytes to read.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* 0 for end of stream.
|
||||||
|
* -1 for read failure.
|
||||||
|
* Greater than zero for number of bytes read into @buf.
|
||||||
|
*
|
||||||
|
* Side effects:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef ssize_t (*bson_reader_read_func_t) (void *handle, /* IN */
|
||||||
|
void *buf, /* IN */
|
||||||
|
size_t count); /* IN */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* bson_reader_destroy_func_t --
|
||||||
|
*
|
||||||
|
* Destroy callback to release any resources associated with the
|
||||||
|
* opaque handle.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* @handle: the handle provided to bson_reader_new_from_handle().
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
* Side effects:
|
||||||
|
* None.
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef void (*bson_reader_destroy_func_t) (void *handle); /* IN */
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bson_reader_t *)
|
||||||
|
bson_reader_new_from_handle (void *handle,
|
||||||
|
bson_reader_read_func_t rf,
|
||||||
|
bson_reader_destroy_func_t df);
|
||||||
|
BSON_EXPORT (bson_reader_t *)
|
||||||
|
bson_reader_new_from_fd (int fd, bool close_on_destroy);
|
||||||
|
BSON_EXPORT (bson_reader_t *)
|
||||||
|
bson_reader_new_from_file (const char *path, bson_error_t *error);
|
||||||
|
BSON_EXPORT (bson_reader_t *)
|
||||||
|
bson_reader_new_from_data (const uint8_t *data, size_t length);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_reader_destroy (bson_reader_t *reader);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_reader_set_read_func (bson_reader_t *reader, bson_reader_read_func_t func);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_reader_set_destroy_func (bson_reader_t *reader,
|
||||||
|
bson_reader_destroy_func_t func);
|
||||||
|
BSON_EXPORT (const bson_t *)
|
||||||
|
bson_reader_read (bson_reader_t *reader, bool *reached_eof);
|
||||||
|
BSON_EXPORT (off_t)
|
||||||
|
bson_reader_tell (bson_reader_t *reader);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_reader_reset (bson_reader_t *reader);
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_READER_H */
|
||||||
84
include/libbson-1.0/bson/bson-string.h
Normal file
84
include/libbson-1.0/bson/bson-string.h
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_STRING_H
|
||||||
|
#define BSON_STRING_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *str;
|
||||||
|
uint32_t len;
|
||||||
|
uint32_t alloc;
|
||||||
|
} bson_string_t;
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bson_string_t *)
|
||||||
|
bson_string_new (const char *str);
|
||||||
|
BSON_EXPORT (char *)
|
||||||
|
bson_string_free (bson_string_t *string, bool free_segment);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_string_append (bson_string_t *string, const char *str);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_string_append_c (bson_string_t *string, char str);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_string_append_unichar (bson_string_t *string, bson_unichar_t unichar);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_string_append_printf (bson_string_t *string, const char *format, ...)
|
||||||
|
BSON_GNUC_PRINTF (2, 3);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_string_truncate (bson_string_t *string, uint32_t len);
|
||||||
|
BSON_EXPORT (char *)
|
||||||
|
bson_strdup (const char *str);
|
||||||
|
BSON_EXPORT (char *)
|
||||||
|
bson_strdup_printf (const char *format, ...) BSON_GNUC_PRINTF (1, 2);
|
||||||
|
BSON_EXPORT (char *)
|
||||||
|
bson_strdupv_printf (const char *format, va_list args) BSON_GNUC_PRINTF (1, 0);
|
||||||
|
BSON_EXPORT (char *)
|
||||||
|
bson_strndup (const char *str, size_t n_bytes);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_strncpy (char *dst, const char *src, size_t size);
|
||||||
|
BSON_EXPORT (int)
|
||||||
|
bson_vsnprintf (char *str, size_t size, const char *format, va_list ap)
|
||||||
|
BSON_GNUC_PRINTF (3, 0);
|
||||||
|
BSON_EXPORT (int)
|
||||||
|
bson_snprintf (char *str, size_t size, const char *format, ...)
|
||||||
|
BSON_GNUC_PRINTF (3, 4);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_strfreev (char **strv);
|
||||||
|
BSON_EXPORT (size_t)
|
||||||
|
bson_strnlen (const char *s, size_t maxlen);
|
||||||
|
BSON_EXPORT (int64_t)
|
||||||
|
bson_ascii_strtoll (const char *str, char **endptr, int base);
|
||||||
|
BSON_EXPORT (int)
|
||||||
|
bson_strcasecmp (const char *s1, const char *s2);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_STRING_H */
|
||||||
564
include/libbson-1.0/bson/bson-types.h
Normal file
564
include/libbson-1.0/bson/bson-types.h
Normal file
@ -0,0 +1,564 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_TYPES_H
|
||||||
|
#define BSON_TYPES_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-config.h"
|
||||||
|
#include "bson/bson-compat.h"
|
||||||
|
#include "bson/bson-endian.h"
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* bson_unichar_t --
|
||||||
|
*
|
||||||
|
* bson_unichar_t provides an unsigned 32-bit type for containing
|
||||||
|
* unicode characters. When iterating UTF-8 sequences, this should
|
||||||
|
* be used to avoid losing the high-bits of non-ascii characters.
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* bson_string_append_unichar()
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef uint32_t bson_unichar_t;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_context_flags_t:
|
||||||
|
*
|
||||||
|
* This enumeration is used to configure a bson_context_t.
|
||||||
|
*
|
||||||
|
* %BSON_CONTEXT_NONE: Use default options.
|
||||||
|
* %BSON_CONTEXT_THREAD_SAFE: Context will be called from multiple threads.
|
||||||
|
* %BSON_CONTEXT_DISABLE_PID_CACHE: Call getpid() instead of caching the
|
||||||
|
* result of getpid() when initializing the context.
|
||||||
|
* %BSON_CONTEXT_DISABLE_HOST_CACHE: Call gethostname() instead of caching the
|
||||||
|
* result of gethostname() when initializing the context.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
BSON_CONTEXT_NONE = 0,
|
||||||
|
BSON_CONTEXT_THREAD_SAFE = (1 << 0),
|
||||||
|
BSON_CONTEXT_DISABLE_HOST_CACHE = (1 << 1),
|
||||||
|
BSON_CONTEXT_DISABLE_PID_CACHE = (1 << 2),
|
||||||
|
#ifdef BSON_HAVE_SYSCALL_TID
|
||||||
|
BSON_CONTEXT_USE_TASK_ID = (1 << 3),
|
||||||
|
#endif
|
||||||
|
} bson_context_flags_t;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_context_t:
|
||||||
|
*
|
||||||
|
* This structure manages context for the bson library. It handles
|
||||||
|
* configuration for thread-safety and other performance related requirements.
|
||||||
|
* Consumers will create a context and may use multiple under a variety of
|
||||||
|
* situations.
|
||||||
|
*
|
||||||
|
* If your program calls fork(), you should initialize a new bson_context_t
|
||||||
|
* using bson_context_init().
|
||||||
|
*
|
||||||
|
* If you are using threading, it is suggested that you use a bson_context_t
|
||||||
|
* per thread for best performance. Alternatively, you can initialize the
|
||||||
|
* bson_context_t with BSON_CONTEXT_THREAD_SAFE, although a performance penalty
|
||||||
|
* will be incurred.
|
||||||
|
*
|
||||||
|
* Many functions will require that you provide a bson_context_t such as OID
|
||||||
|
* generation.
|
||||||
|
*
|
||||||
|
* This structure is opaque in that you cannot see the contents of the
|
||||||
|
* structure. However, it is stack allocatable in that enough padding is
|
||||||
|
* provided in _bson_context_t to hold the structure.
|
||||||
|
*/
|
||||||
|
typedef struct _bson_context_t bson_context_t;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_t:
|
||||||
|
*
|
||||||
|
* This structure manages a buffer whose contents are a properly formatted
|
||||||
|
* BSON document. You may perform various transforms on the BSON documents.
|
||||||
|
* Additionally, it can be iterated over using bson_iter_t.
|
||||||
|
*
|
||||||
|
* See bson_iter_init() for iterating the contents of a bson_t.
|
||||||
|
*
|
||||||
|
* When building a bson_t structure using the various append functions,
|
||||||
|
* memory allocations may occur. That is performed using power of two
|
||||||
|
* allocations and realloc().
|
||||||
|
*
|
||||||
|
* See http://bsonspec.org for the BSON document spec.
|
||||||
|
*
|
||||||
|
* This structure is meant to fit in two sequential 64-byte cachelines.
|
||||||
|
*/
|
||||||
|
#ifdef BSON_MEMCHECK
|
||||||
|
BSON_ALIGNED_BEGIN (128)
|
||||||
|
typedef struct _bson_t {
|
||||||
|
uint32_t flags; /* Internal flags for the bson_t. */
|
||||||
|
uint32_t len; /* Length of BSON data. */
|
||||||
|
char *canary; /* For valgrind check */
|
||||||
|
uint8_t padding[120 - sizeof (char*)];
|
||||||
|
} bson_t BSON_ALIGNED_END (128);
|
||||||
|
#else
|
||||||
|
BSON_ALIGNED_BEGIN (128)
|
||||||
|
typedef struct _bson_t {
|
||||||
|
uint32_t flags; /* Internal flags for the bson_t. */
|
||||||
|
uint32_t len; /* Length of BSON data. */
|
||||||
|
uint8_t padding[120]; /* Padding for stack allocation. */
|
||||||
|
} bson_t BSON_ALIGNED_END (128);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSON_INITIALIZER:
|
||||||
|
*
|
||||||
|
* This macro can be used to initialize a #bson_t structure on the stack
|
||||||
|
* without calling bson_init().
|
||||||
|
*
|
||||||
|
* |[
|
||||||
|
* bson_t b = BSON_INITIALIZER;
|
||||||
|
* ]|
|
||||||
|
*/
|
||||||
|
#ifdef BSON_MEMCHECK
|
||||||
|
#define BSON_INITIALIZER \
|
||||||
|
{ \
|
||||||
|
3, 5, \
|
||||||
|
bson_malloc (1), \
|
||||||
|
{ \
|
||||||
|
5 \
|
||||||
|
}, \
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define BSON_INITIALIZER \
|
||||||
|
{ \
|
||||||
|
3, 5, \
|
||||||
|
{ \
|
||||||
|
5 \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
BSON_STATIC_ASSERT2 (bson_t, sizeof (bson_t) == 128);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_oid_t:
|
||||||
|
*
|
||||||
|
* This structure contains the binary form of a BSON Object Id as specified
|
||||||
|
* on http://bsonspec.org. If you would like the bson_oid_t in string form
|
||||||
|
* see bson_oid_to_string() or bson_oid_to_string_r().
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint8_t bytes[12];
|
||||||
|
} bson_oid_t;
|
||||||
|
|
||||||
|
BSON_STATIC_ASSERT2 (oid_t, sizeof (bson_oid_t) == 12);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_decimal128_t:
|
||||||
|
*
|
||||||
|
* @high The high-order bytes of the decimal128. This field contains sign,
|
||||||
|
* combination bits, exponent, and part of the coefficient continuation.
|
||||||
|
* @low The low-order bytes of the decimal128. This field contains the second
|
||||||
|
* part of the coefficient continuation.
|
||||||
|
*
|
||||||
|
* This structure is a boxed type containing the value for the BSON decimal128
|
||||||
|
* type. The structure stores the 128 bits such that they correspond to the
|
||||||
|
* native format for the IEEE decimal128 type, if it is implemented.
|
||||||
|
**/
|
||||||
|
typedef struct {
|
||||||
|
#if BSON_BYTE_ORDER == BSON_LITTLE_ENDIAN
|
||||||
|
uint64_t low;
|
||||||
|
uint64_t high;
|
||||||
|
#elif BSON_BYTE_ORDER == BSON_BIG_ENDIAN
|
||||||
|
uint64_t high;
|
||||||
|
uint64_t low;
|
||||||
|
#endif
|
||||||
|
} bson_decimal128_t;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_validate_flags_t:
|
||||||
|
*
|
||||||
|
* This enumeration is used for validation of BSON documents. It allows
|
||||||
|
* selective control on what you wish to validate.
|
||||||
|
*
|
||||||
|
* %BSON_VALIDATE_NONE: No additional validation occurs.
|
||||||
|
* %BSON_VALIDATE_UTF8: Check that strings are valid UTF-8.
|
||||||
|
* %BSON_VALIDATE_DOLLAR_KEYS: Check that keys do not start with $.
|
||||||
|
* %BSON_VALIDATE_DOT_KEYS: Check that keys do not contain a period.
|
||||||
|
* %BSON_VALIDATE_UTF8_ALLOW_NULL: Allow NUL bytes in UTF-8 text.
|
||||||
|
* %BSON_VALIDATE_EMPTY_KEYS: Prohibit zero-length field names
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
BSON_VALIDATE_NONE = 0,
|
||||||
|
BSON_VALIDATE_UTF8 = (1 << 0),
|
||||||
|
BSON_VALIDATE_DOLLAR_KEYS = (1 << 1),
|
||||||
|
BSON_VALIDATE_DOT_KEYS = (1 << 2),
|
||||||
|
BSON_VALIDATE_UTF8_ALLOW_NULL = (1 << 3),
|
||||||
|
BSON_VALIDATE_EMPTY_KEYS = (1 << 4),
|
||||||
|
} bson_validate_flags_t;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_type_t:
|
||||||
|
*
|
||||||
|
* This enumeration contains all of the possible types within a BSON document.
|
||||||
|
* Use bson_iter_type() to fetch the type of a field while iterating over it.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
BSON_TYPE_EOD = 0x00,
|
||||||
|
BSON_TYPE_DOUBLE = 0x01,
|
||||||
|
BSON_TYPE_UTF8 = 0x02,
|
||||||
|
BSON_TYPE_DOCUMENT = 0x03,
|
||||||
|
BSON_TYPE_ARRAY = 0x04,
|
||||||
|
BSON_TYPE_BINARY = 0x05,
|
||||||
|
BSON_TYPE_UNDEFINED = 0x06,
|
||||||
|
BSON_TYPE_OID = 0x07,
|
||||||
|
BSON_TYPE_BOOL = 0x08,
|
||||||
|
BSON_TYPE_DATE_TIME = 0x09,
|
||||||
|
BSON_TYPE_NULL = 0x0A,
|
||||||
|
BSON_TYPE_REGEX = 0x0B,
|
||||||
|
BSON_TYPE_DBPOINTER = 0x0C,
|
||||||
|
BSON_TYPE_CODE = 0x0D,
|
||||||
|
BSON_TYPE_SYMBOL = 0x0E,
|
||||||
|
BSON_TYPE_CODEWSCOPE = 0x0F,
|
||||||
|
BSON_TYPE_INT32 = 0x10,
|
||||||
|
BSON_TYPE_TIMESTAMP = 0x11,
|
||||||
|
BSON_TYPE_INT64 = 0x12,
|
||||||
|
BSON_TYPE_DECIMAL128 = 0x13,
|
||||||
|
BSON_TYPE_MAXKEY = 0x7F,
|
||||||
|
BSON_TYPE_MINKEY = 0xFF,
|
||||||
|
} bson_type_t;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_subtype_t:
|
||||||
|
*
|
||||||
|
* This enumeration contains the various subtypes that may be used in a binary
|
||||||
|
* field. See http://bsonspec.org for more information.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
BSON_SUBTYPE_BINARY = 0x00,
|
||||||
|
BSON_SUBTYPE_FUNCTION = 0x01,
|
||||||
|
BSON_SUBTYPE_BINARY_DEPRECATED = 0x02,
|
||||||
|
BSON_SUBTYPE_UUID_DEPRECATED = 0x03,
|
||||||
|
BSON_SUBTYPE_UUID = 0x04,
|
||||||
|
BSON_SUBTYPE_MD5 = 0x05,
|
||||||
|
BSON_SUBTYPE_USER = 0x80,
|
||||||
|
} bson_subtype_t;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* bson_value_t --
|
||||||
|
*
|
||||||
|
* A boxed type to contain various bson_type_t types.
|
||||||
|
*
|
||||||
|
* See also:
|
||||||
|
* bson_value_copy()
|
||||||
|
* bson_value_destroy()
|
||||||
|
*
|
||||||
|
*--------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
BSON_ALIGNED_BEGIN (8)
|
||||||
|
typedef struct _bson_value_t {
|
||||||
|
bson_type_t value_type;
|
||||||
|
int32_t padding;
|
||||||
|
union {
|
||||||
|
bson_oid_t v_oid;
|
||||||
|
int64_t v_int64;
|
||||||
|
int32_t v_int32;
|
||||||
|
int8_t v_int8;
|
||||||
|
double v_double;
|
||||||
|
bool v_bool;
|
||||||
|
int64_t v_datetime;
|
||||||
|
struct {
|
||||||
|
uint32_t timestamp;
|
||||||
|
uint32_t increment;
|
||||||
|
} v_timestamp;
|
||||||
|
struct {
|
||||||
|
char *str;
|
||||||
|
uint32_t len;
|
||||||
|
} v_utf8;
|
||||||
|
struct {
|
||||||
|
uint8_t *data;
|
||||||
|
uint32_t data_len;
|
||||||
|
} v_doc;
|
||||||
|
struct {
|
||||||
|
uint8_t *data;
|
||||||
|
uint32_t data_len;
|
||||||
|
bson_subtype_t subtype;
|
||||||
|
} v_binary;
|
||||||
|
struct {
|
||||||
|
char *regex;
|
||||||
|
char *options;
|
||||||
|
} v_regex;
|
||||||
|
struct {
|
||||||
|
char *collection;
|
||||||
|
uint32_t collection_len;
|
||||||
|
bson_oid_t oid;
|
||||||
|
} v_dbpointer;
|
||||||
|
struct {
|
||||||
|
char *code;
|
||||||
|
uint32_t code_len;
|
||||||
|
} v_code;
|
||||||
|
struct {
|
||||||
|
char *code;
|
||||||
|
uint8_t *scope_data;
|
||||||
|
uint32_t code_len;
|
||||||
|
uint32_t scope_len;
|
||||||
|
} v_codewscope;
|
||||||
|
struct {
|
||||||
|
char *symbol;
|
||||||
|
uint32_t len;
|
||||||
|
} v_symbol;
|
||||||
|
bson_decimal128_t v_decimal128;
|
||||||
|
} value;
|
||||||
|
} bson_value_t BSON_ALIGNED_END (8);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_iter_t:
|
||||||
|
*
|
||||||
|
* This structure manages iteration over a bson_t structure. It keeps track
|
||||||
|
* of the location of the current key and value within the buffer. Using the
|
||||||
|
* various functions to get the value of the iter will read from these
|
||||||
|
* locations.
|
||||||
|
*
|
||||||
|
* This structure is safe to discard on the stack. No cleanup is necessary
|
||||||
|
* after using it.
|
||||||
|
*/
|
||||||
|
BSON_ALIGNED_BEGIN (128)
|
||||||
|
typedef struct {
|
||||||
|
const uint8_t *raw; /* The raw buffer being iterated. */
|
||||||
|
uint32_t len; /* The length of raw. */
|
||||||
|
uint32_t off; /* The offset within the buffer. */
|
||||||
|
uint32_t type; /* The offset of the type byte. */
|
||||||
|
uint32_t key; /* The offset of the key byte. */
|
||||||
|
uint32_t d1; /* The offset of the first data byte. */
|
||||||
|
uint32_t d2; /* The offset of the second data byte. */
|
||||||
|
uint32_t d3; /* The offset of the third data byte. */
|
||||||
|
uint32_t d4; /* The offset of the fourth data byte. */
|
||||||
|
uint32_t next_off; /* The offset of the next field. */
|
||||||
|
uint32_t err_off; /* The offset of the error. */
|
||||||
|
bson_value_t value; /* Internal value for various state. */
|
||||||
|
} bson_iter_t BSON_ALIGNED_END (128);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_reader_t:
|
||||||
|
*
|
||||||
|
* This structure is used to iterate over a sequence of BSON documents. It
|
||||||
|
* allows for them to be iterated with the possibility of no additional
|
||||||
|
* memory allocations under certain circumstances such as reading from an
|
||||||
|
* incoming mongo packet.
|
||||||
|
*/
|
||||||
|
|
||||||
|
BSON_ALIGNED_BEGIN (BSON_ALIGN_OF_PTR)
|
||||||
|
typedef struct {
|
||||||
|
uint32_t type;
|
||||||
|
/*< private >*/
|
||||||
|
} bson_reader_t BSON_ALIGNED_END (BSON_ALIGN_OF_PTR);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_visitor_t:
|
||||||
|
*
|
||||||
|
* This structure contains a series of pointers that can be executed for
|
||||||
|
* each field of a BSON document based on the field type.
|
||||||
|
*
|
||||||
|
* For example, if an int32 field is found, visit_int32 will be called.
|
||||||
|
*
|
||||||
|
* When visiting each field using bson_iter_visit_all(), you may provide a
|
||||||
|
* data pointer that will be provided with each callback. This might be useful
|
||||||
|
* if you are marshaling to another language.
|
||||||
|
*
|
||||||
|
* You may pre-maturely stop the visitation of fields by returning true in your
|
||||||
|
* visitor. Returning false will continue visitation to further fields.
|
||||||
|
*/
|
||||||
|
BSON_ALIGNED_BEGIN (8)
|
||||||
|
typedef struct {
|
||||||
|
/* run before / after descending into a document */
|
||||||
|
bool (*visit_before) (const bson_iter_t *iter, const char *key, void *data);
|
||||||
|
bool (*visit_after) (const bson_iter_t *iter, const char *key, void *data);
|
||||||
|
/* corrupt BSON, or unsupported type and visit_unsupported_type not set */
|
||||||
|
void (*visit_corrupt) (const bson_iter_t *iter, void *data);
|
||||||
|
/* normal bson field callbacks */
|
||||||
|
bool (*visit_double) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
double v_double,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_utf8) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
size_t v_utf8_len,
|
||||||
|
const char *v_utf8,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_document) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
const bson_t *v_document,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_array) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
const bson_t *v_array,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_binary) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
bson_subtype_t v_subtype,
|
||||||
|
size_t v_binary_len,
|
||||||
|
const uint8_t *v_binary,
|
||||||
|
void *data);
|
||||||
|
/* normal field with deprecated "Undefined" BSON type */
|
||||||
|
bool (*visit_undefined) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_oid) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
const bson_oid_t *v_oid,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_bool) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
bool v_bool,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_date_time) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
int64_t msec_since_epoch,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_null) (const bson_iter_t *iter, const char *key, void *data);
|
||||||
|
bool (*visit_regex) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
const char *v_regex,
|
||||||
|
const char *v_options,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_dbpointer) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
size_t v_collection_len,
|
||||||
|
const char *v_collection,
|
||||||
|
const bson_oid_t *v_oid,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_code) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
size_t v_code_len,
|
||||||
|
const char *v_code,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_symbol) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
size_t v_symbol_len,
|
||||||
|
const char *v_symbol,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_codewscope) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
size_t v_code_len,
|
||||||
|
const char *v_code,
|
||||||
|
const bson_t *v_scope,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_int32) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
int32_t v_int32,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_timestamp) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
uint32_t v_timestamp,
|
||||||
|
uint32_t v_increment,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_int64) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
int64_t v_int64,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_maxkey) (const bson_iter_t *iter, const char *key, void *data);
|
||||||
|
bool (*visit_minkey) (const bson_iter_t *iter, const char *key, void *data);
|
||||||
|
/* if set, called instead of visit_corrupt when an apparently valid BSON
|
||||||
|
* includes an unrecognized field type (reading future version of BSON) */
|
||||||
|
void (*visit_unsupported_type) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
uint32_t type_code,
|
||||||
|
void *data);
|
||||||
|
bool (*visit_decimal128) (const bson_iter_t *iter,
|
||||||
|
const char *key,
|
||||||
|
const bson_decimal128_t *v_decimal128,
|
||||||
|
void *data);
|
||||||
|
|
||||||
|
void *padding[7];
|
||||||
|
} bson_visitor_t BSON_ALIGNED_END (8);
|
||||||
|
|
||||||
|
#define BSON_ERROR_BUFFER_SIZE 504
|
||||||
|
|
||||||
|
BSON_ALIGNED_BEGIN (8)
|
||||||
|
typedef struct _bson_error_t {
|
||||||
|
uint32_t domain;
|
||||||
|
uint32_t code;
|
||||||
|
char message[BSON_ERROR_BUFFER_SIZE];
|
||||||
|
} bson_error_t BSON_ALIGNED_END (8);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_STATIC_ASSERT2 (error_t, sizeof (bson_error_t) == 512);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_next_power_of_two:
|
||||||
|
* @v: A 32-bit unsigned integer of required bytes.
|
||||||
|
*
|
||||||
|
* Determines the next larger power of two for the value of @v
|
||||||
|
* in a constant number of operations.
|
||||||
|
*
|
||||||
|
* It is up to the caller to guarantee this will not overflow.
|
||||||
|
*
|
||||||
|
* Returns: The next power of 2 from @v.
|
||||||
|
*/
|
||||||
|
static BSON_INLINE size_t
|
||||||
|
bson_next_power_of_two (size_t v)
|
||||||
|
{
|
||||||
|
v--;
|
||||||
|
v |= v >> 1;
|
||||||
|
v |= v >> 2;
|
||||||
|
v |= v >> 4;
|
||||||
|
v |= v >> 8;
|
||||||
|
v |= v >> 16;
|
||||||
|
#if BSON_WORD_SIZE == 64
|
||||||
|
v |= v >> 32;
|
||||||
|
#endif
|
||||||
|
v++;
|
||||||
|
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static BSON_INLINE bool
|
||||||
|
bson_is_power_of_two (uint32_t v)
|
||||||
|
{
|
||||||
|
return ((v != 0) && ((v & (v - 1)) == 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_TYPES_H */
|
||||||
46
include/libbson-1.0/bson/bson-utf8.h
Normal file
46
include/libbson-1.0/bson/bson-utf8.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_UTF8_H
|
||||||
|
#define BSON_UTF8_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_utf8_validate (const char *utf8, size_t utf8_len, bool allow_null);
|
||||||
|
BSON_EXPORT (char *)
|
||||||
|
bson_utf8_escape_for_json (const char *utf8, ssize_t utf8_len);
|
||||||
|
BSON_EXPORT (bson_unichar_t)
|
||||||
|
bson_utf8_get_char (const char *utf8);
|
||||||
|
BSON_EXPORT (const char *)
|
||||||
|
bson_utf8_next_char (const char *utf8);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_utf8_from_unichar (bson_unichar_t unichar, char utf8[6], uint32_t *len);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_UTF8_H */
|
||||||
40
include/libbson-1.0/bson/bson-value.h
Normal file
40
include/libbson-1.0/bson/bson-value.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_VALUE_H
|
||||||
|
#define BSON_VALUE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-macros.h"
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_value_copy (const bson_value_t *src, bson_value_t *dst);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_value_destroy (bson_value_t *value);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_VALUE_H */
|
||||||
41
include/libbson-1.0/bson/bson-version-functions.h
Normal file
41
include/libbson-1.0/bson/bson-version-functions.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_VERSION_FUNCTIONS_H
|
||||||
|
#define BSON_VERSION_FUNCTIONS_H
|
||||||
|
|
||||||
|
#include "bson/bson-types.h"
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
BSON_EXPORT (int)
|
||||||
|
bson_get_major_version (void);
|
||||||
|
BSON_EXPORT (int)
|
||||||
|
bson_get_minor_version (void);
|
||||||
|
BSON_EXPORT (int)
|
||||||
|
bson_get_micro_version (void);
|
||||||
|
BSON_EXPORT (const char *)
|
||||||
|
bson_get_version (void);
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_check_version (int required_major, int required_minor, int required_micro);
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
#endif /* BSON_VERSION_FUNCTIONS_H */
|
||||||
101
include/libbson-1.0/bson/bson-version.h
Normal file
101
include/libbson-1.0/bson/bson-version.h
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined (BSON_INSIDE) && !defined (BSON_COMPILATION)
|
||||||
|
#error "Only <bson/bson.h> can be included directly."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_VERSION_H
|
||||||
|
#define BSON_VERSION_H
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSON_MAJOR_VERSION:
|
||||||
|
*
|
||||||
|
* BSON major version component (e.g. 1 if %BSON_VERSION is 1.2.3)
|
||||||
|
*/
|
||||||
|
#define BSON_MAJOR_VERSION (1)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSON_MINOR_VERSION:
|
||||||
|
*
|
||||||
|
* BSON minor version component (e.g. 2 if %BSON_VERSION is 1.2.3)
|
||||||
|
*/
|
||||||
|
#define BSON_MINOR_VERSION (14)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSON_MICRO_VERSION:
|
||||||
|
*
|
||||||
|
* BSON micro version component (e.g. 3 if %BSON_VERSION is 1.2.3)
|
||||||
|
*/
|
||||||
|
#define BSON_MICRO_VERSION (0)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSON_PRERELEASE_VERSION:
|
||||||
|
*
|
||||||
|
* BSON prerelease version component (e.g. pre if %BSON_VERSION is 1.2.3-pre)
|
||||||
|
*/
|
||||||
|
#define BSON_PRERELEASE_VERSION ()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSON_VERSION:
|
||||||
|
*
|
||||||
|
* BSON version.
|
||||||
|
*/
|
||||||
|
#define BSON_VERSION (1.14.0)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSON_VERSION_S:
|
||||||
|
*
|
||||||
|
* BSON version, encoded as a string, useful for printing and
|
||||||
|
* concatenation.
|
||||||
|
*/
|
||||||
|
#define BSON_VERSION_S "1.14.0"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSON_VERSION_HEX:
|
||||||
|
*
|
||||||
|
* BSON version, encoded as an hexadecimal number, useful for
|
||||||
|
* integer comparisons.
|
||||||
|
*/
|
||||||
|
#define BSON_VERSION_HEX (BSON_MAJOR_VERSION << 24 | \
|
||||||
|
BSON_MINOR_VERSION << 16 | \
|
||||||
|
BSON_MICRO_VERSION << 8)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BSON_CHECK_VERSION:
|
||||||
|
* @major: required major version
|
||||||
|
* @minor: required minor version
|
||||||
|
* @micro: required micro version
|
||||||
|
*
|
||||||
|
* Compile-time version checking. Evaluates to %TRUE if the version
|
||||||
|
* of BSON is greater than the required one.
|
||||||
|
*/
|
||||||
|
#define BSON_CHECK_VERSION(major,minor,micro) \
|
||||||
|
(BSON_MAJOR_VERSION > (major) || \
|
||||||
|
(BSON_MAJOR_VERSION == (major) && BSON_MINOR_VERSION > (minor)) || \
|
||||||
|
(BSON_MAJOR_VERSION == (major) && BSON_MINOR_VERSION == (minor) && \
|
||||||
|
BSON_MICRO_VERSION >= (micro)))
|
||||||
|
|
||||||
|
#endif /* BSON_VERSION_H */
|
||||||
65
include/libbson-1.0/bson/bson-writer.h
Normal file
65
include/libbson-1.0/bson/bson-writer.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013 MongoDB, Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "bson/bson-prelude.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BSON_WRITER_H
|
||||||
|
#define BSON_WRITER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "bson/bson.h"
|
||||||
|
|
||||||
|
|
||||||
|
BSON_BEGIN_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bson_writer_t:
|
||||||
|
*
|
||||||
|
* The bson_writer_t structure is a helper for writing a series of BSON
|
||||||
|
* documents to a single malloc() buffer. You can provide a realloc() style
|
||||||
|
* function to grow the buffer as you go.
|
||||||
|
*
|
||||||
|
* This is useful if you want to build a series of BSON documents right into
|
||||||
|
* the target buffer for an outgoing packet. The offset parameter allows you to
|
||||||
|
* start at an offset of the target buffer.
|
||||||
|
*/
|
||||||
|
typedef struct _bson_writer_t bson_writer_t;
|
||||||
|
|
||||||
|
|
||||||
|
BSON_EXPORT (bson_writer_t *)
|
||||||
|
bson_writer_new (uint8_t **buf,
|
||||||
|
size_t *buflen,
|
||||||
|
size_t offset,
|
||||||
|
bson_realloc_func realloc_func,
|
||||||
|
void *realloc_func_ctx);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_writer_destroy (bson_writer_t *writer);
|
||||||
|
BSON_EXPORT (size_t)
|
||||||
|
bson_writer_get_length (bson_writer_t *writer);
|
||||||
|
BSON_EXPORT (bool)
|
||||||
|
bson_writer_begin (bson_writer_t *writer, bson_t **bson);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_writer_end (bson_writer_t *writer);
|
||||||
|
BSON_EXPORT (void)
|
||||||
|
bson_writer_rollback (bson_writer_t *writer);
|
||||||
|
|
||||||
|
|
||||||
|
BSON_END_DECLS
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BSON_WRITER_H */
|
||||||
1150
include/libbson-1.0/bson/bson.h
Normal file
1150
include/libbson-1.0/bson/bson.h
Normal file
File diff suppressed because it is too large
Load Diff
147
include/seiscomp/io/recordstream/arclink.h
Normal file
147
include/seiscomp/io/recordstream/arclink.h
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) gempa GmbH *
|
||||||
|
* All rights reserved. *
|
||||||
|
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||||
|
* *
|
||||||
|
* GNU Affero General Public License Usage *
|
||||||
|
* This file may be used under the terms of the GNU Affero *
|
||||||
|
* Public License version 3.0 as published by the Free Software Foundation *
|
||||||
|
* and appearing in the file LICENSE included in the packaging of this *
|
||||||
|
* file. Please review the following information to ensure the GNU Affero *
|
||||||
|
* Public License version 3.0 requirements will be met: *
|
||||||
|
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||||
|
* *
|
||||||
|
* Other Usage *
|
||||||
|
* Alternatively, this file may be used in accordance with the terms and *
|
||||||
|
* conditions contained in a signed written agreement between you and *
|
||||||
|
* gempa GmbH. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SEISCOMP_IO_RECORDSTREAM_ARCLINK_H
|
||||||
|
#define SEISCOMP_IO_RECORDSTREAM_ARCLINK_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <set>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <seiscomp/core/interruptible.h>
|
||||||
|
#include <seiscomp/core/datetime.h>
|
||||||
|
#include <seiscomp/utils/timer.h>
|
||||||
|
#include <seiscomp/io/recordstream.h>
|
||||||
|
#include <seiscomp/core.h>
|
||||||
|
#include <seiscomp/io/socket.h>
|
||||||
|
#include <seiscomp/io/recordstream/streamidx.h>
|
||||||
|
|
||||||
|
namespace Seiscomp {
|
||||||
|
namespace RecordStream {
|
||||||
|
namespace Arclink {
|
||||||
|
namespace _private {
|
||||||
|
|
||||||
|
class SC_SYSTEM_CORE_API ArclinkException: public Seiscomp::IO::RecordStreamException {
|
||||||
|
public:
|
||||||
|
ArclinkException(): RecordStreamException("ArcLink exception") {}
|
||||||
|
ArclinkException(const std::string& what): RecordStreamException(what) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class SC_SYSTEM_CORE_API ArclinkCommandException: public ArclinkException {
|
||||||
|
public:
|
||||||
|
ArclinkCommandException(): ArclinkException("command not accepted") {}
|
||||||
|
ArclinkCommandException(const std::string& what): ArclinkException(what) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
DEFINE_SMARTPOINTER(ArclinkConnection);
|
||||||
|
|
||||||
|
class SC_SYSTEM_CORE_API ArclinkConnection : public Seiscomp::IO::RecordStream {
|
||||||
|
DECLARE_SC_CLASS(ArclinkConnection);
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! C'tor
|
||||||
|
ArclinkConnection();
|
||||||
|
|
||||||
|
//! Initializing Constructor
|
||||||
|
ArclinkConnection(std::string serverloc);
|
||||||
|
|
||||||
|
//! Destructor
|
||||||
|
virtual ~ArclinkConnection();
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! The recordtype cannot be selected when using an arclink
|
||||||
|
//! connection. It will always create MiniSeed records
|
||||||
|
virtual bool setRecordType(const char*);
|
||||||
|
|
||||||
|
//! Initialize the arclink connection.
|
||||||
|
virtual bool setSource(const std::string &serverloc);
|
||||||
|
|
||||||
|
//! Supply user credentials
|
||||||
|
bool setUser(std::string name, std::string password);
|
||||||
|
|
||||||
|
//! Adds the given stream to the server connection description
|
||||||
|
virtual bool addStream(const std::string &networkCode,
|
||||||
|
const std::string &stationCode,
|
||||||
|
const std::string &locationCode,
|
||||||
|
const std::string &channelCode);
|
||||||
|
|
||||||
|
//! Adds the given stream to the server connection description
|
||||||
|
virtual bool addStream(const std::string &networkCode,
|
||||||
|
const std::string &stationCode,
|
||||||
|
const std::string &locationCode,
|
||||||
|
const std::string &channelCode,
|
||||||
|
const Seiscomp::Core::Time &stime,
|
||||||
|
const Seiscomp::Core::Time &etime);
|
||||||
|
|
||||||
|
//! Adds the given start time to the server connection description
|
||||||
|
virtual bool setStartTime(const Seiscomp::Core::Time &stime);
|
||||||
|
|
||||||
|
//! Adds the given end time to the server connection description
|
||||||
|
virtual bool setEndTime(const Seiscomp::Core::Time &etime);
|
||||||
|
|
||||||
|
//! Sets timeout
|
||||||
|
virtual bool setTimeout(int seconds);
|
||||||
|
|
||||||
|
//! Terminates the arclink connection.
|
||||||
|
virtual void close();
|
||||||
|
|
||||||
|
virtual Record *next();
|
||||||
|
|
||||||
|
//! Removes all stream list, time window, etc. -entries from the connection description object.
|
||||||
|
bool clear();
|
||||||
|
|
||||||
|
//! Reconnects a terminated arclink connection.
|
||||||
|
bool reconnect();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
Seiscomp::IO::Socket _sock;
|
||||||
|
std::string _serverloc;
|
||||||
|
std::string _user;
|
||||||
|
std::string _passwd;
|
||||||
|
std::list<StreamIdx> _ordered;
|
||||||
|
std::set<StreamIdx> _streams;
|
||||||
|
Seiscomp::Core::Time _stime;
|
||||||
|
Seiscomp::Core::Time _etime;
|
||||||
|
std::string _reqID;
|
||||||
|
bool _readingData;
|
||||||
|
bool _chunkMode;
|
||||||
|
int _remainingBytes;
|
||||||
|
std::ofstream _dump;
|
||||||
|
|
||||||
|
void handshake();
|
||||||
|
void cleanup();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace _private
|
||||||
|
|
||||||
|
//using _private::ArclinkException;
|
||||||
|
//using _private::ArclinkCommandException;
|
||||||
|
using _private::ArclinkConnection;
|
||||||
|
using _private::ArclinkConnectionPtr;
|
||||||
|
|
||||||
|
} // namespace Arclink
|
||||||
|
} // namespace RecordStream
|
||||||
|
} // namespace Seiscomp
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
109
include/seiscomp/seismology/locator/fixed-hypocenter.h
Normal file
109
include/seiscomp/seismology/locator/fixed-hypocenter.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) gempa GmbH *
|
||||||
|
* All rights reserved. *
|
||||||
|
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||||
|
* *
|
||||||
|
* GNU Affero General Public License Usage *
|
||||||
|
* This file may be used under the terms of the GNU Affero *
|
||||||
|
* Public License version 3.0 as published by the Free Software Foundation *
|
||||||
|
* and appearing in the file LICENSE included in the packaging of this *
|
||||||
|
* file. Please review the following information to ensure the GNU Affero *
|
||||||
|
* Public License version 3.0 requirements will be met: *
|
||||||
|
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||||
|
* *
|
||||||
|
* Other Usage *
|
||||||
|
* Alternatively, this file may be used in accordance with the terms and *
|
||||||
|
* conditions contained in a signed written agreement between you and *
|
||||||
|
* gempa GmbH. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SEISCOMP_SEISMOLOGY_FIXED_HYPOCENTER_H
|
||||||
|
#define SEISCOMP_SEISMOLOGY_FIXED_HYPOCENTER_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <seiscomp/core/exceptions.h>
|
||||||
|
#include <seiscomp/datamodel/origin.h>
|
||||||
|
#include <seiscomp/datamodel/arrival.h>
|
||||||
|
#include <seiscomp/datamodel/pick.h>
|
||||||
|
#include <seiscomp/datamodel/station.h>
|
||||||
|
#include <seiscomp/seismology/locatorinterface.h>
|
||||||
|
#include <seiscomp/seismology/ttt.h>
|
||||||
|
#include <seiscomp/core.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Seiscomp{
|
||||||
|
namespace Seismology {
|
||||||
|
|
||||||
|
|
||||||
|
class SC_SYSTEM_CORE_API FixedHypocenter : public LocatorInterface {
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// X'truction
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
public:
|
||||||
|
FixedHypocenter() = default;
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Locator interface
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
public:
|
||||||
|
virtual bool init(const Config::Config &config) override;
|
||||||
|
|
||||||
|
//! Returns supported parameters to be changed.
|
||||||
|
virtual IDList parameters() const override;
|
||||||
|
|
||||||
|
//! Returns the value of a parameter.
|
||||||
|
virtual std::string parameter(const std::string &name) const override;
|
||||||
|
|
||||||
|
//! Sets the value of a parameter.
|
||||||
|
virtual bool setParameter(const std::string &name,
|
||||||
|
const std::string &value) override;
|
||||||
|
|
||||||
|
virtual IDList profiles() const override;
|
||||||
|
virtual void setProfile(const std::string &name) override;
|
||||||
|
|
||||||
|
virtual int capabilities() const override;
|
||||||
|
|
||||||
|
virtual DataModel::Origin *locate(PickList& pickList) override;
|
||||||
|
virtual DataModel::Origin *locate(PickList& pickList,
|
||||||
|
double initLat, double initLon, double initDepth,
|
||||||
|
const Seiscomp::Core::Time& initTime) override;
|
||||||
|
|
||||||
|
virtual DataModel::Origin *relocate(const DataModel::Origin* origin) override;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum Flag {
|
||||||
|
UsePickUncertainties = 0x01,
|
||||||
|
UseOriginUncertainties = 0x02
|
||||||
|
};
|
||||||
|
|
||||||
|
// Configuration
|
||||||
|
IDList _profiles;
|
||||||
|
int _degreesOfFreedom{8};
|
||||||
|
double _confidenceLevel{0.9};
|
||||||
|
double _defaultTimeError{1.0};
|
||||||
|
union {
|
||||||
|
uint8_t _flags{UseOriginUncertainties};
|
||||||
|
bool _legacyAndUnusedFlag;
|
||||||
|
};
|
||||||
|
bool _verbose{false};
|
||||||
|
std::string _lastError;
|
||||||
|
OPT(double) _initLat;
|
||||||
|
OPT(double) _initLon;
|
||||||
|
OPT(double) _initDepth;
|
||||||
|
|
||||||
|
// Runtime
|
||||||
|
TravelTimeTableInterfacePtr _ttt;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
158
include/seiscomp/seismology/locator/locsat.h
Normal file
158
include/seiscomp/seismology/locator/locsat.h
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) gempa GmbH *
|
||||||
|
* All rights reserved. *
|
||||||
|
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||||
|
* *
|
||||||
|
* GNU Affero General Public License Usage *
|
||||||
|
* This file may be used under the terms of the GNU Affero *
|
||||||
|
* Public License version 3.0 as published by the Free Software Foundation *
|
||||||
|
* and appearing in the file LICENSE included in the packaging of this *
|
||||||
|
* file. Please review the following information to ensure the GNU Affero *
|
||||||
|
* Public License version 3.0 requirements will be met: *
|
||||||
|
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||||
|
* *
|
||||||
|
* Other Usage *
|
||||||
|
* Alternatively, this file may be used in accordance with the terms and *
|
||||||
|
* conditions contained in a signed written agreement between you and *
|
||||||
|
* gempa GmbH. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SEISCOMP_SEISMOLOGY_LOCSAT_H
|
||||||
|
#define SEISCOMP_SEISMOLOGY_LOCSAT_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <seiscomp/core/exceptions.h>
|
||||||
|
#include <seiscomp/datamodel/origin.h>
|
||||||
|
#include <seiscomp/datamodel/arrival.h>
|
||||||
|
#include <seiscomp/datamodel/pick.h>
|
||||||
|
#include <seiscomp/datamodel/station.h>
|
||||||
|
#include <seiscomp/seismology/locatorinterface.h>
|
||||||
|
#include <seiscomp/core.h>
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Seiscomp{
|
||||||
|
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
struct Locator_params;
|
||||||
|
class LocSAT;
|
||||||
|
class Loc;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct SC_SYSTEM_CORE_API LocSATErrorEllipsoid {
|
||||||
|
LocSATErrorEllipsoid() {
|
||||||
|
sxx=syy=szz=stt=sxy=sxz=syz=stx=sty=stz=sdobs=smajax=sminax=strike=sdepth=stime=conf=0.;
|
||||||
|
}
|
||||||
|
|
||||||
|
float sxx;
|
||||||
|
float syy;
|
||||||
|
float szz;
|
||||||
|
float stt;
|
||||||
|
float sxy;
|
||||||
|
float sxz;
|
||||||
|
float syz;
|
||||||
|
float stx;
|
||||||
|
float sty;
|
||||||
|
float stz;
|
||||||
|
float sdobs;
|
||||||
|
float smajax;
|
||||||
|
float sminax;
|
||||||
|
float strike;
|
||||||
|
float sdepth;
|
||||||
|
float stime;
|
||||||
|
float conf;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class SC_SYSTEM_CORE_API LocSAT : public Seismology::LocatorInterface {
|
||||||
|
public:
|
||||||
|
LocSAT();
|
||||||
|
virtual ~LocSAT();
|
||||||
|
|
||||||
|
virtual bool init(const Config::Config &config);
|
||||||
|
|
||||||
|
//! Returns supported parameters to be changed.
|
||||||
|
virtual IDList parameters() const;
|
||||||
|
|
||||||
|
//! Returns the value of a parameter.
|
||||||
|
virtual std::string parameter(const std::string &name) const;
|
||||||
|
|
||||||
|
//! Sets the value of a parameter.
|
||||||
|
virtual bool setParameter(const std::string &name,
|
||||||
|
const std::string &value);
|
||||||
|
|
||||||
|
virtual IDList profiles() const;
|
||||||
|
virtual void setProfile(const std::string &name);
|
||||||
|
|
||||||
|
static void setDefaultProfile(const std::string &name);
|
||||||
|
static std::string currentDefaultProfile();
|
||||||
|
|
||||||
|
void setNewOriginID(const std::string& newOriginID);
|
||||||
|
|
||||||
|
int capabilities() const;
|
||||||
|
|
||||||
|
DataModel::Origin* locate(PickList& pickList);
|
||||||
|
DataModel::Origin* locate(PickList& pickList,
|
||||||
|
double initLat, double initLon, double initDepth,
|
||||||
|
const Seiscomp::Core::Time& initTime);
|
||||||
|
|
||||||
|
DataModel::Origin* relocate(const DataModel::Origin* origin);
|
||||||
|
|
||||||
|
const LocSATErrorEllipsoid &errorEllipsoid() const {
|
||||||
|
return _errorEllipsoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setLocatorParams(int param, const char* value);
|
||||||
|
std::string getLocatorParams(int param) const;
|
||||||
|
void setDefaultLocatorParams();
|
||||||
|
|
||||||
|
bool loadArrivals(const DataModel::Origin* origin);
|
||||||
|
DataModel::Origin *fromPicks(PickList& pickList);
|
||||||
|
DataModel::Origin *loc2Origin(Internal::Loc* loc);
|
||||||
|
|
||||||
|
double stationCorrection(const std::string &staid, const std::string &stacode,
|
||||||
|
const std::string &phase) const;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef std::map<std::string, double> PhaseCorrectionMap;
|
||||||
|
typedef std::map<std::string, PhaseCorrectionMap> StationCorrectionMap;
|
||||||
|
|
||||||
|
static std::string _defaultTablePrefix;
|
||||||
|
static IDList _allowedParameters;
|
||||||
|
|
||||||
|
StationCorrectionMap _stationCorrection;
|
||||||
|
std::string _newOriginID;
|
||||||
|
std::string _tablePrefix;
|
||||||
|
bool _computeConfidenceEllipsoid;
|
||||||
|
Internal::LocSAT *_locateEvent;
|
||||||
|
Internal::Locator_params *_locator_params;
|
||||||
|
double _minArrivalWeight{0.5};
|
||||||
|
double _defaultPickUncertainty;
|
||||||
|
bool _usePickUncertainties{false};
|
||||||
|
bool _usePickBackazimuth{true};
|
||||||
|
bool _usePickSlowness{true};
|
||||||
|
|
||||||
|
bool _enableDebugOutput;
|
||||||
|
|
||||||
|
IDList _profiles;
|
||||||
|
|
||||||
|
LocSATErrorEllipsoid _errorEllipsoid;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}// of namespace Seiscomp
|
||||||
|
|
||||||
|
#endif
|
||||||
148
include/seiscomp/seismology/ttt/locsat.h
Normal file
148
include/seiscomp/seismology/ttt/locsat.h
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) gempa GmbH *
|
||||||
|
* All rights reserved. *
|
||||||
|
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||||
|
* *
|
||||||
|
* GNU Affero General Public License Usage *
|
||||||
|
* This file may be used under the terms of the GNU Affero *
|
||||||
|
* Public License version 3.0 as published by the Free Software Foundation *
|
||||||
|
* and appearing in the file LICENSE included in the packaging of this *
|
||||||
|
* file. Please review the following information to ensure the GNU Affero *
|
||||||
|
* Public License version 3.0 requirements will be met: *
|
||||||
|
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||||
|
* *
|
||||||
|
* Other Usage *
|
||||||
|
* Alternatively, this file may be used in accordance with the terms and *
|
||||||
|
* conditions contained in a signed written agreement between you and *
|
||||||
|
* gempa GmbH. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef SEISCOMP_TTT_LOCSAT_H
|
||||||
|
#define SEISCOMP_TTT_LOCSAT_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <seiscomp/seismology/ttt.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Seiscomp {
|
||||||
|
namespace TTT {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TTTLibTau
|
||||||
|
*
|
||||||
|
* A class to compute seismic travel times for 1D models like "iasp91".
|
||||||
|
*/
|
||||||
|
class SC_SYSTEM_CORE_API Locsat : public TravelTimeTableInterface {
|
||||||
|
public:
|
||||||
|
struct Velocity {
|
||||||
|
Velocity() {}
|
||||||
|
Velocity(float z, float p, float s) : depth(z), vp(p), vs(s) {}
|
||||||
|
float depth;
|
||||||
|
float vp;
|
||||||
|
float vs;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Construct a TravelTimeTable object for the specified model.
|
||||||
|
* Currently only "iasp91" is supported.
|
||||||
|
*/
|
||||||
|
Locsat();
|
||||||
|
~Locsat();
|
||||||
|
|
||||||
|
Locsat(const Locsat &other);
|
||||||
|
Locsat &operator=(const Locsat &other);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool setModel(const std::string &model) override;
|
||||||
|
const std::string &model() const override;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compute the traveltime(s) for the model selected using
|
||||||
|
* setModel().
|
||||||
|
*
|
||||||
|
* Note that altitude correction is currently not implemented! The
|
||||||
|
* respective parameters are ignored.
|
||||||
|
* @param dep1 The source depth in km
|
||||||
|
*
|
||||||
|
* @returns A TravelTimeList of travel times sorted by time.
|
||||||
|
*/
|
||||||
|
TravelTimeList *compute(double lat1, double lon1, double dep1,
|
||||||
|
double lat2, double lon2, double alt2 = 0.,
|
||||||
|
int ellc = 1) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the traveltime and a given phase. The default implementation
|
||||||
|
* computes the complete travel time list and searches for them
|
||||||
|
* requested phase.
|
||||||
|
* @param dep1 The source depth in km
|
||||||
|
*
|
||||||
|
* @returns A TravelTime
|
||||||
|
*/
|
||||||
|
TravelTime compute(const char *phase,
|
||||||
|
double lat1, double lon1, double dep1,
|
||||||
|
double lat2, double lon2, double alt2=0.,
|
||||||
|
int ellc = 1) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compute the traveltime for the model selected using setModel()
|
||||||
|
* and the first (fastest) phase.
|
||||||
|
*
|
||||||
|
* Note that altitude correction is currently not implemented! The
|
||||||
|
* respective parameters are ignored.
|
||||||
|
* @param dep1 The source depth in km
|
||||||
|
* @returns A TravelTime
|
||||||
|
*/
|
||||||
|
TravelTime computeFirst(double lat1, double lon1, double dep1,
|
||||||
|
double lat2, double lon2, double alt2 = 0.,
|
||||||
|
int ellc = 1) override;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the travel time for a given phase. This is intended
|
||||||
|
* to be a faster call than 'compute' since only the travel time
|
||||||
|
* is returned.
|
||||||
|
*
|
||||||
|
* @param lat1 Latitude of source
|
||||||
|
* @param lon1 Longitude of source
|
||||||
|
* @param dep1 The source depth in km
|
||||||
|
* @param lat2 Latitude of receiver
|
||||||
|
* @param lon2 Longitude of receiver
|
||||||
|
* @param elev2 Elevation of receiver in m
|
||||||
|
* @param ellc Apply ellipticity correction (1 = on, 0 = off)
|
||||||
|
* @returns The travel time for the phase
|
||||||
|
*/
|
||||||
|
double computeTime(const char *phase,
|
||||||
|
double lat1, double lon1, double dep1,
|
||||||
|
double lat2, double lon2, double elev2=0.,
|
||||||
|
int ellc = 1) override;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
TravelTimeList *compute(double delta, double depth);
|
||||||
|
TravelTime compute(const char *phase, double delta, double depth);
|
||||||
|
TravelTime computeFirst(double delta, double depth);
|
||||||
|
double computeTime(const char *phase, double delta, double depth);
|
||||||
|
|
||||||
|
bool initTables();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _model;
|
||||||
|
std::string _tablePrefix;
|
||||||
|
int _Pindex;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -122,16 +122,13 @@ class SC_SYSTEM_CORE_API PluginRegistry {
|
|||||||
//! Returns the end iterator over all registered plugins
|
//! Returns the end iterator over all registered plugins
|
||||||
iterator end() const;
|
iterator end() const;
|
||||||
|
|
||||||
//! Returns the list of errors after calling loadPlugins.
|
|
||||||
const std::vector<std::string> &errors() const;
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Private members
|
// Private members
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
private:
|
private:
|
||||||
std::string find(const std::string &name) const;
|
std::string find(const std::string &name) const;
|
||||||
PluginEntry open(const std::string &file, std::string *errorMsg = nullptr) const;
|
PluginEntry open(const std::string &file) const;
|
||||||
bool findLibrary(void *handle) const;
|
bool findLibrary(void *handle) const;
|
||||||
|
|
||||||
|
|
||||||
@ -142,14 +139,12 @@ class SC_SYSTEM_CORE_API PluginRegistry {
|
|||||||
using PluginList = std::list<PluginEntry>;
|
using PluginList = std::list<PluginEntry>;
|
||||||
using PathList = std::vector<std::string>;
|
using PathList = std::vector<std::string>;
|
||||||
using NameList = std::vector<std::string>;
|
using NameList = std::vector<std::string>;
|
||||||
using StringList = NameList;
|
|
||||||
|
|
||||||
static PluginRegistry *_instance;
|
static PluginRegistry *_instance;
|
||||||
|
|
||||||
PluginList _plugins;
|
PluginList _plugins;
|
||||||
PathList _paths;
|
PathList _paths;
|
||||||
NameList _pluginNames;
|
NameList _pluginNames;
|
||||||
StringList _errors;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
1
include/seiscomp3
Symbolic link
1
include/seiscomp3
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
seiscomp
|
||||||
1
lib/libbson-1.0.so
Symbolic link
1
lib/libbson-1.0.so
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
libbson-1.0.so.0
|
||||||
1
lib/libbson-1.0.so.0
Symbolic link
1
lib/libbson-1.0.so.0
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
libbson-1.0.so.0.0.0
|
||||||
BIN
lib/libbson-1.0.so.0.0.0
Normal file
BIN
lib/libbson-1.0.so.0.0.0
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
lib/libseiscomp_client.so.16
Symbolic link
1
lib/libseiscomp_client.so.16
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
libseiscomp_client.so.16.4.0
|
||||||
BIN
lib/libseiscomp_client.so.16.4.0
Normal file
BIN
lib/libseiscomp_client.so.16.4.0
Normal file
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user