Index: generic/nsf.decls =================================================================== diff -u -rcbcfec72376d549a806859c873195cc0ebc9c9ea -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- generic/nsf.decls (.../nsf.decls) (revision cbcfec72376d549a806859c873195cc0ebc9c9ea) +++ generic/nsf.decls (.../nsf.decls) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -201,3 +201,7 @@ declare 39 generic { int Nsf_CmdDefinitionRegister(Tcl_Interp *interp, Nsf_methodDefinition *definitionRecords) } +declare 40 generic { + int NsfArgumentError(Tcl_Interp *interp, CONST char *errorMsg, Nsf_Param CONST *paramPtr, + Tcl_Obj *cmdNameObj, Tcl_Obj *methodPathObj) +} Index: generic/stubs8.5/nsfDecls.h =================================================================== diff -u -ra553acc7766b8fccf2ac59226f62266660319c67 -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- generic/stubs8.5/nsfDecls.h (.../nsfDecls.h) (revision a553acc7766b8fccf2ac59226f62266660319c67) +++ generic/stubs8.5/nsfDecls.h (.../nsfDecls.h) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -314,6 +314,14 @@ EXTERN int Nsf_CmdDefinitionRegister(Tcl_Interp *interp, Nsf_methodDefinition *definitionRecords); #endif +#ifndef NsfArgumentError_TCL_DECLARED +#define NsfArgumentError_TCL_DECLARED +/* 40 */ +EXTERN int NsfArgumentError(Tcl_Interp *interp, + CONST char *errorMsg, + Nsf_Param CONST *paramPtr, + Tcl_Obj *cmdNameObj, Tcl_Obj *methodPathObj); +#endif typedef struct NsfStubHooks { struct NsfIntStubs *nsfIntStubs; @@ -363,6 +371,7 @@ int (*nsf_ConvertToTclobj) (Tcl_Interp *interp, Tcl_Obj *objPtr, Nsf_Param CONST *pPtr, ClientData *clientData, Tcl_Obj **outObjPtr); /* 37 */ int (*nsf_EnumerationTypeRegister) (Tcl_Interp *interp, Nsf_EnumeratorConverterEntry *typeRecords); /* 38 */ int (*nsf_CmdDefinitionRegister) (Tcl_Interp *interp, Nsf_methodDefinition *definitionRecords); /* 39 */ + int (*nsfArgumentError) (Tcl_Interp *interp, CONST char *errorMsg, Nsf_Param CONST *paramPtr, Tcl_Obj *cmdNameObj, Tcl_Obj *methodPathObj); /* 40 */ } NsfStubs; extern NsfStubs *nsfStubsPtr; @@ -534,6 +543,10 @@ #define Nsf_CmdDefinitionRegister \ (nsfStubsPtr->nsf_CmdDefinitionRegister) /* 39 */ #endif +#ifndef NsfArgumentError +#define NsfArgumentError \ + (nsfStubsPtr->nsfArgumentError) /* 40 */ +#endif #endif /* defined(USE_NSF_STUBS) && !defined(USE_NSF_STUB_PROCS) */ Index: generic/stubs8.5/nsfStubInit.c =================================================================== diff -u -rcbcfec72376d549a806859c873195cc0ebc9c9ea -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- generic/stubs8.5/nsfStubInit.c (.../nsfStubInit.c) (revision cbcfec72376d549a806859c873195cc0ebc9c9ea) +++ generic/stubs8.5/nsfStubInit.c (.../nsfStubInit.c) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -115,6 +115,7 @@ Nsf_ConvertToTclobj, /* 37 */ Nsf_EnumerationTypeRegister, /* 38 */ Nsf_CmdDefinitionRegister, /* 39 */ + NsfArgumentError, /* 40 */ }; /* !END!: Do not edit above this line. */ Index: generic/stubs8.6/nsfDecls.h =================================================================== diff -u -r2ff112f22072618fa57d835aceafcc10ac3adf5a -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- generic/stubs8.6/nsfDecls.h (.../nsfDecls.h) (revision 2ff112f22072618fa57d835aceafcc10ac3adf5a) +++ generic/stubs8.6/nsfDecls.h (.../nsfDecls.h) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -197,6 +197,11 @@ /* 39 */ EXTERN int Nsf_CmdDefinitionRegister(Tcl_Interp *interp, Nsf_methodDefinition *definitionRecords); +/* 40 */ +EXTERN int NsfArgumentError(Tcl_Interp *interp, + CONST char *errorMsg, + Nsf_Param CONST *paramPtr, + Tcl_Obj *cmdNameObj, Tcl_Obj *methodPathObj); typedef struct { const struct NsfIntStubs *nsfIntStubs; @@ -246,6 +251,7 @@ int (*nsf_ConvertToTclobj) (Tcl_Interp *interp, Tcl_Obj *objPtr, Nsf_Param CONST *pPtr, ClientData *clientData, Tcl_Obj **outObjPtr); /* 37 */ int (*nsf_EnumerationTypeRegister) (Tcl_Interp *interp, Nsf_EnumeratorConverterEntry *typeRecords); /* 38 */ int (*nsf_CmdDefinitionRegister) (Tcl_Interp *interp, Nsf_methodDefinition *definitionRecords); /* 39 */ + int (*nsfArgumentError) (Tcl_Interp *interp, CONST char *errorMsg, Nsf_Param CONST *paramPtr, Tcl_Obj *cmdNameObj, Tcl_Obj *methodPathObj); /* 40 */ } NsfStubs; extern const NsfStubs *nsfStubsPtr; @@ -339,6 +345,8 @@ (nsfStubsPtr->nsf_EnumerationTypeRegister) /* 38 */ #define Nsf_CmdDefinitionRegister \ (nsfStubsPtr->nsf_CmdDefinitionRegister) /* 39 */ +#define NsfArgumentError \ + (nsfStubsPtr->nsfArgumentError) /* 40 */ #endif /* defined(USE_NSF_STUBS) */ Index: generic/stubs8.6/nsfStubInit.c =================================================================== diff -u -rcbcfec72376d549a806859c873195cc0ebc9c9ea -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- generic/stubs8.6/nsfStubInit.c (.../nsfStubInit.c) (revision cbcfec72376d549a806859c873195cc0ebc9c9ea) +++ generic/stubs8.6/nsfStubInit.c (.../nsfStubInit.c) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -115,6 +115,7 @@ Nsf_ConvertToTclobj, /* 37 */ Nsf_EnumerationTypeRegister, /* 38 */ Nsf_CmdDefinitionRegister, /* 39 */ + NsfArgumentError, /* 40 */ }; /* !END!: Do not edit above this line. */ Index: library/mongodb/configure =================================================================== diff -u -r9297b4159bf699939e464a50dedf193406061a77 -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- library/mongodb/configure (.../configure) (revision 9297b4159bf699939e464a50dedf193406061a77) +++ library/mongodb/configure (.../configure) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for nsfmongo 0.3. +# Generated by GNU Autoconf 2.69 for nsfmongo 0.4. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -577,8 +577,8 @@ # Identity of this package. PACKAGE_NAME='nsfmongo' PACKAGE_TARNAME='nsfmongo' -PACKAGE_VERSION='0.3' -PACKAGE_STRING='nsfmongo 0.3' +PACKAGE_VERSION='0.4' +PACKAGE_STRING='nsfmongo 0.4' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1295,7 +1295,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures nsfmongo 0.3 to adapt to many kinds of systems. +\`configure' configures nsfmongo 0.4 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1356,7 +1356,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of nsfmongo 0.3:";; + short | recursive ) echo "Configuration of nsfmongo 0.4:";; esac cat <<\_ACEOF @@ -1467,7 +1467,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -nsfmongo configure 0.3 +nsfmongo configure 0.4 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1832,7 +1832,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by nsfmongo $as_me 0.3, which was +It was created by nsfmongo $as_me 0.4, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -5364,7 +5364,7 @@ if test "${mongo_h_ok}" = "0" ; then as_fn_error $? " - Could not locate bson.h and mongo.h on your machine to build the nsf mongo interface. + Could not locate bson.h and mongoc.h on your machine to build the nsf mongo interface. " "$LINENO" 5 fi @@ -8533,7 +8533,7 @@ $as_echo "#define USE_TCL_STUBS 1" >>confdefs.h -#AC_DEFINE(USE_TK_STUBS) +#AC_DEFINE([USE_TK_STUBS]) if test "$enable_development" = yes; then $as_echo "#define NSF_DEVELOPMENT 1" >>confdefs.h @@ -9246,7 +9246,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by nsfmongo $as_me 0.3, which was +This file was extended by nsfmongo $as_me 0.4, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -9299,7 +9299,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -nsfmongo config.status 0.3 +nsfmongo config.status 0.4 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" Index: library/mongodb/configure.ac =================================================================== diff -u -rcb10c06a3d3ab4a115ea2412c66e0c1554230152 -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- library/mongodb/configure.ac (.../configure.ac) (revision cb10c06a3d3ab4a115ea2412c66e0c1554230152) +++ library/mongodb/configure.ac (.../configure.ac) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -20,7 +20,7 @@ # so you can encode the package version directly into the source files. #----------------------------------------------------------------------- -AC_INIT([nsfmongo], [0.3]) +AC_INIT([nsfmongo], [0.4]) AC_CONFIG_MACRO_DIR([m4]) #-------------------------------------------------------------------- Index: library/mongodb/mongoAPI.decls =================================================================== diff -u -r25023d3c048b369645973fdfa125a3705c7f1898 -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- library/mongodb/mongoAPI.decls (.../mongoAPI.decls) (revision 25023d3c048b369645973fdfa125a3705c7f1898) +++ library/mongodb/mongoAPI.decls (.../mongoAPI.decls) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -15,6 +15,9 @@ mongoc_gridfs_t 1 } +cmd json NsfMongoJson { + {-argName "list" -required 1 -type tclobj} +} cmd close NsfMongoClose { {-argName "conn" -required 1 -type mongoc_client_t -withObj 1} @@ -32,6 +35,7 @@ {-argName "conn" -required 1 -type mongoc_client_t -withObj 1} } + # # collection # Index: library/mongodb/mongoAPI.h =================================================================== diff -u -r64cdee65763cc97c7ae64f6b522c1dee4707ed6e -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- library/mongodb/mongoAPI.h (.../mongoAPI.h) (revision 64cdee65763cc97c7ae64f6b522c1dee4707ed6e) +++ library/mongodb/mongoAPI.h (.../mongoAPI.h) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -85,7 +85,7 @@ /* just to define the symbol */ -static Nsf_methodDefinition method_definitions[29]; +static Nsf_methodDefinition method_definitions[30]; static CONST char *method_command_namespace_names[] = { "::mongo" @@ -142,6 +142,8 @@ NSF_nonnull(2) NSF_nonnull(4); static int NsfMongoGridFileSeekStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []) NSF_nonnull(2) NSF_nonnull(4); +static int NsfMongoJsonStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []) + NSF_nonnull(2) NSF_nonnull(4); static int NsfMongoRunCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []) NSF_nonnull(2) NSF_nonnull(4); static int NsfMongoStatusStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []) @@ -199,6 +201,8 @@ NSF_nonnull(1) NSF_nonnull(2); static int NsfMongoGridFileSeek(Tcl_Interp *interp, mongoc_gridfs_file_t *gridfilePtr, int offset) NSF_nonnull(1) NSF_nonnull(2); +static int NsfMongoJson(Tcl_Interp *interp, Tcl_Obj *list) + NSF_nonnull(1) NSF_nonnull(2); static int NsfMongoRunCmd(Tcl_Interp *interp, int withNocomplain, mongoc_client_t *connPtr, CONST char *db, Tcl_Obj *cmd) NSF_nonnull(1) NSF_nonnull(3) NSF_nonnull(4) NSF_nonnull(5); static int NsfMongoStatus(Tcl_Interp *interp, mongoc_client_t *connPtr, Tcl_Obj *connObj) @@ -231,6 +235,7 @@ NsfMongoGridFileOpenIdx, NsfMongoGridFileReadIdx, NsfMongoGridFileSeekIdx, + NsfMongoJsonIdx, NsfMongoRunCmdIdx, NsfMongoStatusIdx } NsfMethods; @@ -799,6 +804,22 @@ } static int +NsfMongoJsonStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { + (void)clientData; + + + + if (objc != 2) { + return NsfArgumentError(interp, "wrong # of arguments:", + method_definitions[NsfMongoJsonIdx].paramDefs, + NULL, objv[0]); + } + + return NsfMongoJson(interp, objv[1]); + +} + +static int NsfMongoRunCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { ParseContext pc; (void)clientData; @@ -841,7 +862,7 @@ } } -static Nsf_methodDefinition method_definitions[29] = { +static Nsf_methodDefinition method_definitions[30] = { {"::mongo::collection::close", NsfCollectionCloseStub, 1, { {"collection", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Pointer, NULL,NULL,"mongoc_collection_t",NULL,NULL,NULL,NULL,NULL}} }, @@ -962,6 +983,9 @@ {"gridfile", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Pointer, NULL,NULL,"mongoc_gridfs_file_t",NULL,NULL,NULL,NULL,NULL}, {"offset", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Int32, NULL,NULL,"int32",NULL,NULL,NULL,NULL,NULL}} }, +{"::mongo::json", NsfMongoJsonStub, 1, { + {"list", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Tclobj, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}} +}, {"::mongo::run", NsfMongoRunCmdStub, 4, { {"-nocomplain", 0, 0, Nsf_ConvertTo_String, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}, {"conn", NSF_ARG_REQUIRED, 1, Nsf_ConvertTo_Pointer, NULL,NULL,"mongoc_client_t",NULL,NULL,NULL,NULL,NULL}, Index: library/mongodb/nsfmongo.c =================================================================== diff -u -r41f33e57922555885b3b80530a747d8571f73c85 -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- library/mongodb/nsfmongo.c (.../nsfmongo.c) (revision 41f33e57922555885b3b80530a747d8571f73c85) +++ library/mongodb/nsfmongo.c (.../nsfmongo.c) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -492,25 +492,60 @@ */ static int BsonAppendObjv(Tcl_Interp *interp, bson_t *bPtr, int objc, Tcl_Obj **objv) { - int i; + int i, result = TCL_OK; bson_init(bPtr); for (i = 0; i < objc; i += 3) { char *name = ObjStr(objv[i]); char *tag = ObjStr(objv[i+1]); Tcl_Obj *value = objv[i+2]; /*fprintf(stderr, "adding pair '%s' (%s) '%s'\n", name, tag, ObjStr(value));*/ - BsonAppend(interp, bPtr, name, tag, value); + result = BsonAppend(interp, bPtr, name, tag, value); + if (result != TCL_OK) { + break; + } } - - return TCL_OK; + return result; } /*********************************************************************** * Define the api functions ***********************************************************************/ +/* +cmd json NsfMongoJson { + {-argName "list" -required 1 -type tclobj} +} +*/ +static int +NsfMongoJson(Tcl_Interp *interp, Tcl_Obj *listObj) { + bson_t list, *listPtr = &list; + size_t length; + char *jsonString; + int result, objc; + Tcl_Obj **objv; + result = Tcl_ListObjGetElements(interp, listObj, &objc, &objv); + if (result != TCL_OK || (objc % 3 != 0)) { + return NsfPrintError(interp, "%s: must contain a multiple of 3 elements", ObjStr(listObj)); + } + + result = BsonAppendObjv(interp, listPtr, objc, objv); + if (result == TCL_OK) { + jsonString = bson_as_json(listPtr, &length); + if (jsonString != NULL) { + Tcl_SetObjResult(interp, Tcl_NewStringObj(jsonString, length)); + bson_free(jsonString); + } else { + result = NsfPrintError(interp, "invalid bson string: %s", ObjStr(listObj)); + } + + bson_destroy( listPtr ); + } + + return result; +} + /* cmd close NsfMongoClose { {-argName "conn" -required 1 -type mongoc_client_t -withObj 1} Index: library/mongodb/pkgIndex.add =================================================================== diff -u -r32da8e731670bb8bcb2841ed8aea72d54d6c5b1d -r9e8610ba86e16a518747bd25907d04b2aaf19dd5 --- library/mongodb/pkgIndex.add (.../pkgIndex.add) (revision 32da8e731670bb8bcb2841ed8aea72d54d6c5b1d) +++ library/mongodb/pkgIndex.add (.../pkgIndex.add) (revision 9e8610ba86e16a518747bd25907d04b2aaf19dd5) @@ -1 +1 @@ -package ifneeded nsf::mongo 0.3 [list load [file join $dir libnsfmongo0.3.dylib]] +package ifneeded nsf::mongo 0.4 [list load [file join $dir libnsfmongo0.4.dylib]]