Beispiel #1
0
int workflow::execute(const int argc, const char* argv[]) {
    try {
        const auto o(generate_darting_options(argc, argv));

        /*
         * Can only happen if the options are valid but do not
         * require any action.
         */
        if (!o)
            return 0;

        const auto& s(*o);
        initialise_model_name(s);
        initialise_logging(s);
        dart(s);
    } catch (const darter::parser_validation_error& e) {
        /*
         * Log known not to be initialised as we are still parsing
         * command line options.
         */
        std::cerr << usage_error_msg << e.what() << std::endl
                  << more_information << std::endl;
        return 1;
    } catch (const std::exception& e) {
        report_exception(e);
        return 1;
    } catch(...) {
        report_exception();
        return 1;
    }
    return 0;
}
            static v8::Handle<v8::Value> Include(const v8::Arguments& args) {
                for (int i=0; i < args.Length(); i++) {
                    v8::String::Utf8Value filename(args[i]);

                    std::string javascript_source = load_file(*filename);

                    if (javascript_source.length() > 0) {
                        v8::TryCatch tryCatch;

                        v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(javascript_source.c_str()), v8::String::New(*filename));
                        if (script.IsEmpty()) {
                            std::cerr << "Compiling included script failed:" << std::endl;
                            report_exception(&tryCatch);
                            exit(1);
                        }

                        v8::Handle<v8::Value> result = script->Run();
                        if (result.IsEmpty()) {
                            std::cerr << "Running included script failed:" << std::endl;
                            report_exception(&tryCatch);
                            exit(1);
                        }
                    }
                }
                return v8::Undefined();
            }
Beispiel #3
0
int workflow::execute(const int argc, const char* argv[]) {
    try {
        const auto o(generate_stitching_options_activity(argc, argv));

        /* can only happen if the options are valid but do not
         * require any action.
         */
        if (!o)
            return 0;

        const auto& s(*o);
        initialise_template_name(s);
        initialise_logging_activity(s);
        stitch_activity(s);
    } catch (const stitcher::parser_validation_error& e) {
        /* log known not to be initialised as we are still parsing
         * command line options.
         */
        std::cerr << usage_error_msg << e.what() << std::endl;
        return 1;
    } catch (const std::exception& e) {
        report_exception(e);
        return 1;
    } catch(...) {
        report_exception();
        return 1;
    }
    return 0;
}
Beispiel #4
0
/* create/initialize an object */
DB_ENV_JAVAINFO *
dbjie_construct(JNIEnv *jnienv,
                jobject default_errcall,
                int is_dbopen)
{
    DB_ENV_JAVAINFO *dbjie;

    dbjie = (DB_ENV_JAVAINFO *)malloc(sizeof(DB_ENV_JAVAINFO));
    memset(dbjie, 0, sizeof(DB_ENV_JAVAINFO));
    dbjie->is_dbopen_ = is_dbopen;

    if ((*jnienv)->GetJavaVM(jnienv, &dbjie->javavm_) != 0) {
        free(dbjie);
        report_exception(jnienv, "cannot get Java VM", 0, 0);
        return (NULL);
    }

    /* The default error call just prints to the 'System.err'
     * stream.  If the user does set_errcall to null, we'll
     * want to have a reference to set it back to.
     *
     * Why do we have always set db_errcall to our own callback?
     * Because it makes the interaction between setting the
     * error prefix, error stream, and user's error callback
     * that much easier.
     */
    dbjie->default_errcall_ = NEW_GLOBAL_REF(jnienv, default_errcall);
    dbjie->errcall_ = NEW_GLOBAL_REF(jnienv, default_errcall);
    return (dbjie);
}
Beispiel #5
0
void dbji_set_h_hash_object(DB_JAVAINFO *dbji, JNIEnv *jnienv,
                            DB *db, jobject jhash)
{
    jclass h_hash_class;

    if (dbji->h_hash_method_id_ == NULL) {
        h_hash_class = get_class(jnienv, name_DbHash);
        dbji->h_hash_method_id_ =
            (*jnienv)->GetMethodID(jnienv, h_hash_class,
                                   "hash",
                                   "(Lcom/sleepycat/db/Db;"
                                   "[BI)I");
        if (dbji->h_hash_method_id_ == NULL) {
            /* XXX
             * We should really have a better way
             * to translate this to a Java exception class.
             * In theory, it shouldn't happen.
             */
            report_exception(jnienv, "Cannot find callback method",
                             EFAULT, 0);
            return;
        }
    }

    if (dbji->h_hash_ != NULL)
        DELETE_GLOBAL_REF(jnienv, dbji->h_hash_);

    if (jhash == NULL)
        db->set_h_hash(db, NULL);
    else
        db->set_h_hash(db, Db_h_hash_callback);

    dbji->h_hash_ = NEW_GLOBAL_REF(jnienv, jhash);
}
Beispiel #6
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  // Fetching the high res timer's global scale factor ensures that it
  // is calibrated (if necessary on this platform) at the beginning of
  // the test.  While the timer would otherwise be calibrated on first
  // use, this introduces delay in the middle of the test's execution.
  // This leads to failures due to timing assumptions (timeouts, etc.)
  // within the test itself.
  (void) ACE_High_Res_Timer::global_scale_factor();

  try
  {
    CORBA::ORB_var orb = initialize_orb_and_poa(argc, argv);

    parse_args(argc, argv);

    test_i servant (orb.in());
    CORBA::String_var ior =
      servant.create_and_activate_server();

    write_ior_to_file(ior.in());

    orb->run();
  }
  catch(...)
  {
    report_exception();
    return 1;
  }
  return 0;
}
Beispiel #7
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
  {
    ACE_DEBUG ((LM_DEBUG, "Starting client\n"));
    CORBA::ORB_var orb = initialize_orb_and_poa(argc, argv);

    parse_args(argc, argv);

    ACE_DEBUG ((LM_DEBUG, "Testing remote\n"));
    test_remote_calls(orb.in());

    ACE_DEBUG ((LM_DEBUG, "Testing colocated\n"));
    test_colocated_calls(orb.in());

    ACE_DEBUG ((LM_DEBUG, "Testing ready\n"));
  }
  catch(...)
  {
    report_exception();
    return 1;
  }

  return 0;
}
Beispiel #8
0
void dbji_set_dup_compare_object(DB_JAVAINFO *dbji, JNIEnv *jnienv,
                                 DB *db, jobject jcompare)
{
    jclass dup_compare_class;

    if (dbji->dup_compare_method_id_ == NULL) {
        dup_compare_class = get_class(jnienv, name_DbDupCompare);
        dbji->dup_compare_method_id_ =
            (*jnienv)->GetMethodID(jnienv, dup_compare_class,
                                   "dup_compare",
                                   "(Lcom/sleepycat/db/Db;"
                                   "Lcom/sleepycat/db/Dbt;"
                                   "Lcom/sleepycat/db/Dbt;)I");
        if (dbji->dup_compare_method_id_ == NULL) {
            /* XXX
             * We should really have a better way
             * to translate this to a Java exception class.
             * In theory, it shouldn't happen.
             */
            report_exception(jnienv, "Cannot find callback method",
                             EFAULT, 0);
            return;
        }
    }

    if (dbji->dup_compare_ != NULL)
        DELETE_GLOBAL_REF(jnienv, dbji->dup_compare_);

    if (jcompare == NULL)
        db->set_dup_compare(db, NULL);
    else
        db->set_dup_compare(db, Db_dup_compare_callback);

    dbji->dup_compare_ = NEW_GLOBAL_REF(jnienv, jcompare);
}
Beispiel #9
0
/* If the object is null, report an exception and return false (0),
 * otherwise return true (1).
 */
int verify_non_null(JNIEnv *jnienv, void *obj)
{
	if (obj == NULL) {
		report_exception(jnienv, "null object", EINVAL, 0);
		return (0);
	}
	return (1);
}
Beispiel #10
0
/* If the error code is non-zero, report an exception and return false (0),
 * otherwise return true (1).
 */
int verify_return(JNIEnv *jnienv, int err, unsigned long expect_mask)
{
	if (err == 0)
		return 1;

	report_exception(jnienv, db_strerror(err), err, expect_mask);
	return 0;
}
Beispiel #11
0
int WINAPI WinMain
    (HINSTANCE hInstance
    ,HINSTANCE hPrevInstance
    ,LPSTR     lpCmdLine
    ,int       nCmdShow
    )
#endif // LMI_MSW defined.
{
    // (Historical notes.) Using wx-2.5.1 and mpatrol-1.4.8, both
    // dynamically linked to this application built with gcc-3.2.3,
    // three memory leaks are reported with:
    //   MPATROL_OPTIONS='SHOWUNFREED'
    // It's easier to trace them with:
    //   MPATROL_OPTIONS='LOGALL SHOWUNFREED USEDEBUG'
    // Two are apparently mpatrol artifacts traceable to symbols:
    // [space follows leading underscores in reserved names]
    //   "_ _ _ mp_findsource"
    //   "_ _ _ mp_init"
    // The third is traceable in 'mpatrol.log' with 'USEDEBUG' to
    //   Skeleton::GetEventHashTable() const
    // (although stepping through the code in gdb suggests it's really
    // WinMain(), and mpatrol or libbfd just got the symbol wrong)
    // and seems to be triggered the first time the program allocates
    // memory. The next line forces that to occur here; otherwise,
    // tracing this 'leak' becomes cumbersome and mysterious.
    std::string unused("Seems to trigger initialization of something.");

    int result = EXIT_FAILURE;

    try
        {
        initialize_application();
        initialize_filesystem();
#ifndef LMI_MSW
        result = wxEntry(argc, argv);
#else // LMI_MSW defined.
        result = wxEntry(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
#endif // LMI_MSW defined.
        }
    catch(...)
        {
        try
            {
            report_exception();
            }
        catch(...)
            {
            safely_show_message("Logic error: untrapped exception.");
            }
        }

    fenv_validate();

    return result;
}
Beispiel #12
0
void dbjie_set_tx_recover_object(DB_ENV_JAVAINFO *dbjie, JNIEnv *jnienv,
                                 DB_ENV *dbenv, jobject jtx_recover)
{
    int err;

    if (dbjie->tx_recover_ != NULL) {
        DELETE_GLOBAL_REF(jnienv, dbjie->tx_recover_);
    }
    if (jtx_recover == NULL) {
        if ((err = dbenv->set_tx_recover(dbenv, NULL)) != 0)
            report_exception(jnienv, "set_tx_recover failed",
                             err, 0);
    }
    else {
        if ((err = dbenv->set_tx_recover(dbenv,
                                         DbEnv_tx_recover_callback)) != 0)
            report_exception(jnienv, "set_tx_recover failed",
                             err, 0);
    }

    dbjie->tx_recover_ = NEW_GLOBAL_REF(jnienv, jtx_recover);
}
Beispiel #13
0
void dbjie_set_feedback_object(DB_ENV_JAVAINFO *dbjie, JNIEnv *jnienv,
                               DB_ENV *dbenv, jobject jfeedback)
{
    int err;

    if (dbjie->feedback_ != NULL) {
        DELETE_GLOBAL_REF(jnienv, dbjie->feedback_);
    }
    if (jfeedback == NULL) {
        if ((err = dbenv->set_feedback(dbenv, NULL)) != 0)
            report_exception(jnienv, "set_feedback failed",
                             err, 0);
    }
    else {
        if ((err = dbenv->set_feedback(dbenv,
                                       DbEnv_feedback_callback)) != 0)
            report_exception(jnienv, "set_feedback failed",
                             err, 0);
    }

    dbjie->feedback_ = NEW_GLOBAL_REF(jnienv, jfeedback);
}
Beispiel #14
0
Authenticity& Authenticity::Instance()
{
    try
        {
        static Authenticity z;
        return z;
        }
    catch(...)
        {
        report_exception();
        fatal_error() << "Instantiation failed." << LMI_FLUSH;
        throw "Unreachable--silences a compiler diagnostic.";
        }
}
Beispiel #15
0
MswDllPreloader& MswDllPreloader::instance()
{
    try
        {
        static MswDllPreloader z;
        return z;
        }
    catch(...)
        {
        report_exception();
        fatal_error() << "Instantiation failed." << LMI_FLUSH;
        throw "Unreachable--silences a compiler diagnostic.";
        }
}
Beispiel #16
0
configurable_settings& configurable_settings::instance()
{
    try
        {
        static configurable_settings z;
        return z;
        }
    catch(...)
        {
        report_exception();
        fatal_error() << "Instantiation failed." << LMI_FLUSH;
        throw "Unreachable--silences a compiler diagnostic.";
        }
}
Beispiel #17
0
void dbjie_set_recovery_init_object(DB_ENV_JAVAINFO *dbjie,
                                    JNIEnv *jnienv, DB_ENV *dbenv,
                                    jobject jrecovery_init)
{
    int err;

    if (dbjie->recovery_init_ != NULL) {
        DELETE_GLOBAL_REF(jnienv, dbjie->recovery_init_);
    }
    if (jrecovery_init == NULL) {
        if ((err = dbenv->set_recovery_init(dbenv, NULL)) != 0)
            report_exception(jnienv, "set_recovery_init failed",
                             err, 0);
    }
    else {
        if ((err = dbenv->set_recovery_init(dbenv,
                                            DbEnv_recovery_init_callback)) != 0)
            report_exception(jnienv, "set_recovery_init failed",
                             err, 0);
    }

    dbjie->recovery_init_ = NEW_GLOBAL_REF(jnienv, jrecovery_init);
}
Beispiel #18
0
int test_main(int, char*[])
{
    try
        {
        throw std::runtime_error("  This message should appear on stderr.");
        }
    catch(...)
        {
        report_exception();
        BOOST_TEST(true);
        }

    // Test the
    //   catch(...) { try{report_exception();} catch(...){/*warning*/} }
    // technique to trap every exception--even stealth_exception or an
    // exception derived from it.
    try
        {
        std::cout << "Expect a success message..." << std::endl;
        throw sneaky_exception("ERROR");
        }
    catch(...)
        {
        try
            {
            report_exception(); // Should rethrow.
            BOOST_TEST(false);
            }
        catch(...)
            {
            std::cout << "...Success: caught elusive exception." << std::endl;
            BOOST_TEST(true);
            }
        }

    return 0;
}
Beispiel #19
0
DB_JAVAINFO *dbji_construct(JNIEnv *jnienv, jint flags)
{
    DB_JAVAINFO *dbji;

    dbji = (DB_JAVAINFO *)malloc(sizeof(DB_JAVAINFO));
    memset(dbji, 0, sizeof(DB_JAVAINFO));

    if ((*jnienv)->GetJavaVM(jnienv, &dbji->javavm_) != 0) {
        report_exception(jnienv, "cannot get Java VM", 0, 0);
        free(dbji);
        return (NULL);
    }
    dbji->construct_flags_ = flags;
    return (dbji);
}
Beispiel #20
0
int database_entity::getndata() const
{
    try
        {
        return getndata(axis_lengths_);
        }
    catch(...)
        {
        report_exception();
        fatal_error()
            << "Database item '"
            << GetDBNames()[key_].ShortName
            << "' has invalid dimensions."
            << LMI_FLUSH
            ;
        }
    throw "Unreachable--silences a compiler diagnostic.";
}
Beispiel #21
0
int try_main(int argc, char* argv[])
{
    bool error_flag = false;
    statistics z;
    for(int j = 1; j < argc; ++j)
        {
        try
            {
            z += process_file(argv[j]);
            }
        catch(...)
            {
            error_flag = true;
            std::cerr << "Exception--file '" << argv[j] << "': " << std::flush;
            report_exception();
            }
        }
    z.print_summary();
    return error_flag ? EXIT_FAILURE : EXIT_SUCCESS;
}
Beispiel #22
0
configurable_settings::configurable_settings()
    :calculation_summary_columns_        (default_calculation_summary_columns())
    ,cgi_bin_log_filename_               ("cgi_bin.log"                        )
    ,custom_input_0_filename_            ("custom.ini"                         )
    ,custom_input_1_filename_            ("custom.inix"                        )
    ,custom_output_0_filename_           ("custom.out0"                        )
    ,custom_output_1_filename_           ("custom.out1"                        )
    ,default_input_filename_             ("/etc/opt/lmi/default.ill"           )
    ,libraries_to_preload_               (""                                   )
    ,offer_hobsons_choice_               (false                                )
    ,print_directory_                    ("/var/opt/lmi/spool"                 )
    ,seconds_to_pause_between_printouts_ (10                                   )
    ,skin_filename_                      ("skin.xrc"                           )
    ,spreadsheet_file_extension_         (".gnumeric"                          )
    ,use_builtin_calculation_summary_    (false                                )
    ,xsl_fo_command_                     ("fo"                                 )
{
    ascribe_members();
    load();

    default_input_filename_ = fs::system_complete(default_input_filename_).string();
    print_directory_        = fs::system_complete(print_directory_       ).string();

    try
        {
        validate_directory(print_directory_, "Print directory");
        }
    catch(...)
        {
        report_exception();
        print_directory_ = fs::system_complete(".").string();
        warning()
            << "If possible, current directory '"
            << print_directory_
            << "' will be used for print files instead."
            << LMI_FLUSH
            ;
        validate_directory(print_directory_, "Fallback print directory");
        save();
        }
}
Beispiel #23
0
void dbji_set_bt_prefix_object(DB_JAVAINFO *dbji, JNIEnv *jnienv,
                               DB *db, jobject jprefix)
{
    jclass bt_prefix_class;

    if (dbji->bt_prefix_method_id_ == NULL) {
        bt_prefix_class = get_class(jnienv, name_DbBtreePrefix);
        dbji->bt_prefix_method_id_ =
            (*jnienv)->GetMethodID(jnienv, bt_prefix_class,
                                   "bt_prefix",
                                   "(Lcom/sleepycat/db/Db;"
                                   "Lcom/sleepycat/db/Dbt;"
                                   "Lcom/sleepycat/db/Dbt;)I");
        if (dbji->bt_prefix_method_id_ == NULL) {
            /* XXX
             * We should really have a better way
             * to translate this to a Java exception class.
             * In theory, it shouldn't happen.
             */
            report_exception(jnienv, "Cannot find callback method",
                             EFAULT, 0);
            return;
        }
    }

    if (dbji->bt_prefix_ != NULL) {
        DELETE_GLOBAL_REF(jnienv, dbji->bt_prefix_);
    }
    if (jprefix == NULL) {
        db->set_bt_prefix(db, NULL);
    }
    else {
        db->set_bt_prefix(db, Db_bt_prefix_callback);
    }

    dbji->bt_prefix_ = NEW_GLOBAL_REF(jnienv, jprefix);
}
Beispiel #24
0
void dbji_set_feedback_object(DB_JAVAINFO *dbji, JNIEnv *jnienv,
                              DB *db, jobject jfeedback)
{
    jclass feedback_class;

    if (dbji->feedback_method_id_ == NULL) {
        feedback_class = get_class(jnienv, name_DbFeedback);
        dbji->feedback_method_id_ =
            (*jnienv)->GetMethodID(jnienv, feedback_class,
                                   "feedback",
                                   "(Lcom/sleepycat/db/Db;II)V");
        if (dbji->feedback_method_id_ != NULL) {
            /* XXX
             * We should really have a better way
             * to translate this to a Java exception class.
             * In theory, it shouldn't happen.
             */
            report_exception(jnienv, "Cannot find callback method",
                             EFAULT, 0);
            return;
        }
    }

    if (dbji->feedback_ != NULL) {
        DELETE_GLOBAL_REF(jnienv, dbji->feedback_);
    }
    if (jfeedback == NULL) {
        db->set_feedback(db, NULL);
    }
    else {
        db->set_feedback(db, Db_feedback_callback);
    }

    dbji->feedback_ = NEW_GLOBAL_REF(jnienv, jfeedback);

}
Beispiel #25
0
void dbji_set_append_recno_object(DB_JAVAINFO *dbji, JNIEnv *jnienv,
                                  DB *db, jobject jcallback)
{
    jclass append_recno_class;

    if (dbji->append_recno_method_id_ == NULL) {
        append_recno_class = get_class(jnienv, name_DbAppendRecno);
        dbji->append_recno_method_id_ =
            (*jnienv)->GetMethodID(jnienv, append_recno_class,
                                   "db_append_recno",
                                   "(Lcom/sleepycat/db/Db;"
                                   "Lcom/sleepycat/db/Dbt;I)V");
        if (dbji->append_recno_method_id_ == NULL) {
            /* XXX
             * We should really have a better way
             * to translate this to a Java exception class.
             * In theory, it shouldn't happen.
             */
            report_exception(jnienv, "Cannot find callback method",
                             EFAULT, 0);
            return;
        }
    }

    if (dbji->append_recno_ != NULL) {
        DELETE_GLOBAL_REF(jnienv, dbji->append_recno_);
    }
    if (jcallback == NULL) {
        db->set_append_recno(db, NULL);
    }
    else {
        db->set_append_recno(db, Db_append_recno_callback);
    }

    dbji->append_recno_ = NEW_GLOBAL_REF(jnienv, jcallback);
}
Beispiel #26
0
            Javascript(std::vector<std::string> include_files, const char* filename) : Base() {
//                v8::HandleScope handle_scope;
                v8::Handle<v8::String> init_source = v8::String::New("Osmium = { Callbacks: {}, Output: { } };");
                v8::Handle<v8::Script> init_script = v8::Script::Compile(init_source);
                osmium_object = v8::Persistent<v8::Object>::New(init_script->Run()->ToObject());
                v8::Handle<v8::Object> output_object = osmium_object->Get(v8::String::NewSymbol("Output"))->ToObject();

                osmium_object->Set(v8::String::NewSymbol("debug"), v8::Boolean::New(Osmium::debug()));

                v8::Handle<v8::ObjectTemplate> output_csv_template = v8::ObjectTemplate::New();
                output_csv_template->Set(v8::String::NewSymbol("open"), v8::FunctionTemplate::New(OutputCSVOpen));
                output_object->Set(v8::String::NewSymbol("CSV"), output_csv_template->NewInstance());

#ifdef OSMIUM_WITH_SHPLIB
                v8::Handle<v8::ObjectTemplate> output_shapefile_template = v8::ObjectTemplate::New();
                output_shapefile_template->Set(v8::String::NewSymbol("open"), v8::FunctionTemplate::New(OutputShapefileOpen));
                output_object->Set(v8::String::NewSymbol("Shapefile"), output_shapefile_template->NewInstance());
#endif // OSMIUM_WITH_SHPLIB

                v8::Handle<v8::Object> callbacks_object = osmium_object->Get(v8::String::NewSymbol("Callbacks"))->ToObject();

                v8::TryCatch tryCatch;

                for (std::vector<std::string>::const_iterator vi(include_files.begin()); vi != include_files.end(); vi++) {
                    if (Osmium::debug()) {
                        std::cerr << "include javascript file: " << *vi << std::endl;
                    }
                    std::string javascript_source = load_file((*vi).c_str());
                    v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(javascript_source.c_str()), v8::String::New((*vi).c_str()));
                    if (script.IsEmpty()) {
                        std::cerr << "Compiling script failed:" << std::endl;
                        report_exception(&tryCatch);
                        exit(1);
                    }

                    v8::Handle<v8::Value> result = script->Run();
                    if (result.IsEmpty()) {
                        std::cerr << "Running script failed:" << std::endl;
                        report_exception(&tryCatch);
                        exit(1);
                    }
                }

                std::string javascript_source = load_file(filename);
                if (javascript_source.length() == 0) {
                    std::cerr << "Javascript file " << filename << " is empty" << std::endl;
                    exit(1);
                }

                v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(javascript_source.c_str()), v8::String::New(filename));
                if (script.IsEmpty()) {
                    std::cerr << "Compiling script failed:" << std::endl;
                    report_exception(&tryCatch);
                    exit(1);
                }

                v8::Handle<v8::Value> result = script->Run();
                if (result.IsEmpty()) {
                    std::cerr << "Running script failed:" << std::endl;
                    report_exception(&tryCatch);
                    exit(1);
                }

                v8::Handle<v8::Value> cc;

                cc = callbacks_object->Get(v8::String::NewSymbol("init"));
                if (cc->IsFunction()) {
                    cb.init = v8::Handle<v8::Function>::Cast(cc);
                }
                cc = callbacks_object->Get(v8::String::NewSymbol("node"));
                if (cc->IsFunction()) {
                    cb.node = v8::Handle<v8::Function>::Cast(cc);
                }
                cc = callbacks_object->Get(v8::String::NewSymbol("way"));
                if (cc->IsFunction()) {
                    cb.way = v8::Handle<v8::Function>::Cast(cc);
                }
                cc = callbacks_object->Get(v8::String::NewSymbol("relation"));
                if (cc->IsFunction()) {
                    cb.relation = v8::Handle<v8::Function>::Cast(cc);
                }
                cc = callbacks_object->Get(v8::String::NewSymbol("area"));
                if (cc->IsFunction()) {
                    cb.area = v8::Handle<v8::Function>::Cast(cc);
                }
                cc = callbacks_object->Get(v8::String::NewSymbol("end"));
                if (cc->IsFunction()) {
                    cb.end = v8::Handle<v8::Function>::Cast(cc);
                }
            }
Beispiel #27
0
int try_main(int argc, char* argv[])
{
    int c;
    int option_index = 0;
    // Long options are meta-options not directly supported by the borland
    // librarian. TRICKY !! They are aliased to unlikely octal values.
    static Option long_options[] =
      {
        {"help",         NO_ARG,   0, 001, 0, "display this help and exit"},
        {"license",      NO_ARG,   0, 002, 0, "display license and exit"},
        {"accept",       NO_ARG,   0, 003, 0, "accept license (-l to display)"},
        {"program",      REQD_ARG, 0, 004, 0, "librarian's filepath"},
        {"r",            REQD_ARG, 0, 'r', 0, "see inline documentation"},
        {"s",            REQD_ARG, 0, 's', 0, "see inline documentation"},
        {"u",            REQD_ARG, 0, 'u', 0, "see inline documentation"},
        {"v",            REQD_ARG, 0, 'v', 0, "see inline documentation"},
        {0,              NO_ARG,   0,   0, 0, ""}
      };

    bool license_accepted = false;
    bool show_license     = false;
    bool show_help        = false;

    std::string program;

    std::string library_filename;

    std::string ar_options;

    GetOpt getopt_long
        (argc
        ,argv
        ,""
        ,long_options
        ,&option_index
        ,true
        );
    getopt_long.opterr = false;
    while(EOF != (c = getopt_long()))
        {
        switch(c)
            {
            case 001:
                {
                show_help = true;
                }
                break;

            case 002:
                {
                show_license = true;
                }
                break;

            case 003:
                {
                license_accepted = true;
                }
                break;

            case 004:
                {
                program = getopt_long.optarg;
                }
                break;

            case 'r':
            case 's':
            case 'u':
            case 'v':
                {
                // Do nothing.
                }
                break;

            case '?':
                {
                // Forward any unrecognized options to the tool.
                int offset = getopt_long.optind - 1;
                if(0 < offset)
                    {
                    std::string s = getopt_long.nargv[offset];
                    std::cerr << "Unknown option'" << s << "'.\n";
                    }
                else
                    {
                    std::cerr << "Internal error\n";
                    }
                }
                break;

            default:
                std::cerr << "getopt returned character code 0" << c << '\n';
            }
        }

    if((c = getopt_long.optind) < argc)
        {
        library_filename = std::string(argv[c++]);
        while(c < argc)
            {
            // Forward any unrecognized arguments to the tool.
            ar_options += " +" + std::string(argv[c++]);
            }
        }

    if(!license_accepted)
        {
        std::cerr << license_notices_as_text() << "\n\n";
        }

    if(show_license)
        {
        std::cerr << license_as_text() << "\n\n";
        return EXIT_SUCCESS;
        }

    if(show_help)
        {
        std::cout
            << "This program's emulation of gnu 'ar' is very limited.\n"
            << "Read the inline documentation in file '" __FILE__ "'.\n"
            ;
        getopt_long.usage();
        return EXIT_SUCCESS;
        }

    if("" == program)
        {
        std::cerr << "Must specify --program=(librarian name)\n";
        return EXIT_FAILURE;
        }

    std::remove(library_filename.c_str());

    // The borland librarian allows up to 2^16 'pages', each of a
    // size specified on the command line. The version supplied with
    // their 5.02 compiler fails if the specified page size is not
    // sufficient. The version supplied with their 5.5.1 compiler
    // seems to adjust the page size automatically. It might be nice
    // to perform such an automatic adjustment here for the older
    // version, but we aren't very interested in breathing new life
    // into old tools that were badly designed in the first place.
    std::string command_line =
          program
        + " "
        + "/P1024"
        + " "
        + library_filename
        + " "
        + ar_options
        ;
    try
        {
        system_command(command_line);
        }
    catch(...)
        {
        report_exception();
        std::cerr
            << "Command failed."
            << "\ncommand line: " << command_line
            << '\n'
            << "\nprogram: "      << program
            << "\nlibrary: "      << library_filename
            << "\noptions: "      << ar_options
            << '\n'
            ;
        }
    return 0;
}
Beispiel #28
0
extern int dbji_call_append_recno(DB_JAVAINFO *dbji, DB *db, jobject jdb,
                                  DBT *dbt, jint recno)
{
    JNIEnv *jnienv;
    jobject jdbt;
    DBT_JAVAINFO *dbtji;
    jbyteArray arr;
    unsigned int arraylen;
    unsigned char *data;

    COMPQUIET(db, NULL);
    jnienv = dbji_get_jnienv(dbji);
    if (jnienv == NULL) {
        fprintf(stderr, "Cannot attach to current thread!\n");
        return (0);
    }

    /* XXX
     * We should have a pool of Dbt objects used for this purpose
     * instead of creating new ones each time.  Because of
     * multithreading, we may need an arbitrary number (more than two).
     * We might also have a byte arrays that grow as needed,
     * so we don't need to allocate those either.
     *
     * Note, we do not set the 'create_array_' flag as on other
     * callbacks as we are creating the array here.
     */
    jdbt = create_default_object(jnienv, name_DBT);
    dbtji = get_DBT_JAVAINFO(jnienv, jdbt);
    memcpy(&dbtji->dbt, dbt, sizeof(DBT));
    dbtji->dbt.data = NULL;
    arr = (*jnienv)->NewByteArray(jnienv, dbt->size);
    (*jnienv)->SetByteArrayRegion(jnienv, arr, 0, dbt->size,
                                  (jbyte *)dbt->data);
    dbtji->array_ = (jbyteArray)NEW_GLOBAL_REF(jnienv, arr);

    DB_ASSERT(dbji->append_recno_method_id_ != NULL);
    (*jnienv)->CallVoidMethod(jnienv, dbji->append_recno_,
                              dbji->append_recno_method_id_,
                              jdb, jdbt, recno);

    /* The underlying C API requires that an errno be returned
     * on error.  Java users know nothing of errnos, so we
     * allow them to throw exceptions instead.  We leave the
     * exception in place and return DB_JAVA_CALLBACK to the C API
     * that called us.  Eventually the DB->get will fail and
     * when java prepares to throw an exception in
     * report_exception(), this will be spotted as a special case,
     * and the original exception will be preserved.
     *
     * Note: we have sometimes noticed strange behavior with
     * exceptions under Linux 1.1.7 JVM.  (i.e. multiple calls
     * to ExceptionOccurred() may report different results).
     * Currently we don't know of any problems related to this
     * in our code, but if it pops up in the future, users are
     * encouranged to get a more recent JVM.
     */
    if ((*jnienv)->ExceptionOccurred(jnienv) != NULL)
        return (DB_JAVA_CALLBACK);

    if (dbtji->array_ == NULL) {
        report_exception(jnienv, "Dbt.data is null", 0, 0);
        return (EFAULT);
    }

    arraylen = (*jnienv)->GetArrayLength(jnienv, dbtji->array_);
    if (dbtji->offset_ < 0 ) {
        report_exception(jnienv, "Dbt.offset illegal", 0, 0);
        return (EFAULT);
    }
    if (dbt->ulen + dbtji->offset_ > arraylen) {
        report_exception(jnienv,
                         "Dbt.ulen + Dbt.offset greater than array length", 0, 0);
        return (EFAULT);
    }

    data = (*jnienv)->GetByteArrayElements(jnienv, dbtji->array_,
                                           (jboolean *)0);
    dbt->data = data + dbtji->offset_;
    return (0);
}
Beispiel #29
0
/****************************************************************
 *
 * Implementation of functions to manipulate LOCKED_DBT.
 */
int
locked_dbt_get(LOCKED_DBT *ldbt, JNIEnv *jnienv, DB_ENV *dbenv,
	       jobject jdbt, OpKind kind)
{
	DBT *dbt;

	COMPQUIET(dbenv, NULL);
	ldbt->jdbt = jdbt;
	ldbt->java_array_len = 0;
	ldbt->flags = 0;
	ldbt->kind = kind;
	ldbt->java_data = 0;
	ldbt->before_data = 0;
	ldbt->javainfo =
		(DBT_JAVAINFO *)get_private_dbobj(jnienv, name_DBT, jdbt);

	if (!verify_non_null(jnienv, ldbt->javainfo)) {
		report_exception(jnienv, "Dbt is gc'ed?", 0, 0);
		F_SET(ldbt, LOCKED_ERROR);
		return (EINVAL);
	}
	if (F_ISSET(ldbt->javainfo, DBT_JAVAINFO_LOCKED)) {
		report_exception(jnienv, "Dbt is already in use", 0, 0);
		F_SET(ldbt, LOCKED_ERROR);
		return (EINVAL);
	}
	dbt = &ldbt->javainfo->dbt;

	if ((*jnienv)->GetBooleanField(jnienv,
	    jdbt, fid_Dbt_must_create_data) != 0)
		F_SET(ldbt, LOCKED_CREATE_DATA);
	else
		ldbt->javainfo->array =
			(*jnienv)->GetObjectField(jnienv, jdbt, fid_Dbt_data);

	dbt->size = (*jnienv)->GetIntField(jnienv, jdbt, fid_Dbt_size);
	dbt->ulen = (*jnienv)->GetIntField(jnienv, jdbt, fid_Dbt_ulen);
	dbt->dlen = (*jnienv)->GetIntField(jnienv, jdbt, fid_Dbt_dlen);
	dbt->doff = (*jnienv)->GetIntField(jnienv, jdbt, fid_Dbt_doff);
	dbt->flags = (*jnienv)->GetIntField(jnienv, jdbt, fid_Dbt_flags);
	ldbt->javainfo->offset = (*jnienv)->GetIntField(jnienv, jdbt,
						    fid_Dbt_offset);

	/*
	 * If no flags are set, use default behavior of DB_DBT_MALLOC.
	 * We can safely set dbt->flags because flags will never be copied
	 * back to the Java Dbt.
	 */
	if (kind != inOp &&
	    !F_ISSET(dbt, DB_DBT_USERMEM | DB_DBT_MALLOC | DB_DBT_REALLOC))
		F_SET(dbt, DB_DBT_MALLOC);

	/*
	 * If this is requested to be realloc with an existing array,
	 * we cannot use the underlying realloc, because the array we
	 * will pass in is allocated by the Java VM, not us, so it
	 * cannot be realloced.  We simulate the reallocation by using
	 * USERMEM and reallocating the java array when a ENOMEM error
	 * occurs.  We change the flags during the operation, and they
	 * are reset when the operation completes (in locked_dbt_put).
	 */
	if (F_ISSET(dbt, DB_DBT_REALLOC) && ldbt->javainfo->array != NULL) {
		F_CLR(dbt, DB_DBT_REALLOC);
		F_SET(dbt, DB_DBT_USERMEM);
		F_SET(ldbt, LOCKED_REALLOC_NONNULL);
	}

	if ((F_ISSET(dbt, DB_DBT_USERMEM) || kind != outOp) &&
	    !F_ISSET(ldbt, LOCKED_CREATE_DATA)) {

		/*
		 * If writing with DB_DBT_USERMEM
		 * or it's a set (or get/set) operation,
		 * then the data should point to a java array.
		 * Note that outOp means data is coming out of the database
		 * (it's a get).  inOp means data is going into the database
		 * (either a put, or a key input).
		 */
		if (!ldbt->javainfo->array) {
			report_exception(jnienv, "Dbt.data is null", 0, 0);
			F_SET(ldbt, LOCKED_ERROR);
			return (EINVAL);
		}

		/* Verify other parameters */
		ldbt->java_array_len = (*jnienv)->GetArrayLength(jnienv,
							ldbt->javainfo->array);
		if (ldbt->javainfo->offset < 0 ) {
			report_exception(jnienv, "Dbt.offset illegal", 0, 0);
			F_SET(ldbt, LOCKED_ERROR);
			return (EINVAL);
		}
		if (dbt->size + ldbt->javainfo->offset > ldbt->java_array_len) {
			report_exception(jnienv,
			 "Dbt.size + Dbt.offset greater than array length",
					 0, 0);
			F_SET(ldbt, LOCKED_ERROR);
			return (EINVAL);
		}

		ldbt->java_data = (*jnienv)->GetByteArrayElements(jnienv,
						ldbt->javainfo->array,
						(jboolean *)0);

		dbt->data = ldbt->before_data = ldbt->java_data +
			ldbt->javainfo->offset;
	}
	else if (!F_ISSET(ldbt, LOCKED_CREATE_DATA)) {

		/*
		 * If writing with DB_DBT_MALLOC or DB_DBT_REALLOC with
		 * a null array, then the data is allocated by DB.
		 */
		dbt->data = ldbt->before_data = 0;
	}

	/*
	 * RPC makes the assumption that if dbt->size is non-zero, there
	 * is data to copy from dbt->data.  We may have set dbt->size
	 * to a non-zero integer above but decided not to point
	 * dbt->data at anything.  (One example is if we're doing an outOp
	 * with an already-used Dbt whose values we expect to just
	 * overwrite.)
	 *
	 * Clean up the dbt fields so we don't run into trouble.
	 * (Note that doff, dlen, and flags all may contain meaningful
	 * values.)
	 */
	if (dbt->data == NULL)
		dbt->size = dbt->ulen = 0;

	F_SET(ldbt->javainfo, DBT_JAVAINFO_LOCKED);
	return (0);
}
Beispiel #30
0
std::string Authenticity::Assay
    (calendar_date const& candidate
    ,fs::path const&      data_path
    )
{
    // The cached date is valid unless it's the peremptorily-invalid
    // default value of JDN zero.
    if
        (  calendar_date(jdn_t(0)) != Instance().CachedDate_
        && candidate               == Instance().CachedDate_
        )
        {
        return "cached";
        }

    ResetCache();

    std::ostringstream oss;

    // Read the passkey and valid-date-range files each time
    // because they might change while the program is running.
    // They'll be validated against validated md5sums a fraction
    // of a second later, to guard against fraudulent manipulation.

    // Read saved passkey from file.
    std::string passkey;
    {
    fs::path passkey_path(data_path / "passkey");
    fs::ifstream is(passkey_path);
    if(!is)
        {
        oss
            << "Unable to read passkey file '"
            << passkey_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    is >> passkey;
    if(!is.eof())
        {
        oss
            << "Error reading passkey file '"
            << passkey_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    if(passkey.size() != chars_per_formatted_hex_byte * md5len)
        {
        oss
            << "Length of passkey '"
            << passkey
            << "' is "
            << passkey.size()
            << " but should be "
            << chars_per_formatted_hex_byte * md5len
            << ". Try reinstalling."
            ;
        return oss.str();
        }
    }

    // Read valid date range [begin, end) from file.
    calendar_date begin(last_yyyy_date ());
    calendar_date end  (gregorian_epoch());
    {
    fs::path expiry_path(data_path / "expiry");
    fs::ifstream is(expiry_path);
    if(!is)
        {
        oss
            << "Unable to read expiry file '"
            << expiry_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    is >> begin >> end;
    if(!is || !is.eof())
        {
        oss
            << "Error reading expiry file '"
            << expiry_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }
    }

    // Make sure candidate date is within valid range.
    if(candidate < begin)
        {
        oss
            << "Current date "
            << candidate.str()
            << " is invalid: this system cannot be used before "
            << begin.str()
            << ". Contact the home office."
            ;
        return oss.str();
        }
    if(end <= candidate)
        {
        oss
            << "Current date "
            << candidate.str()
            << " is invalid: this system cannot be used after "
            << (-1 + end).str()
            << ". Contact the home office."
            ;
        return oss.str();
        }

    // Validate all data files.
    fs::path original_path(fs::current_path());
    if(0 != chdir(data_path.string().c_str()))
        {
        oss
            << "Unable to change directory to '"
            << data_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }
    try
        {
        system_command("md5sum --check --status " + std::string(md5sum_file()));
        }
    catch(...)
        {
        report_exception();
        oss
            << "At least one required file is missing, altered, or invalid."
            << " Try reinstalling."
            ;
        return oss.str();
        }
    if(0 != chdir(original_path.string().c_str()))
        {
        oss
            << "Unable to restore directory to '"
            << original_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    // The passkey must match the md5 sum of the md5 sum of the file
    // of md5 sums of secured files.

    char c_passkey[md5len];
    unsigned char u_passkey[md5len];
    std::FILE* md5sums_file = std::fopen
        ((data_path / md5sum_file()).string().c_str()
        ,"rb"
        );
    md5_stream(md5sums_file, u_passkey);
    std::fclose(md5sums_file);
    std::memcpy(c_passkey, u_passkey, md5len);
    md5_buffer(c_passkey, md5len, u_passkey);
    std::memcpy(c_passkey, u_passkey, md5len);
    md5_buffer(c_passkey, md5len, u_passkey);
    std::string expected = md5_hex_string
        (std::vector<unsigned char>(u_passkey, u_passkey + md5len)
        );
    if(passkey != expected)
        {
        oss
            << "Passkey is incorrect for this version."
            << " Contact the home office."
            ;
        return oss.str();
        }
    // Cache the validated date.
    Instance().CachedDate_ = candidate;
    return "validated";
}