T checkNotNull(T obj) {
34 | if (obj == null) {
35 | throw new NullPointerException();
36 | }
37 | return obj;
38 | }
39 |
40 | public static void checkArgument(boolean condition) {
41 | if (!condition) {
42 | throw new IllegalArgumentException();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/include/rtn.hpp:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Copyright (C) 2013 SequoiaDB Software Inc.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License, version 3,
6 | as published by the Free Software Foundation.
7 |
8 | This program is distributed in the hope that it will be useful,
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | GNU Affero General Public License for more details.
12 |
13 | You should have received a copy of the GNU Affero General Public License
14 | along with this program. If not, see .
15 | *******************************************************************************/
16 | #ifndef RTN_HPP__
17 | #define RTN_HPP__
18 |
19 | #include "bson.h"
20 | #include "dms.hpp"
21 | #include "ixmBucket.hpp"
22 | // define the storage file name
23 | #define RTN_FILE_NAME "data.1"
24 |
25 | class rtn
26 | {
27 | private :
28 | dmsFile *_dmsFile ;
29 | ixmBucketManager *_ixmBucketMgr ;
30 | public :
31 | rtn () ;
32 | ~rtn() ;
33 | int rtnInitialize () ;
34 | int rtnInsert ( bson::BSONObj &record ) ;
35 | int rtnFind ( bson::BSONObj &inRecord, bson::BSONObj &outRecord ) ;
36 | int rtnRemove ( bson::BSONObj &record ) ;
37 | } ;
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/FieldNamingStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | import java.lang.reflect.Field;
20 |
21 | /**
22 | * A mechanism for providing custom field naming in Gson. This allows the client code to translate
23 | * field names into a particular convention that is not supported as a normal Java field
24 | * declaration rules. For example, Java does not support "-" characters in a field name.
25 | *
26 | * @author Inderjeet Singh
27 | * @author Joel Leitch
28 | * @since 1.3
29 | */
30 | public interface FieldNamingStrategy {
31 |
32 | /**
33 | * Translates the field name into its JSON field name representation.
34 | *
35 | * @param f the field object that we are translating
36 | * @return the translated field name.
37 | * @since 1.3
38 | */
39 | public String translateName(Field f);
40 | }
41 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/util/annotations/Immutable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2005 Brian Goetz and Tim Peierls
3 | * Released under the Creative Commons Attribution License
4 | * (http://creativecommons.org/licenses/by/2.5)
5 | * Official home: http://www.jcip.net
6 | *
7 | * Any republication or derived work distributed in source code form
8 | * must include this copyright and license notice.
9 | */
10 |
11 | package org.bson.util.annotations;
12 |
13 | import java.lang.annotation.*;
14 |
15 | /**
16 | * The class to which this annotation is applied is immutable. This means that
17 | * its state cannot be seen to change by callers, which implies that
18 | *
19 | * - all public fields are final,
20 | * - all public final reference fields refer to other immutable objects, and
21 | * - constructors and methods do not publish references to any internal state
22 | * which is potentially mutable by the implementation.
23 | *
24 | * Immutable objects may still have internal mutable state for purposes of performance
25 | * optimization; some state variables may be lazily computed, so long as they are computed
26 | * from immutable state and that callers cannot tell the difference.
27 | *
28 | * Immutable objects are inherently thread-safe; they may be passed between threads or
29 | * published without synchronization.
30 | */
31 | @Documented
32 | @Target(ElementType.TYPE)
33 | @Retention(RetentionPolicy.RUNTIME)
34 | public @interface Immutable {
35 | }
36 |
--------------------------------------------------------------------------------
/src/client/edb.hpp:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Copyright (C) 2013 SequoiaDB Software Inc.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License, version 3,
6 | as published by the Free Software Foundation.
7 |
8 | This program is distributed in the hope that it will be useful,
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | GNU Affero General Public License for more details.
12 |
13 | You should have received a copy of the GNU Affero General Public License
14 | along with this program. If not, see .
15 | *******************************************************************************/
16 | #ifndef _EDB_HPP_
17 | #define _EDB_HPP_
18 |
19 | #include "core.hpp"
20 | #include "ossSocket.hpp"
21 | #include "commandFactory.hpp"
22 | const int CMD_BUFFER_SIZE = 512;
23 | class Edb {
24 | public:
25 | Edb(){}
26 | ~Edb(){};
27 | public:
28 | void start(void);
29 | protected:
30 | void prompt(void);
31 | private:
32 | void split(const std::string &text, char delim, std::vector &result);
33 | char* readLine(char *p, int length);
34 | int readInput(const char *pPrompt, int numIndent);
35 | private:
36 | ossSocket _sock;
37 | CommandFactory _cmdFactory;
38 | char _cmdBuffer[CMD_BUFFER_SIZE];
39 | };
40 |
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/JsonIOException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.google.gson;
17 |
18 | /**
19 | * This exception is raised when Gson was unable to read an input stream
20 | * or write to one.
21 | *
22 | * @author Inderjeet Singh
23 | * @author Joel Leitch
24 | */
25 | public final class JsonIOException extends JsonParseException {
26 | private static final long serialVersionUID = 1L;
27 |
28 | public JsonIOException(String msg) {
29 | super(msg);
30 | }
31 |
32 | public JsonIOException(String msg, Throwable cause) {
33 | super(msg, cause);
34 | }
35 |
36 | /**
37 | * Creates exception with the specified cause. Consider using
38 | * {@link #JsonIOException(String, Throwable)} instead if you can describe what happened.
39 | *
40 | * @param cause root exception that caused this exception to be thrown.
41 | */
42 | public JsonIOException(Throwable cause) {
43 | super(cause);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/JsonSyntaxException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.google.gson;
17 |
18 | /**
19 | * This exception is raised when Gson attempts to read (or write) a malformed
20 | * JSON element.
21 | *
22 | * @author Inderjeet Singh
23 | * @author Joel Leitch
24 | */
25 | public final class JsonSyntaxException extends JsonParseException {
26 |
27 | private static final long serialVersionUID = 1L;
28 |
29 | public JsonSyntaxException(String msg) {
30 | super(msg);
31 | }
32 |
33 | public JsonSyntaxException(String msg, Throwable cause) {
34 | super(msg, cause);
35 | }
36 |
37 | /**
38 | * Creates exception with the specified cause. Consider using
39 | * {@link #JsonSyntaxException(String, Throwable)} instead if you can
40 | * describe what actually happened.
41 | *
42 | * @param cause root exception that caused this exception to be thrown.
43 | */
44 | public JsonSyntaxException(Throwable cause) {
45 | super(cause);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/types/CodeWScope.java:
--------------------------------------------------------------------------------
1 | // CodeWScope.java
2 |
3 | /**
4 | * Copyright (C) 2008 10gen Inc.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package org.bson.types;
20 |
21 | import org.bson.*;
22 |
23 | /**
24 | * for using the CodeWScope type
25 | */
26 | public class CodeWScope extends Code {
27 |
28 | private static final long serialVersionUID = -6284832275113680002L;
29 |
30 | public CodeWScope( String code , BSONObject scope ){
31 | super( code );
32 | _scope = scope;
33 | }
34 |
35 | public BSONObject getScope(){
36 | return _scope;
37 | }
38 |
39 | public boolean equals( Object o ){
40 | if ( ! ( o instanceof CodeWScope ) )
41 | return false;
42 |
43 | CodeWScope c = (CodeWScope)o;
44 | return _code.equals( c._code ) && _scope.equals( c._scope );
45 | }
46 |
47 | public int hashCode(){
48 | return _code.hashCode() ^ _scope.hashCode();
49 | }
50 |
51 | final BSONObject _scope;
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/util/SimplePool.java:
--------------------------------------------------------------------------------
1 | // SimplePool.java
2 |
3 | /**
4 | * Copyright (C) 2008 10gen Inc.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package org.bson.util;
20 |
21 | import java.util.*;
22 | import java.util.concurrent.*;
23 |
24 | public abstract class SimplePool {
25 |
26 | public SimplePool( int max ){
27 | _max = max;
28 | }
29 |
30 | public SimplePool(){
31 | _max = 1000;
32 | }
33 |
34 | protected abstract T createNew();
35 |
36 | protected boolean ok( T t ){
37 | return true;
38 | }
39 |
40 | public T get(){
41 | T t = _stored.poll();
42 | if ( t != null )
43 | return t;
44 | return createNew();
45 | }
46 |
47 | public void done( T t ){
48 | if ( ! ok( t ) )
49 | return;
50 |
51 | if ( _stored.size() > _max )
52 | return;
53 | _stored.add( t );
54 | }
55 |
56 | final int _max;
57 | private Queue _stored = new ConcurrentLinkedQueue();
58 | }
59 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/types/Code.java:
--------------------------------------------------------------------------------
1 | // Code.java
2 |
3 | /**
4 | * Copyright (C) 2008 10gen Inc.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package org.bson.types;
20 |
21 | import java.io.Serializable;
22 | import java.util.*;
23 |
24 | import org.bson.*;
25 |
26 | /**
27 | * for using the Code type
28 | */
29 | public class Code implements Serializable {
30 |
31 | private static final long serialVersionUID = 475535263314046697L;
32 |
33 | public Code( String code ){
34 | _code = code;
35 | }
36 |
37 | public String getCode(){
38 | return _code;
39 | }
40 |
41 | public boolean equals( Object o ){
42 | if ( ! ( o instanceof Code ) )
43 | return false;
44 |
45 | Code c = (Code)o;
46 | return _code.equals( c._code );
47 | }
48 |
49 | public int hashCode(){
50 | return _code.hashCode();
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return getCode();
56 | }
57 |
58 | final String _code;
59 |
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/util/Assertions.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2008 Atlassian Pty Ltd
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bson.util;
18 |
19 | /**
20 | * Design by contract assertions.
21 | */
22 | public class Assertions {
23 | public static T notNull(final String name, final T notNull) throws IllegalArgumentException {
24 | if (notNull == null) {
25 | throw new NullArgumentException(name);
26 | }
27 | return notNull;
28 | }
29 |
30 | public static void isTrue(final String name, final boolean check) throws IllegalArgumentException {
31 | if (!check) {
32 | throw new IllegalArgumentException(name);
33 | }
34 | }
35 |
36 | // /CLOVER:OFF
37 | private Assertions() {}
38 |
39 | // /CLOVER:ON
40 |
41 | static class NullArgumentException extends IllegalArgumentException {
42 | private static final long serialVersionUID = 6178592463723624585L;
43 |
44 | NullArgumentException(final String name) {
45 | super(name + " should not be null!");
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/bson/src/util/json.h:
--------------------------------------------------------------------------------
1 | /** @file json.h */
2 |
3 | /**
4 | * Copyright (C) 2008 10gen Inc.
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License, version 3,
8 | * as published by the Free Software Foundation.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | #pragma once
20 |
21 | #include "../bson.h"
22 |
23 | namespace bson {
24 |
25 | /** Create a BSONObj from a JSON string. In addition
26 | to the JSON extensions extensions described here
27 | ,
28 | this function accepts certain unquoted field names and allows single quotes
29 | to optionally be used when specifying field names and string values instead
30 | of double quotes. JSON unicode escape sequences (of the form \uXXXX) are
31 | converted to utf8.
32 | \throws MsgAssertionException if parsing fails. The message included with
33 | this assertion includes a rough indication of where parsing failed.
34 | */
35 | BSONObj fromjson(const string &str);
36 |
37 | /** len will be size of JSON object in text chars. */
38 | BSONObj fromjson(const char *str, int* len=NULL);
39 |
40 | } // namespace mongo
41 |
--------------------------------------------------------------------------------
/src/client/commandFactory.hpp:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | Copyright (C) 2013 SequoiaDB Software Inc.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License, version 3,
6 | as published by the Free Software Foundation.
7 |
8 | This program is distributed in the hope that it will be useful,
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | GNU Affero General Public License for more details.
12 |
13 | You should have received a copy of the GNU Affero General Public License
14 | along with this program. If not, see .
15 | *******************************************************************************/
16 | #ifndef _COMMAND_FACTORY_HPP_
17 | #define _COMMAND_FACTORY_HPP_
18 |
19 | #include "command.hpp"
20 | #define COMMAND_BEGIN void CommandFactory::addCommand() {
21 | #define COMMAND_END }
22 | #define COMMAND_ADD(cmdName,cmdClass) { \
23 | ICommand* pObj = new cmdClass(); \
24 | std::string str = cmdName; \
25 | _cmdMap.insert(COMMAND_MAP::value_type(str,pObj)); \
26 | } \
27 |
28 | class CommandFactory {
29 | typedef std::map COMMAND_MAP;
30 | public:
31 | CommandFactory();
32 | ~CommandFactory(){}
33 | void addCommand();
34 | ICommand * getCommandProcesser(const char * pcmd);
35 | private:
36 | COMMAND_MAP _cmdMap;
37 | };
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/stream/MalformedJsonException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.stream;
18 |
19 | import java.io.IOException;
20 |
21 | /**
22 | * Thrown when a reader encounters malformed JSON. Some syntax errors can be
23 | * ignored by calling {@link JsonReader#setLenient(boolean)}.
24 | */
25 | public final class MalformedJsonException extends IOException {
26 | private static final long serialVersionUID = 1L;
27 |
28 | public MalformedJsonException(String msg) {
29 | super(msg);
30 | }
31 |
32 | public MalformedJsonException(String msg, Throwable throwable) {
33 | super(msg);
34 | // Using initCause() instead of calling super() because Java 1.5 didn't retrofit IOException
35 | // with a constructor with Throwable. This was done in Java 1.6
36 | initCause(throwable);
37 | }
38 |
39 | public MalformedJsonException(Throwable throwable) {
40 | // Using initCause() instead of calling super() because Java 1.5 didn't retrofit IOException
41 | // with a constructor with Throwable. This was done in Java 1.6
42 | initCause(throwable);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/emeralddb/exception/EDBError.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2012 SequoiaDB Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.emeralddb.exception;
17 |
18 | /**
19 | * @author Jacky Zhang
20 | *
21 | */
22 |
23 | public class EDBError {
24 | private String errorType;
25 | private int errorCode;
26 | private String errorDescription;
27 |
28 | /**
29 | * @return
30 | */
31 | public String getErrorType() {
32 | return errorType;
33 | }
34 |
35 | /**
36 | * @param errorType
37 | */
38 | public void setErrorType(String errorType) {
39 | this.errorType = errorType;
40 | }
41 |
42 | /**
43 | * @return
44 | */
45 | public int getErrorCode() {
46 | return errorCode;
47 | }
48 |
49 | /**
50 | * @param errorCode
51 | */
52 | public void setErrorCode(int errorCode) {
53 | this.errorCode = errorCode;
54 | }
55 |
56 | /**
57 | * @return
58 | */
59 | public String getErrorDescription() {
60 | return errorDescription;
61 | }
62 |
63 | /**
64 | * @param errorDescription
65 | */
66 | public void setErrorDescription(String errorDescription) {
67 | this.errorDescription = errorDescription;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/JsonNull.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | /**
20 | * A class representing a Json {@code null} value.
21 | *
22 | * @author Inderjeet Singh
23 | * @author Joel Leitch
24 | * @since 1.2
25 | */
26 | public final class JsonNull extends JsonElement {
27 | /**
28 | * singleton for JsonNull
29 | *
30 | * @since 1.8
31 | */
32 | public static final JsonNull INSTANCE = new JsonNull();
33 |
34 | /**
35 | * Creates a new JsonNull object.
36 | * Deprecated since Gson version 1.8. Use {@link #INSTANCE} instead
37 | */
38 | @Deprecated
39 | public JsonNull() {
40 | // Do nothing
41 | }
42 |
43 | @Override public JsonNull deepCopy() {
44 | return INSTANCE;
45 | }
46 |
47 | /**
48 | * All instances of JsonNull have the same hash code since they are indistinguishable
49 | */
50 | @Override
51 | public int hashCode() {
52 | return JsonNull.class.hashCode();
53 | }
54 |
55 | /**
56 | * All instances of JsonNull are the same
57 | */
58 | @Override
59 | public boolean equals(Object other) {
60 | return this == other || other instanceof JsonNull;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/JsonDeserializationContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | import java.lang.reflect.Type;
20 |
21 | /**
22 | * Context for deserialization that is passed to a custom deserializer during invocation of its
23 | * {@link JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)}
24 | * method.
25 | *
26 | * @author Inderjeet Singh
27 | * @author Joel Leitch
28 | */
29 | public interface JsonDeserializationContext {
30 |
31 | /**
32 | * Invokes default deserialization on the specified object. It should never be invoked on
33 | * the element received as a parameter of the
34 | * {@link JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext)} method. Doing
35 | * so will result in an infinite loop since Gson will in-turn call the custom deserializer again.
36 | *
37 | * @param json the parse tree.
38 | * @param typeOfT type of the expected return value.
39 | * @param The type of the deserialized object.
40 | * @return An object of type typeOfT.
41 | * @throws JsonParseException if the parse tree does not contain expected data.
42 | */
43 | public T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
44 | }
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/util/JSONParseException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2008 10gen Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bson.util;
18 |
19 | /**
20 | * Exception throw when invalid JSON is passed to JSONParser.
21 | *
22 | * This exception creates a message that points to the first
23 | * offending character in the JSON string:
24 | *
25 | * { "x" : 3, "y" : 4, some invalid json.... }
26 | * ^
27 | *
28 | */
29 | public class JSONParseException extends RuntimeException {
30 |
31 | private static final long serialVersionUID = -4415279469780082174L;
32 |
33 | String s;
34 | int pos;
35 |
36 | public String getMessage() {
37 | StringBuilder sb = new StringBuilder();
38 | sb.append("\n");
39 | sb.append(s);
40 | sb.append("\n");
41 | for(int i=0;i
22 | #include
23 |
24 | namespace md5 {
25 |
26 | typedef unsigned char md5digest[16];
27 |
28 | inline void md5(const void *buf, int nbytes, md5digest digest) {
29 | md5_state_t st;
30 | md5_init(&st);
31 | md5_append(&st, (const md5_byte_t *) buf, nbytes);
32 | md5_finish(&st, digest);
33 | }
34 |
35 | inline void md5(const char *str, md5digest digest) {
36 | md5(str, strlen(str), digest);
37 | }
38 |
39 | inline std::string digestToString( md5digest digest ){
40 | static const char * letters = "0123456789abcdef";
41 | std::stringstream ss;
42 | for ( int i=0; i<16; i++){
43 | unsigned char c = digest[i];
44 | ss << letters[ ( c >> 4 ) & 0xf ] << letters[ c & 0xf ];
45 | }
46 | return ss.str();
47 | }
48 |
49 | inline std::string md5simpledigest( const void* buf, int nbytes){
50 | md5digest d;
51 | md5( buf, nbytes , d );
52 | return digestToString( d );
53 | }
54 |
55 | inline std::string md5simpledigest( std::string s ){
56 | return md5simpledigest(s.data(), s.size());
57 | }
58 |
59 |
60 | } // namespace md5
61 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/emeralddb/util/HashAlgorithm.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2012 SequoiaDB Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.emeralddb.util;
17 |
18 | import java.io.UnsupportedEncodingException;
19 | import java.security.MessageDigest;
20 | import java.security.NoSuchAlgorithmException;
21 | /***
22 | *
23 | * @author zhouzhengle
24 | *
25 | */
26 | public enum HashAlgorithm {
27 | /***
28 | * MD5-based hash algorithm used by ketama.
29 | */
30 | KETAMA_HASH;
31 |
32 | public long hash( byte[] digest, int nTime ) {
33 | long rv = ( (long) (digest[3 + nTime*4] & 0xFF) << 24 )
34 | | ( (long) (digest[2 + nTime*4] & 0xFF ) << 16 )
35 | | ( (long) (digest[1 + nTime*4] & 0xFF) << 8 )
36 | | (digest[0 + nTime*4] & 0xFF);
37 | return rv & 0xFFFFFFFFL;
38 | }
39 |
40 | /***
41 | * Get the md5 of the given key.
42 | */
43 | public byte[] md5(String k) {
44 | MessageDigest md5;
45 | try {
46 | md5 = MessageDigest.getInstance("MD5");
47 | } catch( NoSuchAlgorithmException e ) {
48 | throw new RuntimeException("MD5 not supported", e);
49 | }
50 |
51 | md5.reset();
52 | byte[] keyBytes = null;
53 | try {
54 | keyBytes = k.getBytes("UTF-8");
55 | } catch( UnsupportedEncodingException e ) {
56 | throw new RuntimeException("Unknown string :" + k, e);
57 | }
58 |
59 | md5.update(keyBytes);
60 | return md5.digest();
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/LongSerializationPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | /**
20 | * Defines the expected format for a {@code long} or {@code Long} type when its serialized.
21 | *
22 | * @since 1.3
23 | *
24 | * @author Inderjeet Singh
25 | * @author Joel Leitch
26 | */
27 | public enum LongSerializationPolicy {
28 | /**
29 | * This is the "default" serialization policy that will output a {@code long} object as a JSON
30 | * number. For example, assume an object has a long field named "f" then the serialized output
31 | * would be:
32 | * {@code {"f":123}}.
33 | */
34 | DEFAULT() {
35 | public JsonElement serialize(Long value) {
36 | return new JsonPrimitive(value);
37 | }
38 | },
39 |
40 | /**
41 | * Serializes a long value as a quoted string. For example, assume an object has a long field
42 | * named "f" then the serialized output would be:
43 | * {@code {"f":"123"}}.
44 | */
45 | STRING() {
46 | public JsonElement serialize(Long value) {
47 | return new JsonPrimitive(String.valueOf(value));
48 | }
49 | };
50 |
51 | /**
52 | * Serialize this {@code value} using this serialization policy.
53 | *
54 | * @param value the long value to be serialized into a {@link JsonElement}
55 | * @return the serialized version of {@code value}
56 | */
57 | public abstract JsonElement serialize(Long value);
58 | }
59 |
--------------------------------------------------------------------------------
/src/include/pmdEDUEvent.hpp:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Copyright (C) 2013 SequoiaDB Software Inc.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License, version 3,
6 | as published by the Free Software Foundation.
7 |
8 | This program is distributed in the hope that it will be useful,
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | GNU Affero General Public License for more details.
12 |
13 | You should have received a copy of the GNU Affero General Public License
14 | along with this program. If not, see .
15 | *******************************************************************************/
16 | #ifndef PMDEDUEVENT_HPP__
17 | #define PMDEDUEVENT_HPP__
18 |
19 | #include "core.hpp"
20 | enum pmdEDUEventTypes
21 | {
22 | PMD_EDU_EVENT_NONE = 0,
23 | PMD_EDU_EVENT_TERM, // terminate EDU
24 | PMD_EDU_EVENT_RESUME, // resume a EDU, the data is startEDU's argv
25 | PMD_EDU_EVENT_ACTIVE,
26 | PMD_EDU_EVENT_DEACTIVE,
27 | PMD_EDU_EVENT_MSG,
28 | PMD_EDU_EVENT_TIMEOUT, // timeout
29 | PMD_EDU_EVENT_LOCKWAKEUP // transaction lock wake up
30 | } ;
31 |
32 | class pmdEDUEvent
33 | {
34 | public :
35 | pmdEDUEvent () :
36 | _eventType(PMD_EDU_EVENT_NONE),
37 | _release(false),
38 | _Data(NULL)
39 | {
40 | }
41 |
42 | pmdEDUEvent ( pmdEDUEventTypes type ) :
43 | _eventType(type),
44 | _release(false),
45 | _Data(NULL)
46 | {
47 | }
48 |
49 | pmdEDUEvent ( pmdEDUEventTypes type, bool release, void *data ) :
50 | _eventType(type),
51 | _release(release),
52 | _Data(data)
53 | {
54 | }
55 |
56 | void reset ()
57 | {
58 | _eventType = PMD_EDU_EVENT_NONE ;
59 | _release = false ;
60 | _Data = NULL ;
61 | }
62 |
63 | pmdEDUEventTypes _eventType ;
64 | bool _release ;
65 | void *_Data ;
66 | } ;
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/JsonSerializationContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | import java.lang.reflect.Type;
20 |
21 | /**
22 | * Context for serialization that is passed to a custom serializer during invocation of its
23 | * {@link JsonSerializer#serialize(Object, Type, JsonSerializationContext)} method.
24 | *
25 | * @author Inderjeet Singh
26 | * @author Joel Leitch
27 | */
28 | public interface JsonSerializationContext {
29 |
30 | /**
31 | * Invokes default serialization on the specified object.
32 | *
33 | * @param src the object that needs to be serialized.
34 | * @return a tree of {@link JsonElement}s corresponding to the serialized form of {@code src}.
35 | */
36 | public JsonElement serialize(Object src);
37 |
38 | /**
39 | * Invokes default serialization on the specified object passing the specific type information.
40 | * It should never be invoked on the element received as a parameter of the
41 | * {@link JsonSerializer#serialize(Object, Type, JsonSerializationContext)} method. Doing
42 | * so will result in an infinite loop since Gson will in-turn call the custom serializer again.
43 | *
44 | * @param src the object that needs to be serialized.
45 | * @param typeOfSrc the actual genericized type of src object.
46 | * @return a tree of {@link JsonElement}s corresponding to the serialized form of {@code src}.
47 | */
48 | public JsonElement serialize(Object src, Type typeOfSrc);
49 | }
50 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/types/Symbol.java:
--------------------------------------------------------------------------------
1 | // Symbol.java
2 |
3 | /**
4 | * Copyright (C) 2009 10gen Inc.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package org.bson.types;
20 |
21 | import java.io.Serializable;
22 |
23 | /**
24 | * Class to hold a BSON symbol object, which is an interned string in Ruby
25 | */
26 | public class Symbol implements Serializable {
27 |
28 | private static final long serialVersionUID = 1326269319883146072L;
29 |
30 | public Symbol(String s) {
31 | _symbol = s;
32 | }
33 |
34 | public String getSymbol(){
35 | return _symbol;
36 | }
37 |
38 | /**
39 | * Will compare equal to a String that is equal to the String that this holds
40 | * @param o
41 | * @return
42 | */
43 | @Override
44 | public boolean equals(Object o) {
45 | if (this == o) return true;
46 | if (o == null) return false;
47 |
48 | String otherSymbol;
49 | if (o instanceof Symbol) {
50 | otherSymbol = ((Symbol) o)._symbol;
51 | }
52 | else if (o instanceof String) {
53 | otherSymbol = (String) o;
54 | }
55 | else {
56 | return false;
57 | }
58 |
59 | if (_symbol != null ? !_symbol.equals(otherSymbol) : otherSymbol != null) return false;
60 |
61 | return true;
62 | }
63 |
64 | @Override
65 | public int hashCode() {
66 | return _symbol != null ? _symbol.hashCode() : 0;
67 | }
68 |
69 | public String toString(){
70 | return _symbol;
71 | }
72 |
73 | private final String _symbol;
74 | }
75 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/util/annotations/GuardedBy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2005 Brian Goetz and Tim Peierls
3 | * Released under the Creative Commons Attribution License
4 | * (http://creativecommons.org/licenses/by/2.5)
5 | * Official home: http://www.jcip.net
6 | *
7 | * Any republication or derived work distributed in source code form
8 | * must include this copyright and license notice.
9 | */
10 |
11 | package org.bson.util.annotations;
12 |
13 | import java.lang.annotation.ElementType;
14 | import java.lang.annotation.Retention;
15 | import java.lang.annotation.RetentionPolicy;
16 | import java.lang.annotation.Target;
17 |
18 | /**
19 | * The field or method to which this annotation is applied can only be accessed
20 | * when holding a particular lock, which may be a built-in (synchronization) lock,
21 | * or may be an explicit java.util.concurrent.Lock.
22 | *
23 | * The argument determines which lock guards the annotated field or method:
24 | *
25 | * -
26 | *
this : The intrinsic lock of the object in whose class the field is defined.
27 | *
28 | * -
29 | *
class-name.this : For inner classes, it may be necessary to disambiguate 'this';
30 | * the class-name.this designation allows you to specify which 'this' reference is intended
31 | *
32 | * -
33 | *
itself : For reference fields only; the object to which the field refers.
34 | *
35 | * -
36 | *
field-name : The lock object is referenced by the (instance or static) field
37 | * specified by field-name.
38 | *
39 | * -
40 | *
class-name.field-name : The lock object is reference by the static field specified
41 | * by class-name.field-name.
42 | *
43 | * -
44 | *
method-name() : The lock object is returned by calling the named nil-ary method.
45 | *
46 | * -
47 | *
class-name.class : The Class object for the specified class should be used as the lock object.
48 | *
49 | */
50 | @Target({ElementType.FIELD, ElementType.METHOD})
51 | @Retention(RetentionPolicy.RUNTIME)
52 | public @interface GuardedBy {
53 | String value();
54 | }
55 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/stream/JsonScope.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.stream;
18 |
19 | /**
20 | * Lexical scoping elements within a JSON reader or writer.
21 | *
22 | * @author Jesse Wilson
23 | * @since 1.6
24 | */
25 | final class JsonScope {
26 |
27 | /**
28 | * An array with no elements requires no separators or newlines before
29 | * it is closed.
30 | */
31 | static final int EMPTY_ARRAY = 1;
32 |
33 | /**
34 | * A array with at least one value requires a comma and newline before
35 | * the next element.
36 | */
37 | static final int NONEMPTY_ARRAY = 2;
38 |
39 | /**
40 | * An object with no name/value pairs requires no separators or newlines
41 | * before it is closed.
42 | */
43 | static final int EMPTY_OBJECT = 3;
44 |
45 | /**
46 | * An object whose most recent element is a key. The next element must
47 | * be a value.
48 | */
49 | static final int DANGLING_NAME = 4;
50 |
51 | /**
52 | * An object with at least one name/value pair requires a comma and
53 | * newline before the next element.
54 | */
55 | static final int NONEMPTY_OBJECT = 5;
56 |
57 | /**
58 | * No object or array has been started.
59 | */
60 | static final int EMPTY_DOCUMENT = 6;
61 |
62 | /**
63 | * A document with at an array or object.
64 | */
65 | static final int NONEMPTY_DOCUMENT = 7;
66 |
67 | /**
68 | * A document that's been closed and cannot be accessed.
69 | */
70 | static final int CLOSED = 8;
71 | }
72 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/stream/StringPool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.stream;
18 |
19 | /**
20 | * A pool of string instances. Unlike the {@link String#intern() VM's
21 | * interned strings}, this pool provides no guarantee of reference equality.
22 | * It is intended only to save allocations. This class is not thread safe.
23 | */
24 | final class StringPool {
25 |
26 | private final String[] pool = new String[512];
27 |
28 | /**
29 | * Returns a string equal to {@code new String(array, start, length)}.
30 | */
31 | public String get(char[] array, int start, int length) {
32 | // Compute an arbitrary hash of the content
33 | int hashCode = 0;
34 | for (int i = start; i < start + length; i++) {
35 | hashCode = (hashCode * 31) + array[i];
36 | }
37 |
38 | // Pick a bucket using Doug Lea's supplemental secondaryHash function (from HashMap)
39 | hashCode ^= (hashCode >>> 20) ^ (hashCode >>> 12);
40 | hashCode ^= (hashCode >>> 7) ^ (hashCode >>> 4);
41 | int index = hashCode & (pool.length - 1);
42 |
43 | String pooled = pool[index];
44 | if (pooled == null || pooled.length() != length) {
45 | String result = new String(array, start, length);
46 | pool[index] = result;
47 | return result;
48 | }
49 |
50 | for (int i = 0; i < length; i++) {
51 | if (pooled.charAt(i) != array[start + i]) {
52 | String result = new String(array, start, length);
53 | pool[index] = result;
54 | return result;
55 | }
56 | }
57 |
58 | return pooled;
59 | }
60 | }
--------------------------------------------------------------------------------
/src/bson/src/lib/base64.h:
--------------------------------------------------------------------------------
1 | // util/base64.h
2 |
3 | /* Copyright 2009 10gen Inc.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | namespace base64 {
27 |
28 | class Alphabet {
29 | public:
30 | Alphabet()
31 | : encode((unsigned char*)
32 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
33 | "abcdefghijklmnopqrstuvwxyz"
34 | "0123456789"
35 | "+/")
36 | , decode(new unsigned char[257]) {
37 | memset( decode.get() , 0 , 256 );
38 | for ( int i=0; i<64; i++ ) {
39 | decode[ encode[i] ] = i;
40 | }
41 |
42 | test();
43 | }
44 | void test() {
45 | assert( strlen( (char*)encode ) == 64 );
46 | for ( int i=0; i<26; i++ )
47 | assert( encode[i] == toupper( encode[i+26] ) );
48 | }
49 |
50 | char e( int x ) {
51 | return encode[x&0x3f];
52 | }
53 |
54 | private:
55 | const unsigned char * encode;
56 | public:
57 | boost::scoped_array decode;
58 | };
59 |
60 | extern Alphabet alphabet;
61 |
62 | void encode( std::stringstream& ss , const char * data , int size );
63 | std::string encode( const char * data , int size );
64 | std::string encode( const std::string& s );
65 |
66 | void decode( std::stringstream& ss , const std::string& s );
67 | std::string decode( const std::string& s );
68 |
69 | void testAlphabet();
70 | }
71 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/BSONException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2011, 10gen Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.bson;
18 |
19 | /**
20 | * A general runtime exception raised in BSON processing.
21 | */
22 | public class BSONException extends RuntimeException {
23 |
24 | private static final long serialVersionUID = -4415279469780082174L;
25 |
26 | /**
27 | * @param msg The error message.
28 | */
29 | public BSONException( final String msg ) {
30 | super( msg );
31 | }
32 |
33 | /**
34 | * @param errorCode The error code.
35 | * @param msg The error message.
36 | */
37 | public BSONException( final int errorCode, final String msg ) {
38 | super( msg );
39 | _errorCode = errorCode;
40 | }
41 |
42 | /**
43 | * @param msg The error message.
44 | * @param t The throwable cause.
45 | */
46 | public BSONException( final String msg , final Throwable t ) {
47 | super( msg, t );
48 | }
49 |
50 | /**
51 | * @param errorCode The error code.
52 | * @param msg The error message.
53 | * @param t The throwable cause.
54 | */
55 | public BSONException( final int errorCode, final String msg, final Throwable t ) {
56 | super( msg, t );
57 | _errorCode = errorCode;
58 | }
59 |
60 | /**
61 | * Returns the error code.
62 | * @return The error code.
63 | */
64 | public Integer getErrorCode() { return _errorCode; }
65 |
66 | /**
67 | * Returns true if the error code is set (i.e., not null).
68 | */
69 | public boolean hasErrorCode() { return (_errorCode != null); }
70 |
71 | private Integer _errorCode = null;
72 | }
73 |
74 |
--------------------------------------------------------------------------------
/src/bson/src/ordering.h:
--------------------------------------------------------------------------------
1 | // ordering.h
2 |
3 | /* Copyright 2009 10gen Inc.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | namespace bson {
21 |
22 | /** A precomputation of a BSON key pattern.
23 | The constructor is private to make conversion more explicit so we notice
24 | where we call make(). Over time we should push this up higher and
25 | higher.
26 | */
27 | class Ordering {
28 | const unsigned bits;
29 | const unsigned nkeys;
30 | Ordering(unsigned b,unsigned n) : bits(b),nkeys(n) { }
31 | public:
32 | /** so, for key pattern { a : 1, b : -1 }
33 | get(0) == 1
34 | get(1) == -1
35 | */
36 | int get(int i) const {
37 | return ((1 << i) & bits) ? -1 : 1;
38 | }
39 |
40 | // for woCompare...
41 | unsigned descending(unsigned mask) const { return bits & mask; }
42 |
43 | operator string() const {
44 | StringBuilder buf(32);
45 | for ( unsigned i=0; i 0 ? "+" : "-" );
47 | return buf.str();
48 | }
49 |
50 | static Ordering make(const BSONObj& obj) {
51 | unsigned b = 0;
52 | BSONObjIterator k(obj);
53 | unsigned n = 0;
54 | while( 1 ) {
55 | BSONElement e = k.next();
56 | if( e.eoo() )
57 | break;
58 | uassert( 13103, "too many compound keys", n <= 31 );
59 | if( e.number() < 0 )
60 | b |= (1 << n);
61 | n++;
62 | }
63 | return Ordering(b,n);
64 | }
65 | };
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/util/ClassAncestry.java:
--------------------------------------------------------------------------------
1 | package org.bson.util;
2 |
3 | import static java.util.Collections.unmodifiableList;
4 | import static org.bson.util.CopyOnWriteMap.newHashMap;
5 |
6 | import java.util.ArrayList;
7 | import java.util.Collections;
8 | import java.util.List;
9 | import java.util.concurrent.ConcurrentMap;
10 |
11 | class ClassAncestry {
12 | private static final ConcurrentMap, List>> _ancestryCache = newHashMap();
13 |
14 | /**
15 | * getAncestry
16 | *
17 | * Walks superclass and interface graph, superclasses first, then
18 | * interfaces, to compute an ancestry list. Supertypes are visited left to
19 | * right. Duplicates are removed such that no Class will appear in the list
20 | * before one of its subtypes.
21 | *
22 | * Does not need to be synchronized, races are harmless as the Class graph
23 | * does not change at runtime.
24 | */
25 | public static List> getAncestry(Class c) {
26 | final ConcurrentMap, List>> cache = getClassAncestryCache();
27 | while (true) {
28 | List> cachedResult = cache.get(c);
29 | if (cachedResult != null) { return cachedResult; }
30 | cache.putIfAbsent(c, computeAncestry(c));
31 | }
32 | }
33 |
34 | /**
35 | * computeAncestry, starting with children and going back to parents
36 | */
37 | private static List> computeAncestry(Class> c) {
38 | final List> result = new ArrayList>();
39 | result.add(Object.class);
40 | computeAncestry(c, result);
41 | Collections.reverse(result);
42 | return unmodifiableList(new ArrayList>(result));
43 | }
44 |
45 | private static void computeAncestry(Class c, List> result) {
46 | if ((c == null) || (c == Object.class)) { return; }
47 |
48 | // first interfaces (looks backwards but is not)
49 | Class>[] interfaces = c.getInterfaces();
50 | for (int i = interfaces.length - 1; i >= 0; i--) {
51 | computeAncestry(interfaces[i], result);
52 | }
53 |
54 | // next superclass
55 | computeAncestry(c.getSuperclass(), result);
56 |
57 | if (!result.contains(c)) result.add(c);
58 | }
59 |
60 | /**
61 | * classAncestryCache
62 | */
63 | private static ConcurrentMap, List>> getClassAncestryCache() {
64 | return (_ancestryCache);
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/bson/src/util/hex.h:
--------------------------------------------------------------------------------
1 | // util/hex.h
2 |
3 | /* Copyright 2009 10gen Inc.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #pragma once
19 |
20 | #include "../bsonassert.h"
21 | #include "builder.h"
22 |
23 | namespace bson {
24 |
25 | //can't use hex namespace because it conflicts with hex iostream function
26 | inline int fromHex( char c ) {
27 | if ( '0' <= c && c <= '9' )
28 | return c - '0';
29 | if ( 'a' <= c && c <= 'f' )
30 | return c - 'a' + 10;
31 | if ( 'A' <= c && c <= 'F' )
32 | return c - 'A' + 10;
33 | assert( false );
34 | return 0xff;
35 | }
36 | inline char fromHex( const char *c ) {
37 | return (char)(( fromHex( c[ 0 ] ) << 4 ) | fromHex( c[ 1 ] ));
38 | }
39 |
40 | inline string toHex(const void* inRaw, int len) {
41 | static const char hexchars[] = "0123456789ABCDEF";
42 |
43 | StringBuilder out;
44 | const char* in = reinterpret_cast(inRaw);
45 | for (int i=0; i> 4];
48 | char lo = hexchars[(c & 0x0F)];
49 |
50 | out << hi << lo;
51 | }
52 |
53 | return out.str();
54 | }
55 |
56 | inline string toHexLower(const void* inRaw, int len) {
57 | static const char hexchars[] = "0123456789abcdef";
58 |
59 | StringBuilder out;
60 | const char* in = reinterpret_cast(inRaw);
61 | for (int i=0; i> 4];
64 | char lo = hexchars[(c & 0x0F)];
65 |
66 | out << hi << lo;
67 | }
68 |
69 | return out.str();
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/BSONCallback.java:
--------------------------------------------------------------------------------
1 | // BSONCallback.java
2 |
3 | /**
4 | * Copyright (C) 2008 10gen Inc.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package org.bson;
20 |
21 | import org.bson.types.ObjectId;
22 |
23 | public interface BSONCallback {
24 |
25 | void objectStart();
26 | void objectStart(String name);
27 | void objectStart(boolean array);
28 | Object objectDone();
29 |
30 | void reset();
31 | Object get();
32 | BSONCallback createBSONCallback();
33 |
34 | void arrayStart();
35 | void arrayStart(String name);
36 | Object arrayDone();
37 |
38 | void gotNull( String name );
39 | void gotUndefined( String name );
40 | void gotMinKey( String name );
41 | void gotMaxKey( String name );
42 |
43 | void gotBoolean( String name , boolean v );
44 | void gotDouble( String name , double v );
45 | void gotInt( String name , int v );
46 | void gotLong( String name , long v );
47 |
48 | void gotDate( String name , long millis );
49 | void gotString( String name , String v );
50 | void gotSymbol( String name , String v );
51 | void gotRegex( String name , String pattern , String flags );
52 |
53 | void gotTimestamp( String name , int time , int inc );
54 | void gotObjectId( String name , ObjectId id );
55 | void gotDBRef( String name , String ns , ObjectId id );
56 |
57 | /**
58 | *
59 | */
60 | @Deprecated
61 | void gotBinaryArray( String name , byte[] data );
62 | void gotBinary( String name , byte type , byte[] data );
63 | /**
64 | * subtype 3
65 | */
66 | void gotUUID( String name , long part1, long part2);
67 |
68 | void gotCode( String name , String code );
69 | void gotCodeWScope( String name , String code , Object scope );
70 | }
71 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/internal/LazilyParsedNumber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.google.gson.internal;
17 |
18 | import java.io.ObjectStreamException;
19 | import java.math.BigDecimal;
20 | import java.math.BigInteger;
21 |
22 | /**
23 | * This class holds a number value that is lazily converted to a specific number type
24 | *
25 | * @author Inderjeet Singh
26 | */
27 | @SuppressWarnings("serial")
28 | public final class LazilyParsedNumber extends Number {
29 | private final String value;
30 |
31 | public LazilyParsedNumber(String value) {
32 | this.value = value;
33 | }
34 |
35 | @Override
36 | public int intValue() {
37 | try {
38 | return Integer.parseInt(value);
39 | } catch (NumberFormatException e) {
40 | try {
41 | return (int) Long.parseLong(value);
42 | } catch (NumberFormatException nfe) {
43 | return new BigInteger(value).intValue();
44 | }
45 | }
46 | }
47 |
48 | @Override
49 | public long longValue() {
50 | try {
51 | return Long.parseLong(value);
52 | } catch (NumberFormatException e) {
53 | return new BigInteger(value).longValue();
54 | }
55 | }
56 |
57 | @Override
58 | public float floatValue() {
59 | return Float.parseFloat(value);
60 | }
61 |
62 | @Override
63 | public double doubleValue() {
64 | return Double.parseDouble(value);
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return value;
70 | }
71 |
72 | /**
73 | * If somebody is unlucky enough to have to serialize one of these, serialize
74 | * it as a BigDecimal so that they won't need Gson on the other side to
75 | * deserialize it.
76 | */
77 | private Object writeReplace() throws ObjectStreamException {
78 | return new BigDecimal(value);
79 | }
80 | }
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/stream/JsonToken.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.stream;
18 |
19 | /**
20 | * A structure, name or value type in a JSON-encoded string.
21 | *
22 | * @author Jesse Wilson
23 | * @since 1.6
24 | */
25 | public enum JsonToken {
26 |
27 | /**
28 | * The opening of a JSON array. Written using {@link JsonWriter#beginObject}
29 | * and read using {@link JsonReader#beginObject}.
30 | */
31 | BEGIN_ARRAY,
32 |
33 | /**
34 | * The closing of a JSON array. Written using {@link JsonWriter#endArray}
35 | * and read using {@link JsonReader#endArray}.
36 | */
37 | END_ARRAY,
38 |
39 | /**
40 | * The opening of a JSON object. Written using {@link JsonWriter#beginObject}
41 | * and read using {@link JsonReader#beginObject}.
42 | */
43 | BEGIN_OBJECT,
44 |
45 | /**
46 | * The closing of a JSON object. Written using {@link JsonWriter#endObject}
47 | * and read using {@link JsonReader#endObject}.
48 | */
49 | END_OBJECT,
50 |
51 | /**
52 | * A JSON property name. Within objects, tokens alternate between names and
53 | * their values. Written using {@link JsonWriter#name} and read using {@link
54 | * JsonReader#nextName}
55 | */
56 | NAME,
57 |
58 | /**
59 | * A JSON string.
60 | */
61 | STRING,
62 |
63 | /**
64 | * A JSON number represented in this API by a Java {@code double}, {@code
65 | * long}, or {@code int}.
66 | */
67 | NUMBER,
68 |
69 | /**
70 | * A JSON {@code true} or {@code false}.
71 | */
72 | BOOLEAN,
73 |
74 | /**
75 | * A JSON {@code null}.
76 | */
77 | NULL,
78 |
79 | /**
80 | * The end of the JSON stream. This sentinel value is returned by {@link
81 | * JsonReader#peek()} to signal that the JSON-encoded value has no more
82 | * tokens.
83 | */
84 | END_DOCUMENT
85 | }
86 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/emeralddb/util/KetamaNodeLocator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2012 SequoiaDB Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.emeralddb.util;
17 |
18 | import java.util.List;
19 | import java.util.SortedMap;
20 | import java.util.TreeMap;
21 | import com.emeralddb.net.ServerAddress;
22 | public final class KetamaNodeLocator {
23 | private TreeMap _ketamaNodes;
24 | private HashAlgorithm _hashAlg;
25 | private int _numReps = 160;
26 |
27 | public KetamaNodeLocator(List nodeList, HashAlgorithm alg, int nodeCopies) {
28 | _hashAlg = alg;
29 | _ketamaNodes = new TreeMap();
30 |
31 | _numReps = nodeCopies;
32 |
33 | for(ServerAddress node : nodeList) {
34 | for(int i=0; i<_numReps/4; i++) {
35 | byte[] digest = _hashAlg.md5(node.getHost() + ":" + node.getPort() + i);
36 | for(int h=0; h<4; h++) {
37 | long m = _hashAlg.hash(digest,h);
38 | _ketamaNodes.put(m, node);
39 | }
40 | }
41 | }
42 | }
43 |
44 | public ServerAddress getPrimary(final String str) {
45 | byte[] digest = _hashAlg.md5(str);
46 | ServerAddress rv = getNodeForKey(_hashAlg.hash(digest, 0));
47 | return rv;
48 | }
49 |
50 | ServerAddress getNodeForKey(long hash) {
51 | final ServerAddress rv;
52 | Long key = hash;
53 | if(_ketamaNodes.isEmpty()) {
54 | return null;
55 | }
56 | if(!_ketamaNodes.containsKey(key)) {
57 | SortedMap tailMap = _ketamaNodes.tailMap(key);
58 | if(tailMap.isEmpty()) {
59 | key = _ketamaNodes.firstKey();
60 | } else {
61 | key = tailMap.firstKey();
62 | }
63 | }
64 | rv = _ketamaNodes.get(key);
65 | return rv;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/driver/java/src/org/bson/types/BSONTimestamp.java:
--------------------------------------------------------------------------------
1 | // BSONTimestamp.java
2 |
3 | /**
4 | * Copyright (C) 2008 10gen Inc.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | package org.bson.types;
20 |
21 | import java.io.Serializable;
22 | import java.util.Date;
23 |
24 | /**
25 | * this is used for internal increment values.
26 | * for storing normal dates in MongoDB, you should use java.util.Date
27 | * time is seconds since epoch
28 | * inc is an ordinal
29 | */
30 | public class BSONTimestamp implements Serializable {
31 |
32 | private static final long serialVersionUID = -3268482672267936464L;
33 |
34 | static final boolean D = Boolean.getBoolean( "DEBUG.DBTIMESTAMP" );
35 |
36 | public BSONTimestamp(){
37 | _inc = 0;
38 | _time = null;
39 | }
40 |
41 | public BSONTimestamp(int time, int inc ){
42 | _time = new Date( time * 1000L );
43 | _inc = inc;
44 | }
45 |
46 | /**
47 | * @return get time in seconds since epoch
48 | */
49 | public int getTime(){
50 | if ( _time == null )
51 | return 0;
52 | return (int)(_time.getTime() / 1000);
53 | }
54 |
55 | public int getInc(){
56 | return _inc;
57 | }
58 |
59 | public String toString(){
60 | return "TS time:" + _time + " inc:" + _inc;
61 | }
62 |
63 | public Date getDate() {
64 | if(_time == null)
65 | return null;
66 | return _time;
67 | }
68 |
69 | @Override
70 | public boolean equals(Object obj) {
71 | if (obj == this)
72 | return true;
73 | if (obj instanceof BSONTimestamp) {
74 | BSONTimestamp t2 = (BSONTimestamp) obj;
75 | return getTime() == t2.getTime() && getInc() == t2.getInc();
76 | }
77 | return false;
78 | }
79 |
80 | final int _inc;
81 | final Date _time;
82 | }
83 |
--------------------------------------------------------------------------------
/src/oss/ossHash.cpp:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Copyright (C) 2013 SequoiaDB Software Inc.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License, version 3,
6 | as published by the Free Software Foundation.
7 |
8 | This program is distributed in the hope that it will be useful,
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | GNU Affero General Public License for more details.
12 |
13 | You should have received a copy of the GNU Affero General Public License
14 | along with this program. If not, see .
15 | *******************************************************************************/
16 | #include "ossHash.hpp"
17 | #include "pd.hpp"
18 | #undef get16bits
19 | #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
20 | || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
21 | #define get16bits(d) (*((const unsigned short *) (d)))
22 | #endif
23 |
24 | #if !defined (get16bits)
25 | #define get16bits(d) ((((unsigned int)(((const unsigned char *)(d))[1])) << 8)\
26 | +(unsigned int)(((const unsigned char *)(d))[0]) )
27 | #endif
28 | unsigned int ossHash ( const char *data, int len )
29 | {
30 | unsigned int hash = len, tmp ;
31 | int rem ;
32 | if ( len <= 0 || data == NULL ) return 0 ;
33 | rem = len&3 ;
34 | len >>= 2 ;
35 | for (; len > 0 ; --len )
36 | {
37 | hash += get16bits (data) ;
38 | tmp = (get16bits (data+2) << 11) ^ hash;
39 | hash = (hash<<16)^tmp ;
40 | data += 2*sizeof(unsigned short) ;
41 | hash += hash>>11 ;
42 | }
43 | switch ( rem )
44 | {
45 | case 3:
46 | hash += get16bits (data) ;
47 | hash ^= hash<<16 ;
48 | hash ^= ((char)data[sizeof (unsigned short)])<<18 ;
49 | hash += hash>>11 ;
50 | break ;
51 | case 2:
52 | hash += get16bits(data) ;
53 | hash ^= hash <<11 ;
54 | hash += hash >>17 ;
55 | break ;
56 | case 1:
57 | hash += (char)*data ;
58 | hash ^= hash<<10 ;
59 | hash += hash>>1 ;
60 | }
61 | hash ^= hash<<3 ;
62 | hash += hash>>5 ;
63 | hash ^= hash<<4 ;
64 | hash += hash>>17 ;
65 | hash ^= hash<<25 ;
66 | hash += hash>>6 ;
67 | return hash ;
68 | }
69 | #undef get16bits
70 |
71 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/annotations/Since.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.annotations;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | /**
25 | * An annotation that indicates the version number since a member or a type has been present.
26 | * This annotation is useful to manage versioning of your Json classes for a web-service.
27 | *
28 | *
29 | * This annotation has no effect unless you build {@link com.google.gson.Gson} with a
30 | * {@link com.google.gson.GsonBuilder} and invoke
31 | * {@link com.google.gson.GsonBuilder#setVersion(double)} method.
32 | *
33 | *
Here is an example of how this annotation is meant to be used:
34 | *
35 | * public class User {
36 | * private String firstName;
37 | * private String lastName;
38 | * @Since(1.0) private String emailAddress;
39 | * @Since(1.0) private String password;
40 | * @Since(1.1) private Address address;
41 | * }
42 | *
43 | *
44 | * If you created Gson with {@code new Gson()}, the {@code toJson()} and {@code fromJson()}
45 | * methods will use all the fields for serialization and deserialization. However, if you created
46 | * Gson with {@code Gson gson = new GsonBuilder().setVersion(1.0).create()} then the
47 | * {@code toJson()} and {@code fromJson()} methods of Gson will exclude the {@code address} field
48 | * since it's version number is set to {@code 1.1}.
49 | *
50 | * @author Inderjeet Singh
51 | * @author Joel Leitch
52 | */
53 | @Retention(RetentionPolicy.RUNTIME)
54 | @Target({ElementType.FIELD, ElementType.TYPE})
55 | public @interface Since {
56 | /**
57 | * the value indicating a version number since this member
58 | * or type has been present.
59 | */
60 | double value();
61 | }
62 |
--------------------------------------------------------------------------------
/src/include/ossMmapFile.hpp:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | Copyright (C) 2013 SequoiaDB Software Inc.
3 |
4 | This program is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU Affero General Public License, version 3,
6 | as published by the Free Software Foundation.
7 |
8 | This program is distributed in the hope that it will be useful,
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | GNU Affero General Public License for more details.
12 |
13 | You should have received a copy of the GNU Affero General Public License
14 | along with this program. If not, see .
15 | *******************************************************************************/
16 | #ifndef OSSMMAPFILE_HPP_
17 | #define OSSMMAPFILE_HPP_
18 |
19 | #include "core.hpp"
20 | #include "ossLatch.hpp"
21 | #include "ossPrimitiveFileOp.hpp"
22 |
23 | class _ossMmapFile
24 | {
25 | protected :
26 | class _ossMmapSegment
27 | {
28 | public :
29 | void *_ptr ;
30 | unsigned int _length ;
31 | unsigned long long _offset ;
32 | _ossMmapSegment ( void *ptr,
33 | unsigned int length,
34 | unsigned long long offset )
35 | {
36 | _ptr = ptr ;
37 | _length = length ;
38 | _offset = offset ;
39 | }
40 | } ;
41 | typedef _ossMmapSegment ossMmapSegment ;
42 |
43 | ossPrimitiveFileOp _fileOp ;
44 | ossXLatch _mutex ;
45 | bool _opened ;
46 | std::vector _segments ;
47 | char _fileName [ OSS_MAX_PATHSIZE ] ;
48 | public :
49 | typedef std::vector::const_iterator CONST_ITR ;
50 |
51 | inline CONST_ITR begin ()
52 | {
53 | return _segments.begin () ;
54 | }
55 |
56 | inline CONST_ITR end ()
57 | {
58 | return _segments.end() ;
59 | }
60 |
61 | inline unsigned int segmentSize ()
62 | {
63 | return _segments.size() ;
64 | }
65 | public :
66 | _ossMmapFile ()
67 | {
68 | _opened = false ;
69 | memset ( _fileName, 0, sizeof(_fileName) ) ;
70 | }
71 | ~_ossMmapFile ()
72 | {
73 | close () ;
74 | }
75 |
76 | int open ( const char *pFilename, unsigned int options ) ;
77 | void close () ;
78 | int map ( unsigned long long offset, unsigned int length, void **pAddress ) ;
79 | } ;
80 | typedef class _ossMmapFile ossMmapFile ;
81 |
82 | #endif
83 |
--------------------------------------------------------------------------------
/src/bson/src/lib/nonce.cpp:
--------------------------------------------------------------------------------
1 | // nonce.cpp
2 |
3 | /* Copyright 2009 10gen Inc.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | #ifdef _WINDOWS
18 | #define _CRT_RAND_S
19 | #endif
20 |
21 | #include "nonce.h"
22 |
23 | #ifdef _WINDOWS
24 | #include // rand_s
25 | #endif
26 |
27 | #include
28 | #include
29 | #include
30 | namespace Nonce {
31 |
32 | BOOST_STATIC_ASSERT( sizeof(nonce) == 8 );
33 |
34 | Security::Security() {
35 | static int n;
36 | assert(++n == 1 && "Security is a singleton class");
37 | init();
38 | }
39 |
40 | void Security::init() {
41 | if( _initialized ) return;
42 | _initialized = true;
43 |
44 | #if defined(__linux__) || defined(__sunos__)
45 | _devrandom = new std::ifstream("/dev/urandom", std::ios::binary|std::ios::in);
46 | assert(_devrandom->is_open() && "can't open dev/urandom");
47 | #elif defined(_WIN32)
48 | srand(time(NULL));
49 | #else
50 | srandomdev();
51 | #endif
52 | }
53 |
54 | nonce Security::getNonce() {
55 | static boost::mutex m;
56 | boost::mutex::scoped_lock lk(m);
57 |
58 | /* question/todo: /dev/random works on OS X. is it better
59 | to use that than random() / srandom()?
60 | */
61 |
62 | nonce n;
63 | #if defined(__linux__) || defined(__sunos__)
64 | _devrandom->read((char*)&n, sizeof(n));
65 | assert(!_devrandom->fail() && "devrandom failed");
66 | #elif defined(_WIN32)
67 | unsigned a=0, b=0;
68 | assert( rand_s(&a) == 0 );
69 | assert( rand_s(&b) == 0 );
70 | n = (((unsigned long long)a)<<32) | b;
71 | #else
72 | n = (((unsigned long long)random())<<32) | random();
73 | #endif
74 | return n;
75 | }
76 | unsigned getRandomNumber() { return (unsigned) security.getNonce(); }
77 |
78 | bool Security::_initialized;
79 | Security security;
80 |
81 |
82 | } // namespace mongo
83 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/JsonParseException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson;
18 |
19 | /**
20 | * This exception is raised if there is a serious issue that occurs during parsing of a Json
21 | * string. One of the main usages for this class is for the Gson infrastructure. If the incoming
22 | * Json is bad/malicious, an instance of this exception is raised.
23 | *
24 | * This exception is a {@link RuntimeException} because it is exposed to the client. Using a
25 | * {@link RuntimeException} avoids bad coding practices on the client side where they catch the
26 | * exception and do nothing. It is often the case that you want to blow up if there is a parsing
27 | * error (i.e. often clients do not know how to recover from a {@link JsonParseException}.
28 | *
29 | * @author Inderjeet Singh
30 | * @author Joel Leitch
31 | */
32 | public class JsonParseException extends RuntimeException {
33 | static final long serialVersionUID = -4086729973971783390L;
34 |
35 | /**
36 | * Creates exception with the specified message. If you are wrapping another exception, consider
37 | * using {@link #JsonParseException(String, Throwable)} instead.
38 | *
39 | * @param msg error message describing a possible cause of this exception.
40 | */
41 | public JsonParseException(String msg) {
42 | super(msg);
43 | }
44 |
45 | /**
46 | * Creates exception with the specified message and cause.
47 | *
48 | * @param msg error message describing what happened.
49 | * @param cause root exception that caused this exception to be thrown.
50 | */
51 | public JsonParseException(String msg, Throwable cause) {
52 | super(msg, cause);
53 | }
54 |
55 | /**
56 | * Creates exception with the specified cause. Consider using
57 | * {@link #JsonParseException(String, Throwable)} instead if you can describe what happened.
58 | *
59 | * @param cause root exception that caused this exception to be thrown.
60 | */
61 | public JsonParseException(Throwable cause) {
62 | super(cause);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/driver/java/src/com/google/gson/internal/bind/TimeTypeAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.gson.internal.bind;
18 |
19 | import com.google.gson.Gson;
20 | import com.google.gson.JsonSyntaxException;
21 | import com.google.gson.TypeAdapter;
22 | import com.google.gson.TypeAdapterFactory;
23 | import com.google.gson.reflect.TypeToken;
24 | import com.google.gson.stream.JsonReader;
25 | import com.google.gson.stream.JsonToken;
26 | import com.google.gson.stream.JsonWriter;
27 | import java.io.IOException;
28 | import java.sql.Time;
29 | import java.text.DateFormat;
30 | import java.text.ParseException;
31 | import java.text.SimpleDateFormat;
32 | import java.util.Date;
33 |
34 | /**
35 | * Adapter for Time. Although this class appears stateless, it is not.
36 | * DateFormat captures its time zone and locale when it is created, which gives
37 | * this class state. DateFormat isn't thread safe either, so this class has
38 | * to synchronize its read and write methods.
39 | */
40 | public final class TimeTypeAdapter extends TypeAdapter