int main (int argc, /* IN */ char *argv[]) /* IN */ { char *cwd; char buf[1024]; if (argc <= 1 || !!strcmp (argv[1], "-v")) { mongoc_log_set_handler (log_handler, NULL); } mongoc_init (); cwd = getcwd(buf, sizeof(buf)); assert(cwd); gTestCAFile = bson_strdup_printf("%s/" CAFILE, cwd); gTestPEMFileLocalhost = bson_strdup_printf("%s/" PEMFILE_LOCALHOST, cwd); run_test("/ReplicaSet/ssl/client", &test_replica_set_ssl_client); bson_free(gTestCAFile); bson_free(gTestPEMFileLocalhost); mongoc_cleanup(); return 0; }
int main (int argc, char *argv[]) { double start_time, end_time, delta_time; int64_t count; if (argc < 3) { fprintf(stderr, "usage: %s [options] schema_file mbdump_dir table_names", argv[0]); DIE; } argc--, argv++; strcpy(schema_file, argv[0]); argc--, argv++; strcpy(mbdump_dir, argv[0]); argc--, argv++; test_suite (); mongoc_init (); mongoc_log_set_handler (log_local_handler, NULL); start_time = dtimeofday (); count = execute (argc, &argv[0]); end_time = dtimeofday (); delta_time = end_time - start_time + 0.0000001; fprintf (stderr, "total:\n"); fprintf (stderr, "info: real: %.2f, count: %"PRId64", %"PRId64" docs/sec\n", delta_time, count, (int64_t)round (count/delta_time)); mongoc_cleanup (); return 0; }
/** * Initialize libmongoc. */ void monary_init(void) { mongoc_init(); #ifdef NDEBUG mongoc_log_set_handler(monary_log_func, NULL); #endif DEBUG("%s", "monary module initialized"); }
int mongodb_module_init(struct state_conf *conf, UNUSED char **fields, UNUSED int fieldlens) { char *uri_str = NULL; buffer_fill = 0; const char *db; if (conf->output_args) { uri_str = conf->output_args; } mongoc_init(); mongoc_log_set_handler(mongodb_module_log, NULL); mongoc_uri_t *uri = mongoc_uri_new(uri_str); if (uri == NULL) { log_fatal("mongodb-module", "URI %s not valid!", uri_str); } client = mongoc_client_new_from_uri(uri); db = mongoc_uri_get_database(uri); collection = mongoc_client_get_collection(client, db ? db : strdup("zmap_output"), conf->output_filename ? conf->output_filename : strdup("zmap_output")); bulk = mongoc_collection_create_bulk_operation(collection,false,NULL); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { if (argc <= 1 || !!strcmp(argv[1], "-v")) { mongoc_log_set_handler(log_handler, NULL); } run_test("/mongoc/buffer/basic", test_mongoc_buffer_basic); return 0; }
/** * Instantiate module. * @param[in] conf Module config. * @param[in] instance Module instance. * @return Zero on success. */ static int mod_instantiate(CONF_SECTION *conf, void *instance) { rlm_mongodb_t *inst = instance; inst->name = cf_section_name2(conf); if (!inst->name) { inst->name = cf_section_name1(conf); } if (!strcasecmp(inst->cfg.action, "get")) { inst->action = RLM_MONGODB_GET; cf_log_err_cs(conf, "action 'get' is not implemented"); goto err; } else if (!strcasecmp(inst->cfg.action, "set")) { inst->action = RLM_MONGODB_SET; } else { cf_log_err_cs(conf, "invalid 'action', use'get' or 'set'"); goto err; } if (inst->cfg.remove && inst->cfg.update_query) { cf_log_err_cs(conf, "'update_query' and 'remove' can't be used at the same time"); goto err; } else if (!inst->cfg.remove && !inst->cfg.update_query) { cf_log_err_cs(conf, "'update_query' or 'remove' must be set for 'set' action"); goto err; } if (!cf_pair_find(conf, "pool")) { if (!inst->cfg.server) { cf_log_err_cs(conf, "Invalid or missing 'server' option"); goto err; } } else { if (inst->cfg.server) { cf_log_err_cs(conf, "Can't use server option when foreign connection pool specified"); goto err; } } mongoc_init(); mongoc_log_set_handler(mongoc_log_handler, inst); inst->pool = fr_connection_pool_module_init(conf, inst, mod_conn_create, NULL, inst->name); if (!inst->pool) { goto err; } return 0; err: return -1; }
int main (int argc, char *argv[]) { if (argc <= 1 || !!strcmp(argv[1], "-v")) { mongoc_log_set_handler(log_handler, NULL); } run_test("/mongoc/cursor/get_host", test_get_host); run_test("/mongoc/cursor/clone", test_clone); return 0; }
int main (int argc, char *argv[]) { TestSuite suite; int ret; mongoc_init (); bson_snprintf (MONGOC_TEST_UNIQUE, sizeof MONGOC_TEST_UNIQUE, "test_%u_%u", (unsigned)time (NULL), (unsigned)gettestpid ()); set_mongoc_test_host (); mongoc_log_set_handler (log_handler, NULL); TestSuite_Init (&suite, "", argc, argv); test_array_install (&suite); test_buffer_install (&suite); test_client_install (&suite); test_client_pool_install (&suite); test_write_command_install (&suite); test_bulk_install (&suite); test_collection_install (&suite); test_cursor_install (&suite); test_database_install (&suite); test_gridfs_install (&suite); test_gridfs_file_page_install (&suite); test_list_install (&suite); test_matcher_install (&suite); test_queue_install (&suite); test_read_prefs_install (&suite); test_rpc_install (&suite); test_stream_install (&suite); test_uri_install (&suite); test_write_concern_install (&suite); #ifdef MONGOC_ENABLE_SSL test_x509_install (&suite); test_stream_tls_install (&suite); #endif ret = TestSuite_Run (&suite); TestSuite_Destroy (&suite); mongoc_cleanup(); return ret; }
static MONGO * get_mongodb_connection(void) { persistent_users_db_t * pud = get_persistent_users_db(); MONGO * mydbconnection = (MONGO *) pthread_getspecific(connection_key); if (!mydbconnection) { mongoc_init(); mongoc_log_set_handler(&mongo_logger, NULL); mydbconnection = (MONGO *) turn_malloc(sizeof(MONGO)); mydbconnection->uri = mongoc_uri_new(pud->userdb); if (!mydbconnection->uri) { TURN_LOG_FUNC( TURN_LOG_LEVEL_ERROR, "Cannot open parse MongoDB URI <%s>, connection string format error\n", pud->userdb); MongoFree(mydbconnection); mydbconnection = NULL; } else { mydbconnection->client = mongoc_client_new_from_uri( mydbconnection->uri); if (!mydbconnection->client) { TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Cannot initialize MongoDB connection\n"); MongoFree(mydbconnection); mydbconnection = NULL; } else { mydbconnection->database = mongoc_uri_get_database( mydbconnection->uri); if (!mydbconnection->database) mydbconnection->database = MONGO_DEFAULT_DB; if(mydbconnection) { (void) pthread_setspecific(connection_key, mydbconnection); } TURN_LOG_FUNC( TURN_LOG_LEVEL_INFO, "Opened MongoDB URI <%s>\n", pud->userdb); } } } return mydbconnection; }
int main (int argc, char *argv[]) { TestSuite suite; int ret; mongoc_init(); set_mongoc_test_host(); mongoc_log_set_handler (log_handler, NULL); TestSuite_Init (&suite, "", argc, argv); test_array_install (&suite); test_buffer_install (&suite); test_client_install (&suite); test_client_pool_install (&suite); test_collection_install (&suite); test_cursor_install (&suite); test_database_install (&suite); test_gridfs_install (&suite); test_gridfs_file_page_install (&suite); test_list_install (&suite); test_matcher_install (&suite); test_queue_install (&suite); test_read_prefs_install (&suite); test_rpc_install (&suite); test_stream_install (&suite); test_uri_install (&suite); #ifdef MONGOC_ENABLE_SSL test_x509_install (&suite); test_stream_tls_install (&suite); #endif ret = TestSuite_Run (&suite); TestSuite_Destroy (&suite); return ret; }
static int TestSuite_RunTest (TestSuite *suite, /* IN */ Test *test, /* IN */ int *count) /* INOUT */ { struct timespec ts1; struct timespec ts2; struct timespec ts3; char name[MAX_TEST_NAME_LENGTH]; char buf[MAX_TEST_NAME_LENGTH + 500]; int status = 0; snprintf (name, sizeof name, "%s%s", suite->name, test->name); name [sizeof name - 1] = '\0'; if (!test->check || test->check ()) { _Clock_GetMonotonic (&ts1); /* * TODO: If not verbose, close()/dup(/dev/null) for stdout. */ if (suite->flags & TEST_DEBUGOUTPUT) { _Print_StdOut ("Begin %s\n", name); } if ((suite->flags & TEST_NOFORK)) { #ifdef MONGOC_TRACE if (suite->flags & TEST_TRACE) { mongoc_log_set_handler (mongoc_log_default_handler, NULL); mongoc_log_trace_enable (); } else { mongoc_log_trace_disable (); } #endif srand (test->seed); test->func (test->ctx); status = 0; } else { status = TestSuite_RunFuncInChild (suite, test); } capture_logs (false); if (suite->silent) { return status; } _Clock_GetMonotonic (&ts2); _Clock_Subtract (&ts3, &ts2, &ts1); snprintf (buf, sizeof buf, " { \"status\": \"%s\", " "\"test_file\": \"%s\", " "\"seed\": \"%u\", " "\"start\": %u.%09u, " "\"end\": %u.%09u, " "\"elapsed\": %u.%09u }%s\n", (status == 0) ? "PASS" : "FAIL", name, test->seed, (unsigned)ts1.tv_sec, (unsigned)ts1.tv_nsec, (unsigned)ts2.tv_sec, (unsigned)ts2.tv_nsec, (unsigned)ts3.tv_sec, (unsigned)ts3.tv_nsec, ((*count) == 1) ? "" : ","); buf [sizeof buf - 1] = 0; _Print_StdOut ("%s", buf); if (suite->outfile) { fprintf (suite->outfile, "%s", buf); fflush (suite->outfile); } } else if (!suite->silent) { status = 0; snprintf (buf, sizeof buf, " { \"status\": \"SKIP\", \"test_file\": \"%s\" }%s\n", test->name, ((*count) == 1) ? "" : ","); buf [sizeof buf - 1] = '\0'; _Print_StdOut ("%s", buf); if (suite->outfile) { fprintf (suite->outfile, "%s", buf); fflush (suite->outfile); } } return status ? 1 : 0; }
void R_init_mongolite(DllInfo *info) { static mongoc_log_func_t logfun = mongolite_log_handler; mongoc_init(); mongoc_log_set_handler(logfun, NULL); }