Browse files

inital

  • Loading branch information...
1 parent 99017f0 commit ca300f69b2b921ffe26882b620c0b6069540d565 itiu committed May 19, 2010
Showing with 4,264 additions and 0 deletions.
  1. +5 −0 .classpath
  2. +17 −0 .project
  3. +317 −0 .settings/descent.core.prefs
  4. +5 −0 .settings/descent.ui.prefs
  5. +996 −0 src/bson.d
  6. +3 −0 src/build.sh
  7. +374 −0 src/export/bson.di
  8. +189 −0 src/export/md5.di
  9. +522 −0 src/export/mongo.di
  10. BIN src/libmongod.a
  11. +387 −0 src/md5.d
  12. +1,449 −0 src/mongo.d
View
5 .classpath
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path=""/>
+ <classpathentry kind="output" path=""/>
+</classpath>
View
17 .project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>mongo-d-driver</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>descent.core.dbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>descent.core.dnature</nature>
+ </natures>
+</projectDescription>
View
317 .settings/descent.core.prefs
@@ -0,0 +1,317 @@
+#Thu May 13 14:06:05 MSD 2010
+descent.core.formatter.alignment_for_array_literals=16
+descent.core.formatter.alignment_for_base_class_lists=16
+descent.core.formatter.alignment_for_function_declaration_parameters=16
+descent.core.formatter.alignment_for_function_invocation_arguments=16
+descent.core.formatter.alignment_for_multiple_variable_declarations=16
+descent.core.formatter.alignment_for_selective_imports=16
+descent.core.formatter.alignment_for_struct_initializer=16
+descent.core.formatter.alignment_for_template_declaration_parameters=16
+descent.core.formatter.alignment_for_template_invocation_arguments=16
+descent.core.formatter.blank_lines_after_module=1
+descent.core.formatter.blank_lines_before_module=0
+descent.core.formatter.brace_position_for_align_declaration=end_of_line
+descent.core.formatter.brace_position_for_anonymous_type=next_line
+descent.core.formatter.brace_position_for_class_invariant=next_line
+descent.core.formatter.brace_position_for_conditional_declaration=next_line
+descent.core.formatter.brace_position_for_conditional_statement=next_line
+descent.core.formatter.brace_position_for_enum_declaration=next_line
+descent.core.formatter.brace_position_for_function_declaration=next_line
+descent.core.formatter.brace_position_for_function_literal=next_line
+descent.core.formatter.brace_position_for_loop_statement=next_line
+descent.core.formatter.brace_position_for_modifiers=next_line
+descent.core.formatter.brace_position_for_postblit_declaration=next_line
+descent.core.formatter.brace_position_for_pragmas=next_line
+descent.core.formatter.brace_position_for_scope_statement=next_line
+descent.core.formatter.brace_position_for_switch_case=next_line
+descent.core.formatter.brace_position_for_switch_statement=next_line
+descent.core.formatter.brace_position_for_synchronized_statement=next_line
+descent.core.formatter.brace_position_for_template_declaration=next_line
+descent.core.formatter.brace_position_for_try_catch_finally=next_line
+descent.core.formatter.brace_position_for_type_declaration=next_line
+descent.core.formatter.brace_position_for_unittest=next_line
+descent.core.formatter.brace_position_for_with_statement=next_line
+descent.core.formatter.continuation_indentation=2
+descent.core.formatter.indent_body_declarations_compare_to_align_header=true
+descent.core.formatter.indent_body_declarations_compare_to_pragma_header=true
+descent.core.formatter.indent_body_declarations_compare_to_template_header=true
+descent.core.formatter.indent_body_declarations_compare_to_type_header=true
+descent.core.formatter.indent_break_compare_to_switch=false
+descent.core.formatter.indent_cases_compare_to_switch=true
+descent.core.formatter.indent_empty_lines=false
+descent.core.formatter.indent_enum_members_compare_to_enum_header=true
+descent.core.formatter.indent_in_out_body_compare_to_function_header=false
+descent.core.formatter.indent_statements_compare_to_case=true
+descent.core.formatter.indent_statements_compare_to_function_body_header=true
+descent.core.formatter.indent_statements_compare_to_function_header=true
+descent.core.formatter.indent_statements_compare_to_function_in_header=true
+descent.core.formatter.indent_statements_compare_to_function_out_header=true
+descent.core.formatter.indentation_size=4
+descent.core.formatter.indentation_style_compare_to_modifier_header=indent_normal
+descent.core.formatter.insert_new_line_after_case_or_default_statement=true
+descent.core.formatter.insert_new_line_after_label=true
+descent.core.formatter.insert_new_line_at_end_of_file_if_missing=false
+descent.core.formatter.insert_new_line_before_catch=false
+descent.core.formatter.insert_new_line_before_else_declaration=false
+descent.core.formatter.insert_new_line_before_else_statement=false
+descent.core.formatter.insert_new_line_before_finally=false
+descent.core.formatter.insert_new_line_before_while_in_do_statement=false
+descent.core.formatter.insert_space_after_assignment_operator=true
+descent.core.formatter.insert_space_after_closing_paren_in_casts=true
+descent.core.formatter.insert_space_after_colon_in_array_initializer=true
+descent.core.formatter.insert_space_after_colon_in_base_class_lists=true
+descent.core.formatter.insert_space_after_colon_in_case_default_statement=true
+descent.core.formatter.insert_space_after_colon_in_conditional_expressions=true
+descent.core.formatter.insert_space_after_colon_in_selective_imports=true
+descent.core.formatter.insert_space_after_colon_in_statement_labels=true
+descent.core.formatter.insert_space_after_colon_in_struct_initializer=true
+descent.core.formatter.insert_space_after_colon_in_template_specific_type=true
+descent.core.formatter.insert_space_after_comma_in_aggregate_template_parameters=true
+descent.core.formatter.insert_space_after_comma_in_array_access=true
+descent.core.formatter.insert_space_after_comma_in_array_literal=true
+descent.core.formatter.insert_space_after_comma_in_assert_statements=true
+descent.core.formatter.insert_space_after_comma_in_base_class_lists=true
+descent.core.formatter.insert_space_after_comma_in_delegates=true
+descent.core.formatter.insert_space_after_comma_in_foreach_statement=true
+descent.core.formatter.insert_space_after_comma_in_function_declaration_parameters=true
+descent.core.formatter.insert_space_after_comma_in_function_invocation_arguments=true
+descent.core.formatter.insert_space_after_comma_in_function_template_parameters=true
+descent.core.formatter.insert_space_after_comma_in_multiple_field_declarations=true
+descent.core.formatter.insert_space_after_comma_in_multiple_imports=true
+descent.core.formatter.insert_space_after_comma_in_new_arguments=true
+descent.core.formatter.insert_space_after_comma_in_pragmas=true
+descent.core.formatter.insert_space_after_comma_in_selective_imports=true
+descent.core.formatter.insert_space_after_comma_in_struct_initializer=true
+descent.core.formatter.insert_space_after_comma_in_template_declaration=true
+descent.core.formatter.insert_space_after_comma_in_template_invocation=true
+descent.core.formatter.insert_space_after_comma_in_traits_expression=true
+descent.core.formatter.insert_space_after_dot_in_qualified_names=false
+descent.core.formatter.insert_space_after_elipsis_in_function_varargs=false
+descent.core.formatter.insert_space_after_elipsis_in_tuples=false
+descent.core.formatter.insert_space_after_equals_in_default_function_arguments=true
+descent.core.formatter.insert_space_after_equals_in_default_template_arguments=true
+descent.core.formatter.insert_space_after_equals_in_enum_constants=true
+descent.core.formatter.insert_space_after_equals_in_renamed_imports=true
+descent.core.formatter.insert_space_after_equals_in_variable_inits=true
+descent.core.formatter.insert_space_after_equals_in_version_debug_assignment=true
+descent.core.formatter.insert_space_after_exclamation_point_in_template_invocation=false
+descent.core.formatter.insert_space_after_infix_operator=true
+descent.core.formatter.insert_space_after_opening_bracket_in_array_access=false
+descent.core.formatter.insert_space_after_opening_bracket_in_array_constructors=false
+descent.core.formatter.insert_space_after_opening_bracket_in_array_literals=false
+descent.core.formatter.insert_space_after_opening_bracket_in_associative_arrays=false
+descent.core.formatter.insert_space_after_opening_bracket_in_slices=false
+descent.core.formatter.insert_space_after_opening_bracket_in_static_arrays=false
+descent.core.formatter.insert_space_after_opening_paren_in_align_declarations=false
+descent.core.formatter.insert_space_after_opening_paren_in_assert_statements=false
+descent.core.formatter.insert_space_after_opening_paren_in_c_style_fp=false
+descent.core.formatter.insert_space_after_opening_paren_in_casts=false
+descent.core.formatter.insert_space_after_opening_paren_in_catch=false
+descent.core.formatter.insert_space_after_opening_paren_in_class_template_params=false
+descent.core.formatter.insert_space_after_opening_paren_in_delegate=false
+descent.core.formatter.insert_space_after_opening_paren_in_extern_declarations=false
+descent.core.formatter.insert_space_after_opening_paren_in_file_imports=false
+descent.core.formatter.insert_space_after_opening_paren_in_for_loops=false
+descent.core.formatter.insert_space_after_opening_paren_in_foreach_loops=false
+descent.core.formatter.insert_space_after_opening_paren_in_function_declaration_parameters=false
+descent.core.formatter.insert_space_after_opening_paren_in_function_invocation=false
+descent.core.formatter.insert_space_after_opening_paren_in_function_template_args=false
+descent.core.formatter.insert_space_after_opening_paren_in_if_statements=false
+descent.core.formatter.insert_space_after_opening_paren_in_is_expressions=false
+descent.core.formatter.insert_space_after_opening_paren_in_mixins=false
+descent.core.formatter.insert_space_after_opening_paren_in_modified_type=false
+descent.core.formatter.insert_space_after_opening_paren_in_new_arguments=false
+descent.core.formatter.insert_space_after_opening_paren_in_out_declaration=false
+descent.core.formatter.insert_space_after_opening_paren_in_parenthesized_expressions=false
+descent.core.formatter.insert_space_after_opening_paren_in_pragmas=false
+descent.core.formatter.insert_space_after_opening_paren_in_scope_statements=false
+descent.core.formatter.insert_space_after_opening_paren_in_switch_statements=false
+descent.core.formatter.insert_space_after_opening_paren_in_synchronized_statement=false
+descent.core.formatter.insert_space_after_opening_paren_in_template_declarations=false
+descent.core.formatter.insert_space_after_opening_paren_in_template_invocation=false
+descent.core.formatter.insert_space_after_opening_paren_in_traits_expression=false
+descent.core.formatter.insert_space_after_opening_paren_in_typeid_statements=false
+descent.core.formatter.insert_space_after_opening_paren_in_typeof_statements=false
+descent.core.formatter.insert_space_after_opening_paren_in_version_debug=false
+descent.core.formatter.insert_space_after_opening_paren_in_while_loops=false
+descent.core.formatter.insert_space_after_opening_paren_in_with_statements=false
+descent.core.formatter.insert_space_after_postfix_operator=false
+descent.core.formatter.insert_space_after_prefix_operator=false
+descent.core.formatter.insert_space_after_question_mark_in_conditional_expressions=true
+descent.core.formatter.insert_space_after_semicolon_in_for_statement=true
+descent.core.formatter.insert_space_after_semicolon_in_foreach_statement=true
+descent.core.formatter.insert_space_after_slice_operator=true
+descent.core.formatter.insert_space_after_slice_operator_in_foreach_range_statement=true
+descent.core.formatter.insert_space_after_star_in_c_style_fp=false
+descent.core.formatter.insert_space_after_trailing_comma_in_array_initializer=true
+descent.core.formatter.insert_space_before_assignment_operator=true
+descent.core.formatter.insert_space_before_asterisk_for_pointer_types=false
+descent.core.formatter.insert_space_before_closing_bracket_in_array_access=false
+descent.core.formatter.insert_space_before_closing_bracket_in_array_constructors=false
+descent.core.formatter.insert_space_before_closing_bracket_in_array_literals=false
+descent.core.formatter.insert_space_before_closing_bracket_in_associative_arrays=false
+descent.core.formatter.insert_space_before_closing_bracket_in_slices=false
+descent.core.formatter.insert_space_before_closing_bracket_in_static_arrays=false
+descent.core.formatter.insert_space_before_closing_paren_in_align_declarations=false
+descent.core.formatter.insert_space_before_closing_paren_in_assert_statements=false
+descent.core.formatter.insert_space_before_closing_paren_in_c_style_fp=false
+descent.core.formatter.insert_space_before_closing_paren_in_casts=false
+descent.core.formatter.insert_space_before_closing_paren_in_catch=false
+descent.core.formatter.insert_space_before_closing_paren_in_class_template_params=false
+descent.core.formatter.insert_space_before_closing_paren_in_delegate=false
+descent.core.formatter.insert_space_before_closing_paren_in_extern_declarations=false
+descent.core.formatter.insert_space_before_closing_paren_in_file_imports=false
+descent.core.formatter.insert_space_before_closing_paren_in_for_loops=false
+descent.core.formatter.insert_space_before_closing_paren_in_foreach_loops=false
+descent.core.formatter.insert_space_before_closing_paren_in_function_declaration_parameters=false
+descent.core.formatter.insert_space_before_closing_paren_in_function_invocation=false
+descent.core.formatter.insert_space_before_closing_paren_in_function_template_args=false
+descent.core.formatter.insert_space_before_closing_paren_in_if_statements=false
+descent.core.formatter.insert_space_before_closing_paren_in_is_expressions=false
+descent.core.formatter.insert_space_before_closing_paren_in_mixins=false
+descent.core.formatter.insert_space_before_closing_paren_in_modified_type=false
+descent.core.formatter.insert_space_before_closing_paren_in_new_arguments=false
+descent.core.formatter.insert_space_before_closing_paren_in_out_declaration=false
+descent.core.formatter.insert_space_before_closing_paren_in_parenthesized_expressions=false
+descent.core.formatter.insert_space_before_closing_paren_in_pragmas=false
+descent.core.formatter.insert_space_before_closing_paren_in_scope_statements=false
+descent.core.formatter.insert_space_before_closing_paren_in_switch_statements=false
+descent.core.formatter.insert_space_before_closing_paren_in_synchronized_statement=false
+descent.core.formatter.insert_space_before_closing_paren_in_template_declarations=false
+descent.core.formatter.insert_space_before_closing_paren_in_template_invocation=false
+descent.core.formatter.insert_space_before_closing_paren_in_traits_expression=false
+descent.core.formatter.insert_space_before_closing_paren_in_typeid_statements=false
+descent.core.formatter.insert_space_before_closing_paren_in_typeof_statements=false
+descent.core.formatter.insert_space_before_closing_paren_in_version_debug=false
+descent.core.formatter.insert_space_before_closing_paren_in_while_loops=false
+descent.core.formatter.insert_space_before_closing_paren_in_with_statements=false
+descent.core.formatter.insert_space_before_colon_in_array_initializer=false
+descent.core.formatter.insert_space_before_colon_in_base_class_lists=false
+descent.core.formatter.insert_space_before_colon_in_case_default_statement=false
+descent.core.formatter.insert_space_before_colon_in_conditional_expressions=true
+descent.core.formatter.insert_space_before_colon_in_modifiers=false
+descent.core.formatter.insert_space_before_colon_in_selective_imports=false
+descent.core.formatter.insert_space_before_colon_in_statement_labels=false
+descent.core.formatter.insert_space_before_colon_in_struct_initializer=false
+descent.core.formatter.insert_space_before_colon_in_template_specific_type=false
+descent.core.formatter.insert_space_before_comma_in_aggregate_template_parameters=false
+descent.core.formatter.insert_space_before_comma_in_array_access=false
+descent.core.formatter.insert_space_before_comma_in_array_literal=false
+descent.core.formatter.insert_space_before_comma_in_assert_statements=false
+descent.core.formatter.insert_space_before_comma_in_base_class_lists=false
+descent.core.formatter.insert_space_before_comma_in_delegates=false
+descent.core.formatter.insert_space_before_comma_in_enum_member_lists=false
+descent.core.formatter.insert_space_before_comma_in_foreach_statement=false
+descent.core.formatter.insert_space_before_comma_in_function_declaration_parameters=false
+descent.core.formatter.insert_space_before_comma_in_function_invocation_arguments=false
+descent.core.formatter.insert_space_before_comma_in_function_template_parameters=false
+descent.core.formatter.insert_space_before_comma_in_multiple_field_declarations=false
+descent.core.formatter.insert_space_before_comma_in_multiple_imports=false
+descent.core.formatter.insert_space_before_comma_in_new_arguments=false
+descent.core.formatter.insert_space_before_comma_in_pragmas=false
+descent.core.formatter.insert_space_before_comma_in_selective_imports=false
+descent.core.formatter.insert_space_before_comma_in_struct_initializer=false
+descent.core.formatter.insert_space_before_comma_in_template_declaration=false
+descent.core.formatter.insert_space_before_comma_in_template_invocation=false
+descent.core.formatter.insert_space_before_comma_in_traits_expression=false
+descent.core.formatter.insert_space_before_dot_in_qualified_names=false
+descent.core.formatter.insert_space_before_elipsis_in_function_varargs=false
+descent.core.formatter.insert_space_before_elipsis_in_tuples=false
+descent.core.formatter.insert_space_before_equals_in_default_function_arguments=true
+descent.core.formatter.insert_space_before_equals_in_default_template_arguments=true
+descent.core.formatter.insert_space_before_equals_in_enum_constants=true
+descent.core.formatter.insert_space_before_equals_in_renamed_imports=true
+descent.core.formatter.insert_space_before_equals_in_variable_inits=true
+descent.core.formatter.insert_space_before_equals_in_version_debug_assignment=true
+descent.core.formatter.insert_space_before_exclamation_point_in_template_invocation=false
+descent.core.formatter.insert_space_before_infix_operator=true
+descent.core.formatter.insert_space_before_opening_bracket_in_array_access=false
+descent.core.formatter.insert_space_before_opening_bracket_in_array_constructors=false
+descent.core.formatter.insert_space_before_opening_bracket_in_associative_arrays=false
+descent.core.formatter.insert_space_before_opening_bracket_in_dynamic_arrays=false
+descent.core.formatter.insert_space_before_opening_bracket_in_slices=false
+descent.core.formatter.insert_space_before_opening_bracket_in_static_arrays=false
+descent.core.formatter.insert_space_before_opening_paren_in_align_declarations=false
+descent.core.formatter.insert_space_before_opening_paren_in_assert_statements=false
+descent.core.formatter.insert_space_before_opening_paren_in_c_style_fp=true
+descent.core.formatter.insert_space_before_opening_paren_in_casts=false
+descent.core.formatter.insert_space_before_opening_paren_in_catch=false
+descent.core.formatter.insert_space_before_opening_paren_in_class_invariants=false
+descent.core.formatter.insert_space_before_opening_paren_in_class_template_params=false
+descent.core.formatter.insert_space_before_opening_paren_in_delegate=false
+descent.core.formatter.insert_space_before_opening_paren_in_extern_declarations=false
+descent.core.formatter.insert_space_before_opening_paren_in_file_imports=false
+descent.core.formatter.insert_space_before_opening_paren_in_for_loops=false
+descent.core.formatter.insert_space_before_opening_paren_in_foreach_loops=false
+descent.core.formatter.insert_space_before_opening_paren_in_function_declaration_parameters=false
+descent.core.formatter.insert_space_before_opening_paren_in_function_invocation=false
+descent.core.formatter.insert_space_before_opening_paren_in_function_template_args=false
+descent.core.formatter.insert_space_before_opening_paren_in_if_statements=false
+descent.core.formatter.insert_space_before_opening_paren_in_is_expressions=false
+descent.core.formatter.insert_space_before_opening_paren_in_mixins=false
+descent.core.formatter.insert_space_before_opening_paren_in_modified_type=false
+descent.core.formatter.insert_space_before_opening_paren_in_new_arguments=false
+descent.core.formatter.insert_space_before_opening_paren_in_out_declaration=false
+descent.core.formatter.insert_space_before_opening_paren_in_parenthesized_expressions=false
+descent.core.formatter.insert_space_before_opening_paren_in_pragmas=false
+descent.core.formatter.insert_space_before_opening_paren_in_scope_statements=false
+descent.core.formatter.insert_space_before_opening_paren_in_switch_statements=false
+descent.core.formatter.insert_space_before_opening_paren_in_synchronized_statement=false
+descent.core.formatter.insert_space_before_opening_paren_in_template_declarations=false
+descent.core.formatter.insert_space_before_opening_paren_in_traits_expression=false
+descent.core.formatter.insert_space_before_opening_paren_in_typeid_statements=false
+descent.core.formatter.insert_space_before_opening_paren_in_typeof_statements=false
+descent.core.formatter.insert_space_before_opening_paren_in_version_debug=false
+descent.core.formatter.insert_space_before_opening_paren_in_while_loops=false
+descent.core.formatter.insert_space_before_opening_paren_in_with_statements=false
+descent.core.formatter.insert_space_before_postfix_operator=false
+descent.core.formatter.insert_space_before_prefix_operator=false
+descent.core.formatter.insert_space_before_question_mark_in_conditional_expressions=true
+descent.core.formatter.insert_space_before_semicolon=false
+descent.core.formatter.insert_space_before_semicolon_in_for_statement=false
+descent.core.formatter.insert_space_before_semicolon_in_foreach_statement=false
+descent.core.formatter.insert_space_before_slice_operator=true
+descent.core.formatter.insert_space_before_slice_operator_in_foreach_range_statement=true
+descent.core.formatter.insert_space_before_trailing_comma_in_array_initializer=false
+descent.core.formatter.insert_space_between_adjacent_brackets_in_multidimensional_arrays=false
+descent.core.formatter.insert_space_between_empty_brackets_in_dynamic_array_type=false
+descent.core.formatter.insert_space_between_empty_brackets_in_slice=false
+descent.core.formatter.insert_space_between_empty_parens_in_class_invariants=false
+descent.core.formatter.insert_space_between_empty_parens_in_class_template_params=false
+descent.core.formatter.insert_space_between_empty_parens_in_delegate=false
+descent.core.formatter.insert_space_between_empty_parens_in_extern_declarations=false
+descent.core.formatter.insert_space_between_empty_parens_in_function_declaration_parameters=false
+descent.core.formatter.insert_space_between_empty_parens_in_function_invocation=false
+descent.core.formatter.insert_space_between_empty_parens_in_function_template_args=false
+descent.core.formatter.insert_space_between_empty_parens_in_new_arguments=false
+descent.core.formatter.insert_space_between_empty_parens_in_out_declaration=false
+descent.core.formatter.insert_space_between_empty_parens_in_template_declarations=false
+descent.core.formatter.insert_space_between_empty_parens_in_template_invocation=false
+descent.core.formatter.insert_space_between_name_and_args_in_c_style_fp=false
+descent.core.formatter.insert_space_between_succesive_opcalls=false
+descent.core.formatter.insert_space_between_template_and_arg_parens_in_function_declaration=false
+descent.core.formatter.insert_space_between_template_args_and_function_args=false
+descent.core.formatter.keep_else_conditional_on_one_line=true
+descent.core.formatter.keep_else_version_debug_on_one_line=true
+descent.core.formatter.keep_functions_with_no_statement_in_one_line=false
+descent.core.formatter.keep_functions_with_one_statement_in_one_line=false
+descent.core.formatter.keep_simple_catch_statement_on_same_line=false
+descent.core.formatter.keep_simple_else_declaration_on_same_line=false
+descent.core.formatter.keep_simple_else_statement_on_same_line=false
+descent.core.formatter.keep_simple_finally_statement_on_same_line=false
+descent.core.formatter.keep_simple_loop_statement_on_same_line=false
+descent.core.formatter.keep_simple_scope_statement_on_same_line=false
+descent.core.formatter.keep_simple_synchronized_statement_on_same_line=false
+descent.core.formatter.keep_simple_then_declaration_on_same_line=false
+descent.core.formatter.keep_simple_then_statement_on_same_line=false
+descent.core.formatter.keep_simple_try_statement_on_same_line=false
+descent.core.formatter.keep_simple_with_statement_on_same_line=false
+descent.core.formatter.line_split=80
+descent.core.formatter.never_indent_block_comments_on_first_column=false
+descent.core.formatter.never_indent_line_comments_on_first_column=false
+descent.core.formatter.number_of_empty_lines_to_preserve=1
+descent.core.formatter.page_width=80
+descent.core.formatter.tab_char=tab
+descent.core.formatter.tab_size=4
+descent.core.formatter.use_tabs_only_for_leading_indentations=false
+eclipse.preferences.version=1
View
5 .settings/descent.ui.prefs
@@ -0,0 +1,5 @@
+#Thu May 13 14:06:05 MSD 2010
+descent.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates/>
+eclipse.preferences.version=1
+formatter_profile=_my
+formatter_settings_version=1
View
996 src/bson.d
@@ -0,0 +1,996 @@
+module bson;
+
+private import tango.stdc.string;
+private import tango.stdc.stdlib;
+private import tango.stdc.time;
+private import tango.stdc.stdio;
+
+/* bson.c */
+
+/* Copyright 2009, 2010 10gen 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.h"
+alias int bson_bool_t;
+
+struct bson
+{
+ char* data;
+ bson_bool_t owned;
+};
+
+struct bson_buffer
+{
+ char* buf;
+ char* cur;
+ int bufSize;
+ bson_bool_t finished;
+ int stack[32];
+ int stackPos;
+};
+
+union bson_oid_t
+{
+ char bytes[12];
+ int ints[3];
+};
+
+struct bson_iterator
+{
+ char* cur;
+ bson_bool_t first;
+};
+
+alias int time_t;
+
+enum bson_type
+{
+ bson_eoo = 0,
+ bson_double = 1,
+ bson_string = 2,
+ bson_object = 3,
+ bson_array = 4,
+ bson_bindata = 5,
+ bson_undefined = 6,
+ bson_oid = 7,
+ bson_bool = 8,
+ bson_date = 9,
+ bson_null = 10,
+ bson_regex = 11,
+ bson_dbref = 12, /* deprecated */
+ bson_code = 13,
+ bson_symbol = 14,
+ bson_codewscope = 15,
+ bson_int = 16,
+ bson_timestamp = 17,
+ bson_long = 18
+};
+
+alias long int64_t;
+
+alias int64_t bson_date_t;
+
+alias char* bson_err_handler;
+
+void bson_swap_endian64(char* outp, char* inp)
+{
+ outp[0] = inp[7];
+ outp[1] = inp[6];
+ outp[2] = inp[5];
+ outp[3] = inp[4];
+ outp[4] = inp[3];
+ outp[5] = inp[2];
+ outp[6] = inp[1];
+ outp[7] = inp[0];
+
+}
+
+void bson_swap_endian32(char* outp, char* inp)
+{
+ outp[0] = inp[3];
+ outp[1] = inp[2];
+ outp[2] = inp[1];
+ outp[3] = inp[0];
+}
+
+version(MONGO_BIG_ENDIAN)
+{
+//#define bson_little_endian64(out, in) ( bson_swap_endian64(out, in) )
+//#define bson_little_endian32(out, in) ( bson_swap_endian32(out, in) )
+
+//#define bson_big_endian32(out, in) ( memcpy(out, in, 4) )
+} else
+{
+ //#else
+
+ //#define bson_little_endian64(out, in) ( memcpy(out, in, 8) )
+ void bson_little_endian64(void* outp, void* inp)
+ {
+ memcpy(outp, inp, 8);
+ }
+
+ //#define bson_little_endian32(out, in) ( memcpy(out, in, 4) )
+ void bson_little_endian32(void* outp, void* inp)
+ {
+ memcpy(outp, inp, 4);
+ }
+
+ //#define bson_big_endian32(out, in) ( bson_swap_endian32(out, in) )
+ void bson_big_endian32(void* outp, void* inp)
+ {
+ bson_swap_endian32(cast(char*) outp, cast(char*) inp);
+ }
+
+ //#define bson_big_endian64(out, in) ( bson_swap_endian64(out, in) )
+ void bson_big_endian64(void* outp, void* inp)
+ {
+ bson_swap_endian64(cast(char*) outp, cast(char*) inp);
+ }
+//#endif
+}
+
+//#include <stdlib.h>
+//#include <string.h>
+//#include <stdio.h>
+//#include <time.h>
+
+const int initialBufferSize = 128;
+
+/* only need one of these */
+static int zero = 0;
+
+/* ----------------------------
+ READING
+ ------------------------------ */
+
+bson* bson_empty(bson* obj)
+{
+ static char* data = "\005\0\0\0\0";
+ return bson_init(obj, data, 0);
+}
+
+void bson_copy(bson* _out, bson* _in)
+{
+ if(!_out)
+ return;
+ _out.data = cast(char*) bson_malloc(bson_size(_in));
+ _out.owned = 1;
+ memcpy(_out.data, _in.data, bson_size(_in));
+}
+
+bson* bson_from_buffer(bson* b, bson_buffer* buf)
+{
+ return bson_init(b, bson_buffer_finish(buf), 1);
+}
+
+bson* bson_init(bson* b, char* data, bson_bool_t mine)
+{
+ b.data = data;
+ b.owned = mine;
+ return b;
+}
+
+int bson_size(bson* b)
+{
+ int i;
+ if(!b || !b.data)
+ return 0;
+ bson_little_endian32(cast(void*) &i, cast(void*) b.data);
+ return i;
+}
+
+void bson_destroy(bson* b)
+{
+ if(b.owned && b.data)
+ free(b.data);
+ b.data = null;
+ b.owned = 0;
+}
+
+static char hexbyte(char hex)
+{
+ switch(hex)
+ {
+ case '0':
+ return 0x0;
+ case '1':
+ return 0x1;
+ case '2':
+ return 0x2;
+ case '3':
+ return 0x3;
+ case '4':
+ return 0x4;
+ case '5':
+ return 0x5;
+ case '6':
+ return 0x6;
+ case '7':
+ return 0x7;
+ case '8':
+ return 0x8;
+ case '9':
+ return 0x9;
+ 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 0x0; /* something smarter? */
+ }
+}
+
+void bson_oid_from_string(bson_oid_t* oid, char* str)
+{
+ int i;
+ for(i = 0; i < 12; i++)
+ {
+ oid.bytes[i] = (hexbyte(str[2 * i]) << 4) | hexbyte(str[2 * i + 1]);
+ }
+}
+
+void bson_oid_to_string(bson_oid_t* oid, char* str)
+{
+ static const char hex[16] = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
+ '9', 'a', 'b', 'c', 'd', 'e', 'f'];
+ int i;
+ for(i = 0; i < 12; i++)
+ {
+ str[2 * i] = hex[(oid.bytes[i] & 0xf0) >> 4];
+ str[2 * i + 1] = hex[oid.bytes[i] & 0x0f];
+ }
+ str[24] = '\0';
+}
+
+void bson_oid_gen(bson_oid_t* oid)
+{
+ static int incr = 0;
+ static int fuzz = 0;
+ int i = incr++; /*TODO make atomic*/
+ int t = time(null);
+
+ /* TODO rand sucks. find something better */
+ if(!fuzz)
+ {
+ srand(t);
+ fuzz = rand();
+ }
+
+ bson_big_endian32(&oid.ints[0], &t);
+ oid.ints[1] = fuzz;
+ bson_big_endian32(&oid.ints[2], &i);
+}
+
+time_t bson_oid_generated_time(bson_oid_t* oid)
+{
+ time_t _out;
+ bson_big_endian32(&_out, &oid.ints[0]);
+ return _out;
+}
+
+void bson_print(bson* b)
+{
+ bson_print_raw(b.data, 0);
+}
+
+void bson_print_raw(char* data, int depth)
+{
+ bson_iterator i;
+ char* key;
+ int temp;
+ char oidhex[25];
+ bson_iterator_init(&i, data);
+
+ while(bson_iterator_next(&i))
+ {
+ bson_type t = bson_iterator_type(&i);
+ if(t == 0)
+ break;
+ key = bson_iterator_key(&i);
+
+ for(temp = 0; temp <= depth; temp++)
+ printf("\t");
+ printf("%s : %d \t ", key, t);
+ switch(t)
+ {
+ case bson_type.bson_int:
+ printf("%d", bson_iterator_int(&i));
+ break;
+ case bson_type.bson_double:
+ printf("%f", bson_iterator_double(&i));
+ break;
+ case bson_type.bson_bool:
+ printf("%s", bson_iterator_bool(&i) ? "true" : "false");
+ break;
+ case bson_type.bson_string:
+ printf("%s", bson_iterator_string(&i));
+ break;
+ case bson_type.bson_null:
+ printf("null");
+ break;
+ case bson_type.bson_oid:
+ bson_oid_to_string(bson_iterator_oid(&i), cast(char*) &oidhex);
+ printf("%s", oidhex);
+ break; //@@@ cast (char*)&oidhex)
+ case bson_type.bson_object:
+ case bson_type.bson_array:
+ printf("\n");
+ bson_print_raw(bson_iterator_value(&i), depth + 1);
+ break;
+ default:
+ fprintf(stderr, "can't print type : %d\n", t);
+ }
+ printf("\n");
+ }
+}
+
+/* ----------------------------
+ ITERATOR
+ ------------------------------ */
+
+void bson_iterator_init(bson_iterator* i, char* bson)
+{
+ i.cur = bson + 4;
+ i.first = 1;
+}
+
+bson_type bson_find(bson_iterator* it, bson* obj, char* name)
+{
+ bson_iterator_init(it, obj.data);
+ while(bson_iterator_next(it))
+ {
+ if(strcmp(name, bson_iterator_key(it)) == 0)
+ break;
+ }
+ return bson_iterator_type(it);
+}
+
+bson_bool_t bson_iterator_more(bson_iterator* i)
+{
+ return *(i.cur);
+}
+
+bson_type bson_iterator_next(bson_iterator* i)
+{
+ int ds;
+
+ if(i.first)
+ {
+ i.first = 0;
+ return cast(bson_type) (i.cur);
+ }
+
+ switch(bson_iterator_type(i))
+ {
+ case bson_type.bson_eoo:
+ return bson_type.bson_eoo; /* don't advance */
+ case bson_type.bson_undefined:
+ case bson_type.bson_null:
+ ds = 0;
+ break;
+ case bson_type.bson_bool:
+ ds = 1;
+ break;
+ case bson_type.bson_int:
+ ds = 4;
+ break;
+ case bson_type.bson_long:
+ case bson_type.bson_double:
+ case bson_type.bson_timestamp:
+ case bson_type.bson_date:
+ ds = 8;
+ break;
+ case bson_type.bson_oid:
+ ds = 12;
+ break;
+ case bson_type.bson_string:
+ case bson_type.bson_symbol:
+ case bson_type.bson_code:
+ ds = 4 + bson_iterator_int_raw(i);
+ break;
+ case bson_type.bson_bindata:
+ ds = 5 + bson_iterator_int_raw(i);
+ break;
+ case bson_type.bson_object:
+ case bson_type.bson_array:
+ case bson_type.bson_codewscope:
+ ds = bson_iterator_int_raw(i);
+ break;
+ case bson_type.bson_dbref:
+ ds = 4 + 12 + bson_iterator_int_raw(i);
+ break;
+ case bson_type.bson_regex:
+ {
+ char* s = bson_iterator_value(i);
+ char* p = s;
+ p += strlen(p) + 1;
+ p += strlen(p) + 1;
+ ds = p - s;
+ break;
+ }
+
+ default:
+ {
+ char msg[] = "unknown type: 000000000000";
+ bson_numstr(cast(char*) (&msg + 14), cast(int) (i.cur[0]));
+ bson_fatal_msg(0, cast(char*) &msg);
+ return cast(bson_type) 0;
+ }
+ }
+
+ i.cur += 1 + strlen(i.cur + 1) + 1 + ds;
+
+ return cast(bson_type) (i.cur);
+}
+
+bson_type bson_iterator_type(bson_iterator* i)
+{
+ return cast(bson_type) i.cur[0];
+}
+
+char* bson_iterator_key(bson_iterator* i)
+{
+ return i.cur + 1;
+}
+
+char* bson_iterator_value(bson_iterator* i)
+{
+ char* t = i.cur + 1;
+ t += strlen(t) + 1;
+ return t;
+}
+
+/* types */
+
+int bson_iterator_int_raw(bson_iterator* i)
+{
+ int _out;
+ bson_little_endian32(&_out, bson_iterator_value(i));
+ return _out;
+}
+
+double bson_iterator_double_raw(bson_iterator* i)
+{
+ double _out;
+ bson_little_endian64(&_out, bson_iterator_value(i));
+ return _out;
+}
+
+int64_t bson_iterator_long_raw(bson_iterator* i)
+{
+ int64_t _out;
+ bson_little_endian64(&_out, bson_iterator_value(i));
+ return _out;
+}
+
+bson_bool_t bson_iterator_bool_raw(bson_iterator* i)
+{
+ return bson_iterator_value(i)[0];
+}
+
+bson_oid_t* bson_iterator_oid(bson_iterator* i)
+{
+ return cast(bson_oid_t*) bson_iterator_value(i);
+}
+
+int bson_iterator_int(bson_iterator* i)
+{
+ switch(bson_iterator_type(i))
+ {
+ case bson_type.bson_int:
+ return bson_iterator_int_raw(i);
+ case bson_type.bson_long:
+ return cast(int) bson_iterator_long_raw(i);
+ case bson_type.bson_double:
+ return cast(int) bson_iterator_double_raw(i);
+ default:
+ return 0;
+ }
+}
+
+double bson_iterator_double(bson_iterator* i)
+{
+ switch(bson_iterator_type(i))
+ {
+ case bson_type.bson_int:
+ return bson_iterator_int_raw(i);
+ case bson_type.bson_long:
+ return bson_iterator_long_raw(i);
+ case bson_type.bson_double:
+ return bson_iterator_double_raw(i);
+ default:
+ return 0;
+ }
+}
+
+int64_t bson_iterator_long(bson_iterator* i)
+{
+ switch(bson_iterator_type(i))
+ {
+ case bson_type.bson_int:
+ return bson_iterator_int_raw(i);
+ case bson_type.bson_long:
+ return bson_iterator_long_raw(i);
+ case bson_type.bson_double:
+ return cast(int64_t) bson_iterator_double_raw(i);
+ default:
+ return 0;
+ }
+}
+
+bson_bool_t bson_iterator_bool(bson_iterator* i)
+{
+ switch(bson_iterator_type(i))
+ {
+ case bson_type.bson_bool:
+ return bson_iterator_bool_raw(i);
+ case bson_type.bson_int:
+ return bson_iterator_int_raw(i) != 0;
+ case bson_type.bson_long:
+ return bson_iterator_long_raw(i) != 0;
+ case bson_type.bson_double:
+ return bson_iterator_double_raw(i) != 0;
+ case bson_type.bson_eoo:
+ case bson_type.bson_null:
+ return 0;
+ default:
+ return 1;
+ }
+}
+
+char* bson_iterator_string(bson_iterator* i)
+{
+ return bson_iterator_value(i) + 4;
+}
+
+int bson_iterator_string_len(bson_iterator* i)
+{
+ return bson_iterator_int_raw(i);
+}
+
+char* bson_iterator_code(bson_iterator* i)
+{
+ switch(bson_iterator_type(i))
+ {
+ case bson_type.bson_string:
+ case bson_type.bson_code:
+ return bson_iterator_value(i) + 4;
+ case bson_type.bson_codewscope:
+ return bson_iterator_value(i) + 8;
+ default:
+ return null;
+ }
+}
+
+void bson_iterator_code_scope(bson_iterator* i, bson* _scope)
+{
+ if(bson_iterator_type(i) == bson_type.bson_codewscope)
+ {
+ int code_len;
+ bson_little_endian32(&code_len, bson_iterator_value(i) + 4);
+ bson_init(_scope, cast(char*) (bson_iterator_value(i) + 8 + code_len),
+ 0);
+ } else
+ {
+ bson_empty(_scope);
+ }
+}
+
+bson_date_t bson_iterator_date(bson_iterator* i)
+{
+ return bson_iterator_long_raw(i);
+}
+
+time_t bson_iterator_time_t(bson_iterator* i)
+{
+ return bson_iterator_date(i) / 1000;
+}
+
+int bson_iterator_bin_len(bson_iterator* i)
+{
+ return bson_iterator_int_raw(i);
+}
+
+char bson_iterator_bin_type(bson_iterator* i)
+{
+ return bson_iterator_value(i)[4];
+}
+
+char* bson_iterator_bin_data(bson_iterator* i)
+{
+ return bson_iterator_value(i) + 5;
+}
+
+char* bson_iterator_regex(bson_iterator* i)
+{
+ return bson_iterator_value(i);
+}
+
+char* bson_iterator_regex_opts(bson_iterator* i)
+{
+ char* p = bson_iterator_value(i);
+ return p + strlen(p) + 1;
+
+}
+
+void bson_iterator_subobject(bson_iterator* i, bson* sub)
+{
+ bson_init(sub, cast(char*) bson_iterator_value(i), 0);
+}
+
+void bson_iterator_subiterator(bson_iterator* i, bson_iterator* sub)
+{
+ bson_iterator_init(sub, bson_iterator_value(i));
+}
+
+/* ----------------------------
+ BUILDING
+ ------------------------------ */
+
+bson_buffer* bson_buffer_init(bson_buffer* b)
+{
+ b.buf = cast(char*) bson_malloc(initialBufferSize);
+ b.bufSize = initialBufferSize;
+ b.cur = b.buf + 4;
+ b.finished = 0;
+ b.stackPos = 0;
+ return b;
+}
+
+void bson_append_byte(bson_buffer* b, char c)
+{
+ b.cur[0] = c;
+ b.cur++;
+}
+
+void bson_append(bson_buffer* b, void* data, int len)
+{
+ memcpy(b.cur, data, len);
+ b.cur += len;
+}
+
+void bson_append32(bson_buffer* b, void* data)
+{
+ bson_little_endian32(b.cur, data);
+ b.cur += 4;
+}
+
+void bson_append64(bson_buffer* b, void* data)
+{
+ bson_little_endian64(b.cur, data);
+ b.cur += 8;
+}
+
+bson_buffer* bson_ensure_space(bson_buffer* b, int bytesNeeded)
+{
+ int pos = b.cur - b.buf;
+ char* orig = b.buf;
+ int new_size;
+
+ if(b.finished)
+ bson_fatal_msg(!!b.buf, "trying to append to finished buffer");
+
+ if(pos + bytesNeeded <= b.bufSize)
+ return b;
+
+ new_size = cast(int) (1.5 * (b.bufSize + bytesNeeded));
+ b.buf = cast(char*) realloc(cast(void*) b.buf, new_size);
+ if(!b.buf)
+ bson_fatal_msg(!!b.buf, "realloc() failed");
+
+ b.bufSize = new_size;
+ b.cur += b.buf - orig;
+
+ return b;
+}
+
+char* bson_buffer_finish(bson_buffer* b)
+{
+ int i;
+ if(!b.finished)
+ {
+ if(!bson_ensure_space(b, 1))
+ return null;
+ bson_append_byte(b, 0);
+ i = b.cur - b.buf;
+ bson_little_endian32(b.buf, &i);
+ b.finished = 1;
+ }
+ return b.buf;
+}
+
+void bson_buffer_destroy(bson_buffer* b)
+{
+ free(b.buf);
+ b.buf = null;
+ b.cur = null;
+ b.finished = 1;
+}
+
+static bson_buffer* bson_append_estart(bson_buffer* b, int type, char* name,
+ int dataSize)
+{
+ int sl = strlen(name) + 1;
+ if(!bson_ensure_space(b, 1 + sl + dataSize))
+ return null;
+ bson_append_byte(b, cast(char) type);
+ bson_append(b, name, sl);
+ return b;
+}
+
+/* ----------------------------
+ BUILDING TYPES
+ ------------------------------ */
+
+bson_buffer* bson_append_int(bson_buffer* b, char* name, int i)
+{
+ if(!bson_append_estart(b, bson_type.bson_int, name, 4))
+ return null;
+ bson_append32(b, &i);
+ return b;
+}
+
+bson_buffer* bson_append_long(bson_buffer* b, char* name, int64_t i)
+{
+ if(!bson_append_estart(b, bson_type.bson_long, name, 8))
+ return null;
+ bson_append64(b, &i);
+ return b;
+}
+
+bson_buffer* bson_append_double(bson_buffer* b, char* name, double d)
+{
+ if(!bson_append_estart(b, bson_type.bson_double, name, 8))
+ return null;
+ bson_append64(b, &d);
+ return b;
+}
+
+bson_buffer* bson_append_bool(bson_buffer* b, char* name, bson_bool_t i)
+{
+ if(!bson_append_estart(b, bson_type.bson_bool, name, 1))
+ return null;
+ bson_append_byte(b, i != 0);
+ return b;
+}
+
+bson_buffer* bson_append_null(bson_buffer* b, char* name)
+{
+ if(!bson_append_estart(b, bson_type.bson_null, name, 0))
+ return null;
+ return b;
+}
+
+bson_buffer* bson_append_undefined(bson_buffer* b, char* name)
+{
+ if(!bson_append_estart(b, bson_type.bson_undefined, name, 0))
+ return null;
+ return b;
+}
+
+bson_buffer* bson_append_string_base(bson_buffer* b, char* name, char* value,
+ bson_type type)
+{
+ int sl = strlen(value) + 1;
+ if(!bson_append_estart(b, type, name, 4 + sl))
+ return null;
+ bson_append32(b, &sl);
+ bson_append(b, value, sl);
+ return b;
+}
+
+bson_buffer* bson_append_string(bson_buffer* b, char* name, char* value)
+{
+ return bson_append_string_base(b, name, value, bson_type.bson_string);
+}
+
+bson_buffer* bson_append_symbol(bson_buffer* b, char* name, char* value)
+{
+ return bson_append_string_base(b, name, value, bson_type.bson_symbol);
+}
+
+bson_buffer* bson_append_code(bson_buffer* b, char* name, char* value)
+{
+ return bson_append_string_base(b, name, value, bson_type.bson_code);
+}
+
+bson_buffer* bson_append_code_w_scope(bson_buffer* b, char* name, char* code,
+ bson* _scope)
+{
+ int sl = strlen(code) + 1;
+ int size = 4 + 4 + sl + bson_size(_scope);
+ if(!bson_append_estart(b, bson_type.bson_codewscope, name, size))
+ return null;
+ bson_append32(b, &size);
+ bson_append32(b, &sl);
+ bson_append(b, code, sl);
+ bson_append(b, _scope.data, bson_size(_scope));
+ return b;
+}
+
+bson_buffer* bson_append_binary(bson_buffer* b, char* name, char type,
+ char* str, int len)
+{
+ if(!bson_append_estart(b, bson_type.bson_bindata, name, 4 + 1 + len))
+ return null;
+ bson_append32(b, &len);
+ bson_append_byte(b, type);
+ bson_append(b, str, len);
+ return b;
+}
+
+bson_buffer* bson_append_oid(bson_buffer* b, char* name, bson_oid_t* oid)
+{
+ if(!bson_append_estart(b, bson_type.bson_oid, name, 12))
+ return null;
+ bson_append(b, oid, 12);
+ return b;
+}
+
+bson_buffer* bson_append_new_oid(bson_buffer* b, char* name)
+{
+ bson_oid_t oid;
+ bson_oid_gen(&oid);
+ return bson_append_oid(b, name, &oid);
+}
+
+bson_buffer* bson_append_regex(bson_buffer* b, char* name, char* pattern,
+ char* opts)
+{
+ int plen = strlen(pattern) + 1;
+ int olen = strlen(opts) + 1;
+ if(!bson_append_estart(b, bson_type.bson_regex, name, plen + olen))
+ return null;
+ bson_append(b, pattern, plen);
+ bson_append(b, opts, olen);
+ return b;
+}
+
+bson_buffer* bson_append_bson(bson_buffer* b, char* name, bson* bson)
+{
+ if(!bson_append_estart(b, bson_type.bson_object, name, bson_size(bson)))
+ return null;
+ bson_append(b, bson.data, bson_size(bson));
+ return b;
+}
+
+bson_buffer* bson_append_element(bson_buffer* b, char* name_or_null,
+ bson_iterator* elem)
+{
+ bson_iterator next = *elem;
+ int size;
+
+ bson_iterator_next(&next);
+ size = next.cur - elem.cur;
+
+ if(name_or_null is null)
+ {
+ bson_ensure_space(b, size);
+ bson_append(b, elem.cur, size);
+ } else
+ {
+ int data_size = size - 1 - strlen(bson_iterator_key(elem));
+ bson_append_estart(b, elem.cur[0], name_or_null, data_size);
+ bson_append(b, name_or_null, strlen(name_or_null));
+ bson_append(b, bson_iterator_value(elem), data_size);
+ }
+
+ return b;
+}
+
+bson_buffer* bson_append_date(bson_buffer* b, char* name, bson_date_t millis)
+{
+ if(!bson_append_estart(b, bson_type.bson_date, name, 8))
+ return null;
+ bson_append64(b, &millis);
+ return b;
+}
+
+bson_buffer* bson_append_time_t(bson_buffer* b, char* name, time_t secs)
+{
+ return bson_append_date(b, name, cast(bson_date_t) secs * 1000);
+}
+
+bson_buffer* bson_append_start_object(bson_buffer* b, char* name)
+{
+ if(!bson_append_estart(b, bson_type.bson_object, name, 5))
+ return null;
+ b.stack[b.stackPos++] = b.cur - b.buf;
+ bson_append32(b, &zero);
+ return b;
+}
+
+bson_buffer* bson_append_start_array(bson_buffer* b, char* name)
+{
+ if(!bson_append_estart(b, bson_type.bson_array, name, 5))
+ return null;
+ b.stack[b.stackPos++] = b.cur - b.buf;
+ bson_append32(b, &zero);
+ return b;
+}
+
+bson_buffer* bson_append_finish_object(bson_buffer* b)
+{
+ char* start;
+ int i;
+ if(!bson_ensure_space(b, 1))
+ return null;
+ bson_append_byte(b, 0);
+
+ start = b.buf + b.stack[--b.stackPos];
+ i = b.cur - start;
+ bson_little_endian32(start, &i);
+
+ return b;
+}
+
+void* bson_malloc(int size)
+{
+ void* p = malloc(size);
+ bson_fatal_msg(!!p, "malloc() failed");
+ return p;
+}
+
+static bson_err_handler err_handler = null;
+
+bson_err_handler set_bson_err_handler(bson_err_handler func)
+{
+ bson_err_handler old = err_handler;
+ err_handler = func;
+ return old;
+}
+
+void bson_fatal(int ok)
+{
+ bson_fatal_msg(ok, "");
+}
+
+void bson_fatal_msg(int ok, char* msg)
+{
+ if(ok)
+ return;
+
+ if(err_handler)
+ {
+ // err_handler(msg); @@@???
+ }
+
+ fprintf(stderr, "error: %s\n", msg);
+ exit(-5);
+}
+
+const char bson_numstrs[1000][4];
+
+void bson_numstr(char* str, int i)
+{
+ if(i < 1000)
+ memcpy(str, &bson_numstrs[i], 4);
+ else
+ sprintf(str, "%d", i);
+}
View
3 src/build.sh
@@ -0,0 +1,3 @@
+rm *.o
+rm *.a
+dmd mongo.d bson.d md5.d -Hdexport -release -lib -oflibmongod
View
374 src/export/bson.di
@@ -0,0 +1,374 @@
+// D import file generated from 'bson.d'
+module bson;
+private
+{
+ import tango.stdc.string;
+}
+private
+{
+ import tango.stdc.stdlib;
+}
+private
+{
+ import tango.stdc.time;
+}
+private
+{
+ import tango.stdc.stdio;
+}
+alias int bson_bool_t;
+struct bson
+{
+ char* data;
+ bson_bool_t owned;
+}
+struct bson_buffer
+{
+ char* buf;
+ char* cur;
+ int bufSize;
+ bson_bool_t finished;
+ int[32] stack;
+ int stackPos;
+}
+union bson_oid_t
+{
+ char[12] bytes;
+ int[3] ints;
+}
+struct bson_iterator
+{
+ char* cur;
+ bson_bool_t first;
+}
+alias int time_t;
+enum bson_type
+{
+bson_eoo = 0,
+bson_double = 1,
+bson_string = 2,
+bson_object = 3,
+bson_array = 4,
+bson_bindata = 5,
+bson_undefined = 6,
+bson_oid = 7,
+bson_bool = 8,
+bson_date = 9,
+bson_null = 10,
+bson_regex = 11,
+bson_dbref = 12,
+bson_code = 13,
+bson_symbol = 14,
+bson_codewscope = 15,
+bson_int = 16,
+bson_timestamp = 17,
+bson_long = 18,
+}
+alias long int64_t;
+alias int64_t bson_date_t;
+alias char* bson_err_handler;
+void bson_swap_endian64(char* outp, char* inp)
+{
+outp[0] = inp[7];
+outp[1] = inp[6];
+outp[2] = inp[5];
+outp[3] = inp[4];
+outp[4] = inp[3];
+outp[5] = inp[2];
+outp[6] = inp[1];
+outp[7] = inp[0];
+}
+void bson_swap_endian32(char* outp, char* inp)
+{
+outp[0] = inp[3];
+outp[1] = inp[2];
+outp[2] = inp[1];
+outp[3] = inp[0];
+}
+version (MONGO_BIG_ENDIAN)
+{
+}
+else
+{
+ void bson_little_endian64(void* outp, void* inp)
+{
+memcpy(outp,inp,8);
+}
+ void bson_little_endian32(void* outp, void* inp)
+{
+memcpy(outp,inp,4);
+}
+ void bson_big_endian32(void* outp, void* inp)
+{
+bson_swap_endian32(cast(char*)outp,cast(char*)inp);
+}
+ void bson_big_endian64(void* outp, void* inp)
+{
+bson_swap_endian64(cast(char*)outp,cast(char*)inp);
+}
+}
+const
+{
+ int initialBufferSize = 128;
+}
+static
+{
+ int zero = 0;
+}
+bson* bson_empty(bson* obj)
+{
+static char* data = "\x05\x00\x00\x00\x00";
+return bson_init(obj,data,0);
+}
+void bson_copy(bson* _out, bson* _in);
+bson* bson_from_buffer(bson* b, bson_buffer* buf)
+{
+return bson_init(b,bson_buffer_finish(buf),1);
+}
+bson* bson_init(bson* b, char* data, bson_bool_t mine)
+{
+b.data = data;
+b.owned = mine;
+return b;
+}
+int bson_size(bson* b);
+void bson_destroy(bson* b)
+{
+if (b.owned && b.data)
+free(b.data);
+b.data = null;
+b.owned = 0;
+}
+static
+{
+ char hexbyte(char hex);
+}
+void bson_oid_from_string(bson_oid_t* oid, char* str);
+void bson_oid_to_string(bson_oid_t* oid, char* str);
+void bson_oid_gen(bson_oid_t* oid);
+time_t bson_oid_generated_time(bson_oid_t* oid)
+{
+time_t _out;
+bson_big_endian32(&_out,&oid.ints[0]);
+return _out;
+}
+void bson_print(bson* b)
+{
+bson_print_raw(b.data,0);
+}
+void bson_print_raw(char* data, int depth);
+void bson_iterator_init(bson_iterator* i, char* bson)
+{
+i.cur = bson + 4;
+i.first = 1;
+}
+bson_type bson_find(bson_iterator* it, bson* obj, char* name);
+bson_bool_t bson_iterator_more(bson_iterator* i)
+{
+return *i.cur;
+}
+bson_type bson_iterator_next(bson_iterator* i);
+bson_type bson_iterator_type(bson_iterator* i)
+{
+return cast(bson_type)i.cur[0];
+}
+char* bson_iterator_key(bson_iterator* i)
+{
+return i.cur + 1;
+}
+char* bson_iterator_value(bson_iterator* i)
+{
+char* t = i.cur + 1;
+t += strlen(t) + 1;
+return t;
+}
+int bson_iterator_int_raw(bson_iterator* i)
+{
+int _out;
+bson_little_endian32(&_out,bson_iterator_value(i));
+return _out;
+}
+double bson_iterator_double_raw(bson_iterator* i)
+{
+double _out;
+bson_little_endian64(&_out,bson_iterator_value(i));
+return _out;
+}
+int64_t bson_iterator_long_raw(bson_iterator* i)
+{
+int64_t _out;
+bson_little_endian64(&_out,bson_iterator_value(i));
+return _out;
+}
+bson_bool_t bson_iterator_bool_raw(bson_iterator* i)
+{
+return bson_iterator_value(i)[0];
+}
+bson_oid_t* bson_iterator_oid(bson_iterator* i)
+{
+return cast(bson_oid_t*)bson_iterator_value(i);
+}
+int bson_iterator_int(bson_iterator* i);
+double bson_iterator_double(bson_iterator* i);
+int64_t bson_iterator_long(bson_iterator* i);
+bson_bool_t bson_iterator_bool(bson_iterator* i);
+char* bson_iterator_string(bson_iterator* i)
+{
+return bson_iterator_value(i) + 4;
+}
+int bson_iterator_string_len(bson_iterator* i)
+{
+return bson_iterator_int_raw(i);
+}
+char* bson_iterator_code(bson_iterator* i);
+void bson_iterator_code_scope(bson_iterator* i, bson* _scope);
+bson_date_t bson_iterator_date(bson_iterator* i)
+{
+return bson_iterator_long_raw(i);
+}
+time_t bson_iterator_time_t(bson_iterator* i)
+{
+return bson_iterator_date(i) / 1000;
+}
+int bson_iterator_bin_len(bson_iterator* i)
+{
+return bson_iterator_int_raw(i);
+}
+char bson_iterator_bin_type(bson_iterator* i)
+{
+return bson_iterator_value(i)[4];
+}
+char* bson_iterator_bin_data(bson_iterator* i)
+{
+return bson_iterator_value(i) + 5;
+}
+char* bson_iterator_regex(bson_iterator* i)
+{
+return bson_iterator_value(i);
+}
+char* bson_iterator_regex_opts(bson_iterator* i)
+{
+char* p = bson_iterator_value(i);
+return p + strlen(p) + 1;
+}
+void bson_iterator_subobject(bson_iterator* i, bson* sub)
+{
+bson_init(sub,cast(char*)bson_iterator_value(i),0);
+}
+void bson_iterator_subiterator(bson_iterator* i, bson_iterator* sub)
+{
+bson_iterator_init(sub,bson_iterator_value(i));
+}
+bson_buffer* bson_buffer_init(bson_buffer* b)
+{
+b.buf = cast(char*)bson_malloc(initialBufferSize);
+b.bufSize = initialBufferSize;
+b.cur = b.buf + 4;
+b.finished = 0;
+b.stackPos = 0;
+return b;
+}
+void bson_append_byte(bson_buffer* b, char c)
+{
+b.cur[0] = c;
+b.cur++;
+}
+void bson_append(bson_buffer* b, void* data, int len)
+{
+memcpy(b.cur,data,len);
+b.cur += len;
+}
+void bson_append32(bson_buffer* b, void* data)
+{
+bson_little_endian32(b.cur,data);
+b.cur += 4;
+}
+void bson_append64(bson_buffer* b, void* data)
+{
+bson_little_endian64(b.cur,data);
+b.cur += 8;
+}
+bson_buffer* bson_ensure_space(bson_buffer* b, int bytesNeeded);
+char* bson_buffer_finish(bson_buffer* b);
+void bson_buffer_destroy(bson_buffer* b)
+{
+free(b.buf);
+b.buf = null;
+b.cur = null;
+b.finished = 1;
+}
+static
+{
+ bson_buffer* bson_append_estart(bson_buffer* b, int type, char* name, int dataSize);
+}
+bson_buffer* bson_append_int(bson_buffer* b, char* name, int i);
+bson_buffer* bson_append_long(bson_buffer* b, char* name, int64_t i);
+bson_buffer* bson_append_double(bson_buffer* b, char* name, double d);
+bson_buffer* bson_append_bool(bson_buffer* b, char* name, bson_bool_t i);
+bson_buffer* bson_append_null(bson_buffer* b, char* name);
+bson_buffer* bson_append_undefined(bson_buffer* b, char* name);
+bson_buffer* bson_append_string_base(bson_buffer* b, char* name, char* value, bson_type type);
+bson_buffer* bson_append_string(bson_buffer* b, char* name, char* value)
+{
+return bson_append_string_base(b,name,value,bson_type.bson_string);
+}
+bson_buffer* bson_append_symbol(bson_buffer* b, char* name, char* value)
+{
+return bson_append_string_base(b,name,value,bson_type.bson_symbol);
+}
+bson_buffer* bson_append_code(bson_buffer* b, char* name, char* value)
+{
+return bson_append_string_base(b,name,value,bson_type.bson_code);
+}
+bson_buffer* bson_append_code_w_scope(bson_buffer* b, char* name, char* code, bson* _scope);
+bson_buffer* bson_append_binary(bson_buffer* b, char* name, char type, char* str, int len);
+bson_buffer* bson_append_oid(bson_buffer* b, char* name, bson_oid_t* oid);
+bson_buffer* bson_append_new_oid(bson_buffer* b, char* name)
+{
+bson_oid_t oid;
+bson_oid_gen(&oid);
+return bson_append_oid(b,name,&oid);
+}
+bson_buffer* bson_append_regex(bson_buffer* b, char* name, char* pattern, char* opts);
+bson_buffer* bson_append_bson(bson_buffer* b, char* name, bson* bson);
+bson_buffer* bson_append_element(bson_buffer* b, char* name_or_null, bson_iterator* elem);
+bson_buffer* bson_append_date(bson_buffer* b, char* name, bson_date_t millis);
+bson_buffer* bson_append_time_t(bson_buffer* b, char* name, time_t secs)
+{
+return bson_append_date(b,name,cast(bson_date_t)secs * 1000);
+}
+bson_buffer* bson_append_start_object(bson_buffer* b, char* name);
+bson_buffer* bson_append_start_array(bson_buffer* b, char* name);
+bson_buffer* bson_append_finish_object(bson_buffer* b);
+void* bson_malloc(int size)
+{
+void* p = malloc(size);
+bson_fatal_msg(!!p,"malloc() failed");
+return p;
+}
+static
+{
+ bson_err_handler err_handler = null;
+}
+bson_err_handler set_bson_err_handler(bson_err_handler func)
+{
+bson_err_handler old = err_handler;
+err_handler = func;
+return old;
+}
+void bson_fatal(int ok)
+{
+bson_fatal_msg(ok,"");
+}
+void bson_fatal_msg(int ok, char* msg);
+const
+{
+ char[4][1000] bson_numstrs;
+}
+void bson_numstr(char* str, int i)
+{
+if (i < 1000)
+memcpy(str,&bson_numstrs[i],4);
+else
+sprintf(str,"%d",i);
+}
View
189 src/export/md5.di
@@ -0,0 +1,189 @@
+// D import file generated from 'md5.d'
+module md5;
+private
+{
+ import tango.stdc.string;
+}
+alias uint mongo_md5_word_t;
+alias ubyte mongo_md5_byte_t;
+struct mongo_md5_state_t
+{
+ mongo_md5_word_t[2] count;
+ mongo_md5_word_t[4] abcd;
+ mongo_md5_byte_t[64] buf;
+}
+const
+{
+ mongo_md5_word_t T_MASK = 0;
+}
+private
+{
+ enum
+{
+S11 = 7,
+S12 = 12,
+S13 = 17,
+S14 = 22,
+S21 = 5,
+S22 = 9,
+S23 = 14,
+S24 = 20,
+S31 = 4,
+S32 = 11,
+S33 = 16,
+S34 = 23,
+S41 = 6,
+S42 = 10,
+S43 = 15,
+S44 = 21,
+}
+}
+private
+{
+ uint bswap(uint v)
+{
+uint res;
+byte* in_res = cast(byte*)&res;
+byte* in_v = cast(byte*)&v;
+*(in_res + 0) = *(in_v + 3);
+*(in_res + 1) = *(in_v + 2);
+*(in_res + 2) = *(in_v + 1);
+*(in_res + 3) = *(in_v + 0);
+return res;
+}
+}
+final
+{
+ static
+{
+ private
+{
+ void swap32(void* dst, uint bytes);
+}
+}
+}
+static
+{
+ protected
+{
+ final
+{
+ void littleEndian32(ubyte* input, uint* output);
+}
+}
+}
+private
+{
+ void mongo_md5_process(mongo_md5_state_t* pms, mongo_md5_byte_t* data);
+}
+static
+{
+ protected
+{
+ final
+{
+ uint rotateLeft(uint x, uint n)
+{
+return x << n | x >> 32 - n;
+}
+}
+}
+}
+protected
+{
+ static
+{
+ uint h(uint x, uint y, uint z)
+{
+return x ^ y ^ z;
+}
+}
+}
+protected
+{
+ static
+{
+ uint f(uint x, uint y, uint z)
+{
+return x & y | ~x & z;
+}
+}
+}
+private
+{
+ static
+{
+ uint g(uint x, uint y, uint z)
+{
+return x & z | y & ~z;
+}
+}
+}
+private
+{
+ static
+{
+ uint i(uint x, uint y, uint z)
+{
+return y ^ (x | ~z);
+}
+}
+}
+private
+{
+ static
+{
+ void ff(ref uint a, uint b, uint c, uint d, uint x, uint s, uint ac)
+{
+a += f(b,c,d) + x + ac;
+a = rotateLeft(a,s);
+a += b;
+}
+}
+}
+private
+{
+ static
+{
+ void gg(ref uint a, uint b, uint c, uint d, uint x, uint s, uint ac)
+{
+a += g(b,c,d) + x + ac;
+a = rotateLeft(a,s);
+a += b;
+}
+}
+}
+private
+{
+ static
+{
+ void hh(ref uint a, uint b, uint c, uint d, uint x, uint s, uint ac)
+{
+a += h(b,c,d) + x + ac;
+a = rotateLeft(a,s);
+a += b;
+}
+}
+}
+private
+{
+ static
+{
+ void ii(ref uint a, uint b, uint c, uint d, uint x, uint s, uint ac)
+{
+a += i(b,c,d) + x + ac;
+a = rotateLeft(a,s);
+a += b;
+}
+}
+}
+void mongo_md5_init(mongo_md5_state_t* pms)
+{
+pms.count[0] = (pms.count[1] = 0);
+pms.abcd[0] = 1732584193;
+pms.abcd[1] = T_MASK ^ 271733878;
+pms.abcd[2] = T_MASK ^ 1732584193;
+pms.abcd[3] = 271733878;
+}
+void mongo_md5_append(mongo_md5_state_t* pms, mongo_md5_byte_t* data, int nbytes);
+void mongo_md5_finish(mongo_md5_state_t* pms, mongo_md5_byte_t[16] digest);
View
522 src/export/mongo.di
@@ -0,0 +1,522 @@
+// D import file generated from 'mongo.d'
+module mongo;
+import md5;
+import bson;
+private
+{
+ import tango.stdc.stdlib;
+}
+private
+{
+ import tango.stdc.string;
+}
+private
+{
+ import tango.stdc.stdio;
+}
+private
+{
+ import tango.io.Stdout;
+}
+version (windows)
+{
+ alias int socklen_t;
+}
+else
+{
+ alias int socklen_t;
+}
+static
+{
+ int zero = 0;
+}
+static
+{
+ int one = 1;
+}
+enum mongo_exception_type
+{
+MONGO_EXCEPT_NETWORK = 1,
+MONGO_EXCEPT_FIND_ERR,
+}
+enum mongo_conn_return
+{
+mongo_conn_success = 0,
+mongo_conn_bad_arg,
+mongo_conn_no_socket,
+mongo_conn_fail,
+mongo_conn_not_master,
+}
+struct mongo_connection_options
+{
+ char[255] host;
+ int port;
+}
+alias int bson_bool_t;
+alias byte int8_t;
+alias ubyte uint8_t;
+alias short int16_t;
+alias ushort uint16_t;
+alias int int32_t;
+alias uint uint32_t;
+alias long int64_t;
+alias ulong uint64_t;
+extern (C)
+{
+ union in_addr
+{
+ private
+{
+ union _S_un_t
+{
+ private
+{
+ struct _S_un_b_t
+{
+ uint8_t s_b1;
+ uint8_t s_b2;
+ uint8_t s_b3;
+ uint8_t s_b4;
+}
+}
+ _S_un_b_t S_un_b;
+ private
+{
+ struct _S_un_w_t
+{
+ uint16_t s_w1;
+ uint16_t s_w2;
+}
+}
+ _S_un_w_t S_un_w;
+ uint32_t S_addr;
+}
+}
+ _S_un_t S_un;
+ uint32_t s_addr;
+ struct
+{
+uint8_t s_net;
+uint8_t s_host;
+union
+{
+uint16_t s_imp;
+struct
+{
+uint8_t s_lh;
+uint8_t s_impno;
+}
+}
+}
+}
+}
+enum : int
+{
+AF_UNSPEC = 0,
+AF_UNIX = 1,
+AF_INET = 2,
+AF_IPX = 4,
+AF_APPLETALK = 5,
+AF_INET6 = 10,
+PF_UNSPEC = AF_UNSPEC,
+PF_UNIX = AF_UNIX,
+PF_INET = AF_INET,
+PF_IPX = AF_IPX,
+PF_APPLETALK = AF_APPLETALK,
+PF_INET6 = AF_INET6,
+}
+extern (C)
+{
+ struct sockaddr_in
+{
+ int16_t sin_family = AF_INET;
+ uint16_t sin_port;
+ in_addr sin_addr;
+ ubyte[8] sin_zero;
+}
+}
+const _SIGSET_NWORDS = 1024 / (8 * (uint).sizeof);
+extern (C)
+{
+ struct __sigset_t
+{
+ uint[_SIGSET_NWORDS] __val;
+}
+}
+version (WORDSIZE64)
+{
+ alias short[8] __jmp_buf;
+}
+else
+{
+ alias short[6] __jmp_buf;
+}
+struct __jmp_buf_tag
+{
+ __jmp_buf __jmpbuf;
+ int __mask_was_saved;
+ __sigset_t __saved_mask;
+}
+alias __jmp_buf_tag[1] jmp_buf;
+extern (C)
+{
+ void longjmp(__jmp_buf_tag[1] __env, int __val);
+}
+extern (C)
+{
+ uint16_t htons(uint16_t __hostshort);
+}
+struct mongo_exception_context
+{
+ jmp_buf base_handler;
+ jmp_buf* penv;
+ int caught;
+ mongo_exception_type type;
+}
+struct mongo_header
+{
+ int len;
+ int id;
+ int responseTo;
+ int op;
+}
+struct mongo_message
+{
+ mongo_header head;
+ char data;
+}
+struct mongo_connection
+{
+ mongo_connection_options* left_opts;
+ mongo_connection_options* right_opts;
+ sockaddr_in sa;
+ socklen_t addressSize;
+ int sock;
+ bson_bool_t connected;
+ mongo_exception_context exception;
+}
+struct mongo_reply_fields
+{
+ int flag;
+ int cursorID;
+ int cursorID1;
+ int start;
+ int num;
+}
+struct mongo_reply
+{
+ mongo_header head;
+ mongo_reply_fields fields;
+ char objs;
+}
+struct mongo_cursor
+{
+ mongo_reply* mm;
+ mongo_connection* conn;
+ char* ns;
+ bson current;
+}
+alias int ssize_t;
+extern (C)
+{
+ ssize_t send(int __fd, void* __buf, size_t __n, int __flags);
+}
+extern (C)
+{
+ ssize_t recv(int __fd, void* __buf, size_t __n, int __flags);
+}
+extern (C)
+{
+ int setjmp(jmp_buf __env);
+}
+alias uint32_t in_addr_t;
+extern (C)
+{
+ in_addr_t inet_addr(char* __cp);
+}
+extern (C)
+{
+ int socket(int __domain, int __type, int __protocol);
+}
+enum socket_type
+{
+SOCK_STREAM = 1,
+SOCK_DGRAM = 2,
+SOCK_RAW = 3,
+SOCK_RDM = 4,
+SOCK_SEQPACKET = 5,
+SOCK_DCCP = 6,
+SOCK_PACKET = 10,
+SOCK_CLOEXEC = 524288,
+SOCK_NONBLOCK = 2048,
+}
+extern (C)
+{
+ struct sockaddr
+{
+ ushort sa_family;
+ ubyte[14] sa_data;
+}
+}
+extern (C)
+{
+ int connect(int __fd, sockaddr* __addr, socklen_t __len);
+}
+extern (C)
+{
+ int setsockopt(int __fd, int __level, int __optname, void* __optval, socklen_t __optlen);
+}
+enum
+{
+IPPROTO_IP = 0,
+IPPROTO_HOPOPTS = 0,
+IPPROTO_ICMP = 1,
+IPPROTO_IGMP = 2,
+IPPROTO_IPIP = 4,
+IPPROTO_TCP = 6,
+IPPROTO_EGP = 8,
+IPPROTO_PUP = 12,
+IPPROTO_UDP = 17,
+IPPROTO_IDP = 22,
+IPPROTO_TP = 29,
+IPPROTO_DCCP = 33,
+IPPROTO_IPV6 = 41,
+IPPROTO_ROUTING = 43,
+IPPROTO_FRAGMENT = 44,
+IPPROTO_RSVP = 46,
+IPPROTO_GRE = 47,
+IPPROTO_ESP = 50,
+IPPROTO_AH = 51,
+IPPROTO_ICMPV6 = 58,
+IPPROTO_NONE = 59,
+IPPROTO_DSTOPTS = 60,
+IPPROTO_MTP = 92,
+IPPROTO_ENCAP = 98,
+IPPROTO_PIM = 103,
+IPPROTO_COMP = 108,
+IPPROTO_SCTP = 132,
+IPPROTO_UDPLITE = 136,
+IPPROTO_RAW = 255,
+IPPROTO_MAX,
+}
+enum
+{
+TCP_NODELAY = 1,
+TCP_MAXSEG = 2,
+TCP_CORK = 3,
+TCP_KEEPIDLE = 4,
+TCP_KEEPINTVL = 5,
+TCP_KEEPCNT = 6,
+TCP_SYNCNT = 7,
+TCP_LINGER2 = 8,
+TCP_DEFER_ACCEPT = 9,
+TCP_WINDOW_CLAMP = 10,
+TCP_INFO = 11,
+TCP_QUICKACK = 12,
+TCP_CONGESTION = 13,
+TCP_MD5SIG = 14,
+}
+enum mongo_operations
+{
+mongo_op_msg = 1000,
+mongo_op_update = 2001,
+mongo_op_insert = 2002,
+mongo_op_query = 2004,
+mongo_op_get_more = 2005,
+mongo_op_delete = 2006,
+mongo_op_kill_cursors = 2007,
+}
+static
+{
+ void looping_write(mongo_connection* conn, void* buf, int len);
+}
+static
+{
+ void looping_read(mongo_connection* conn, void* buf, int len);
+}
+void mongo_message_send(mongo_connection* conn, mongo_message* mm);
+char* mongo_data_append(char* start, void* data, int len)
+{
+memcpy(start,data,len);
+return start + len;
+}
+char* mongo_data_append32(char* start, void* data)
+{
+bson_little_endian32(start,data);
+return start + 4;
+}
+char* mongo_data_append64(char* start, void* data)
+{
+bson_little_endian64(start,data);
+return start + 8;
+}
+mongo_message* mongo_message_create(int len, int id, int responseTo, int op)
+{
+mongo_message* mm = cast(mongo_message*)bson_malloc(len);
+if (!id)
+id = rand();
+mm.head.len = len;
+mm.head.id = id;
+mm.head.responseTo = responseTo;
+mm.head.op = op;
+return mm;
+}
+static
+{
+ int mongo_connect_helper(mongo_connection* conn);
+}
+void MONGO_INIT_EXCEPTION(mongo_exception_context* exception_ptr);
+mongo_conn_return mongo_connect(mongo_connection* conn, mongo_connection_options* options);
+static
+{
+ void swap_repl_pair(mongo_connection* conn)
+{
+mongo_connection_options* tmp = conn.left_opts;
+conn.left_opts = conn.right_opts;
+conn.right_opts = tmp;
+}
+}
+mongo_conn_return mongo_connect_pair(mongo_connection* conn, mongo_connection_options* left, mongo_connection_options* right);
+mongo_conn_return mongo_reconnect(mongo_connection* conn);
+void mongo_insert_batch(mongo_connection* conn, char* ns, bson** bsons, int count);
+void mongo_insert(mongo_connection* conn, char* ns, bson* bson)
+{
+char* data;
+mongo_message* mm = mongo_message_create(16 + 4 + strlen(ns) + 1 + bson_size(bson),0,0,mongo_operations.mongo_op_insert);
+data = &mm.data;
+data = mongo_data_append32(data,&zero);
+data = mongo_data_append(data,ns,strlen(ns) + 1);
+data = mongo_data_append(data,bson.data,bson_size(bson));
+mongo_message_send(conn,mm);
+}
+void mongo_update(mongo_connection* conn, char* ns, bson* cond, bson* op, int flags)
+{
+char* data;
+mongo_message* mm = mongo_message_create(16 + 4 + strlen(ns) + 1 + 4 + bson_size(cond) + bson_size(op),0,0,mongo_operations.mongo_op_update);
+data = &mm.data;
+data = mongo_data_append32(data,&zero);
+data = mongo_data_append(data,ns,strlen(ns) + 1);
+data = mongo_data_append32(data,&flags);
+data = mongo_data_append(data,cond.data,bson_size(cond));
+data = mongo_data_append(data,op.data,bson_size(op));
+mongo_message_send(conn,mm);
+}
+void mongo_remove(mongo_connection* conn, char* ns, bson* cond)
+{
+char* data;
+mongo_message* mm = mongo_message_create(16 + 4 + strlen(ns) + 1 + 4 + bson_size(cond),0,0,mongo_operations.mongo_op_delete);
+data = &mm.data;
+data = mongo_data_append32(data,&zero);
+data = mongo_data_append(data,ns,strlen(ns) + 1);
+data = mongo_data_append32(data,&zero);
+data = mongo_data_append(data,cond.data,bson_size(cond));
+mongo_message_send(conn,mm);
+}
+mongo_reply* mongo_read_response(mongo_connection* conn);
+mongo_cursor* mongo_find(mongo_connection* conn, char* ns, bson* query, bson* fields, int nToReturn, int nToSkip, int options);
+bson_bool_t mongo_find_one(mongo_connection* conn, char* ns, bson* query, bson* fields, bson* _out);
+int64_t mongo_count(mongo_connection* conn, char* db, char* ns, bson* query);
+bson_bool_t mongo_disconnect(mongo_connection* conn);
+bson_bool_t mongo_destroy(mongo_connection* conn)
+{
+free(conn.left_opts);
+free(conn.right_opts);
+conn.left_opts = null;
+conn.right_opts = null;
+return mongo_disconnect(conn);
+}
+bson_bool_t mongo_cursor_get_more(mongo_cursor* cursor);
+bson_bool_t mongo_cursor_next(mongo_cursor* cursor);
+void mongo_cursor_destroy(mongo_cursor* cursor);
+static const
+{
+ int MONGO_INDEX_UNIQUE = 1;
+}
+static const
+{
+ int MONGO_INDEX_DROP_DUPS = 2;
+}
+bson_bool_t mongo_create_index(mongo_connection* conn, char* ns, bson* key, int options, bson* _out);
+bson_bool_t mongo_create_simple_index(mongo_connection* conn, char* ns, char* field, int options, bson* _out)
+{
+bson_buffer bb;
+bson b;
+bson_bool_t success;
+bson_buffer_init(&bb);
+bson_append_int(&bb,field,1);
+bson_from_buffer(&b,&bb);
+success = mongo_create_index(conn,ns,&b,options,_out);
+bson_destroy(&b);
+return success;
+}
+bson_bool_t mongo_run_command(mongo_connection* conn, char* db, bson* command, bson* _out)
+{
+bson fields;
+int sl = strlen(db);
+char* ns = cast(char*)bson_malloc(sl + 5 + 1);
+bson_bool_t success;
+strcpy(ns,db);
+strcpy(ns + sl,".$cmd");
+success = mongo_find_one(conn,ns,command,bson_empty(&fields),_out);
+free(ns);
+return success;
+}
+bson_bool_t mongo_simple_int_command(mongo_connection* conn, char* db, char* cmdstr, int arg, bson* realout);
+bson_bool_t mongo_simple_str_command(mongo_connection* conn, char* db, char* cmdstr, char* arg, bson* realout);
+bson_bool_t mongo_cmd_drop_db(mongo_connection* conn, char* db)
+{
+return mongo_simple_int_command(conn,db,"dropDatabase",1,null);
+}
+bson_bool_t mongo_cmd_drop_collection(mongo_connection* conn, char* db, char* collection, bson* _out)
+{
+return mongo_simple_str_command(conn,db,"drop",collection,_out);
+}
+void mongo_cmd_reset_error(mongo_connection* conn, char* db)
+{
+mongo_simple_int_command(conn,db,"reseterror",1,null);
+}
+static
+{
+ bson_bool_t mongo_cmd_get_error_helper(mongo_connection* conn, char* db, bson* realout, char* cmdtype);
+}
+bson_bool_t mongo_cmd_get_prev_error(mongo_connection* conn, char* db, bson* _out)
+{
+return mongo_cmd_get_error_helper(conn,db,_out,"getpreverror");
+}
+bson_bool_t mongo_cmd_get_last_error(mongo_connection* conn, char* db, bson* _out)
+{
+return mongo_cmd_get_error_helper(conn,db,_out,"getlasterror");
+}
+bson_bool_t mongo_cmd_ismaster(mongo_connection* conn, bson* realout);
+static
+{
+ void digest2hex(mongo_md5_byte_t[16] digest, char[33] hex_digest);
+}
+static
+{
+ void mongo_pass_digest(char* user, char* pass, char[33] hex_digest)
+{
+mongo_md5_state_t st;
+mongo_md5_byte_t[16] digest;
+mongo_md5_init(&st);
+mongo_md5_append(&st,cast(mongo_md5_byte_t*)user,strlen(user));
+mongo_md5_append(&st,cast(mongo_md5_byte_t*)":mongo:",7);
+mongo_md5_append(&st,cast(mongo_md5_byte_t*)pass,strlen(pass));
+mongo_md5_finish(&st,digest);
+digest2hex(digest,hex_digest);
+}
+}
+static const
+{
+ int MONGO_UPDATE_UPSERT = 1;
+}
+static const
+{
+ int MONGO_UPDATE_MULTI = 2;
+}
+void mongo_cmd_add_user(mongo_connection* conn, char* db, char* user, char* pass);
+private
+{
+ void MONGO_THROW_GENERIC(mongo_connection* conn, mongo_exception_type type_in);
+}
+bson_bool_t mongo_cmd_authenticate(mongo_connection* conn, char* db, char* user, char* pass);
View
BIN src/libmongod.a
Binary file not shown.
View
387 src/md5.d
@@ -0,0 +1,387 @@
+module md5;
+
+private import tango.stdc.string;
+
+/*
+ Copyright (C) 1999, 2000, 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 acknowledgment 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.c,v 1.6 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.c 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 Clarified derivation from RFC 1321; now handles byte order
+ either statically or dynamically; added missing #include <string.h>
+ in library.
+ 2002-03-11 lpd Corrected argument list for main(), and added int return
+ type, in test program and T value program.
+ 2002-02-21 lpd Added missing #include <stdio.h> in test program.
+ 2000-07-03 lpd Patched to eliminate warnings about "constant is
+ unsigned in ANSI C, signed in traditional"; made test program
+ self-checking.
+ 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
+ 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
+ 1999-05-03 lpd Original version.
+ */
+
+//#include "md5.h"
+//#include <string.h>
+// version !
+// BYTE_ORDER_big_endian
+// BYTE_ORDER_little_endian
+// BYTE_ORDER_unknown
+alias uint mongo_md5_word_t; /* 32-bit byte */
+alias ubyte mongo_md5_byte_t; /* 8-bit byte */
+
+/* Define the state of the MD5 Algorithm. */
+struct mongo_md5_state_t
+{
+ mongo_md5_word_t count[2]; /* message length in bits, lsw first */
+ mongo_md5_word_t abcd[4]; /* digest buffer */
+ mongo_md5_byte_t buf[64]; /* accumulate block */
+};
+
+const mongo_md5_word_t T_MASK = 0;
+
+private enum
+{
+ S11 = 7,
+ S12 = 12,
+ S13 = 17,
+ S14 = 22,
+ S21 = 5,
+ S22 = 9,
+ S23 = 14,
+ S24 = 20,
+ S31 = 4,
+ S32 = 11,
+ S33 = 16,
+ S34 = 23,
+ S41 = 6,
+ S42 = 10,
+ S43 = 15,
+ S44 = 21
+};
+
+/**
+ * Swaps bytes in a 4 byte uint end-to-end, i.e. byte 0 becomes
+ * byte 3, byte 1 becomes byte 2, byte 2 becomes byte 1, byte 3
+ * becomes byte 0.
+ */
+private uint bswap(uint v)
+{
+ uint res;
+ byte* in_res = cast(byte*) &res;
+ byte* in_v = cast(byte*) &v;
+ *(in_res + 0) = *(in_v + 3);
+ *(in_res + 1) = *(in_v + 2);
+ *(in_res + 2) = *(in_v + 1);
+ *(in_res + 3) = *(in_v + 0);
+ return res;
+}
+