jlong
StateReporter::finishReport()
{
  //DEBUG:fprintf(stderr, "  (n) StateReporter::finishReport()\n");

  if (!m_valid) { throw_reporter_inactive(); return SVN_INVALID_REVNUM; }

  SVN::Pool subPool(pool);
  SVN_JNI_ERR(m_raw_reporter->finish_report(m_report_baton,
                                            subPool.getPool()),
              SVN_INVALID_REVNUM);
  m_valid = false;
  return jlong(m_target_revision);
}
apr_hash_t *
OperationContext::getConfigData()
{
  if(m_pool->getPool() == NULL)
    {
      JNIUtil::throwNullPointerException("pool is null");
    }

  if (m_config == NULL)
    {
      const char *configDir = m_configDir.c_str();
      if (m_configDir.empty())
        configDir = NULL;
      SVN_JNI_ERR(
          svn_config_get_config(&m_config, configDir, m_pool->getPool()), NULL);
      notifyConfigLoad();
    }

  return m_config;
}
svn_client_ctx_t *
ClientContext::getContext(CommitMessage *message, SVN::Pool &in_pool)
{
    apr_pool_t *pool = in_pool.getPool();
    svn_client_ctx_t *ctx = m_context;

    /* Make a temporary copy of ctx to restore at pool cleanup to avoid
       leaving references to dangling pointers.

       Note that this allows creating a stack of context changes if
       the function is invoked multiple times with different pools.
     */
    clearctx_baton_t *bt =
      reinterpret_cast<clearctx_baton_t *>(apr_pcalloc(pool, sizeof(*bt)));
    bt->ctx = ctx;
    bt->backup =
      reinterpret_cast<svn_client_ctx_t*>(apr_pmemdup(pool, ctx, sizeof(*ctx)));
    apr_pool_cleanup_register(in_pool.getPool(), bt, clear_ctx_ptrs,
                              clear_ctx_ptrs);

    if (!ctx->config)
      {
        apr_hash_t * configData = getConfigData();

        ctx->config = configData;
        bt->backup->config = ctx->config;
      }

    ctx->auth_baton = getAuthBaton(in_pool);
    ctx->log_msg_baton3 = message;
    resetCancelRequest();

    SVN_JNI_ERR(svn_wc_context_create(&ctx->wc_ctx, NULL,
                                      in_pool.getPool(), in_pool.getPool()),
                NULL);

    return ctx;
}
Exemple #4
0
apr_array_header_t *
CopySources::array(SVN::Pool &pool)
{
  apr_pool_t *p = pool.getPool();

  JNIEnv *env = JNIUtil::getEnv();
  jclass clazz = env->FindClass(JAVA_PACKAGE "/types/CopySource");
  if (JNIUtil::isJavaExceptionThrown())
    return NULL;

  std::vector<jobject> sources = m_copySources.vector();

  apr_array_header_t *copySources =
    apr_array_make(p, static_cast<int>(sources.size()),
                   sizeof(svn_client_copy_source_t *));
  for (std::vector<jobject>::const_iterator it = sources.begin();
        it < sources.end(); ++it)
    {
      svn_client_copy_source_t *src =
        reinterpret_cast<svn_client_copy_source_t *>(apr_palloc(p, sizeof(*src)));

      // Extract the path or URL from the copy source.
      static jmethodID getPath = 0;
      if (getPath == 0)
        {
          getPath = env->GetMethodID(clazz, "getPath",
                                     "()Ljava/lang/String;");
          if (JNIUtil::isJavaExceptionThrown() || getPath == 0)
            return NULL;
        }
      jstring jpath = (jstring)
        env->CallObjectMethod(*it, getPath);
      if (JNIUtil::isJavaExceptionThrown())
        return NULL;

      const char *path = env->GetStringUTFChars(jpath, NULL);
      if (JNIUtil::isJavaExceptionThrown())
        return NULL;

      src->path = apr_pstrdup(p, path);
      env->ReleaseStringUTFChars(jpath, path);
      SVN_JNI_ERR(JNIUtil::preprocessPath(src->path, pool.getPool()),
                  NULL);
      env->DeleteLocalRef(jpath);

      // Extract source revision from the copy source.
      static jmethodID getRevision = 0;
      if (getRevision == 0)
        {
          getRevision = env->GetMethodID(clazz, "getRevision",
                                         "()L"JAVA_PACKAGE"/types/Revision;");
          if (JNIUtil::isJavaExceptionThrown() || getRevision == 0)
            return NULL;
        }
      jobject jrev = env->CallObjectMethod(*it, getRevision);
      if (JNIUtil::isJavaExceptionThrown())
        return NULL;

      // TODO: Default this to svn_opt_revision_undefined (or HEAD)
      Revision rev(jrev);
      src->revision = reinterpret_cast<const svn_opt_revision_t *>
        (apr_pmemdup(p, rev.revision(), sizeof(*src->revision)));
      env->DeleteLocalRef(jrev);

      // Extract pegRevision from the copy source.
      static jmethodID getPegRevision = 0;
      if (getPegRevision == 0)
        {
          getPegRevision = env->GetMethodID(clazz, "getPegRevision",
                                            "()L"JAVA_PACKAGE"/types/Revision;");
          if (JNIUtil::isJavaExceptionThrown() || getPegRevision == 0)
            return NULL;
        }
      jobject jPegRev = env->CallObjectMethod(*it, getPegRevision);
      if (JNIUtil::isJavaExceptionThrown())
        return NULL;

      Revision pegRev(jPegRev, true);
      src->peg_revision = reinterpret_cast<const svn_opt_revision_t *>
        (apr_pmemdup(p, pegRev.revision(), sizeof(*src->peg_revision)));
      env->DeleteLocalRef(jPegRev);

      APR_ARRAY_PUSH(copySources, svn_client_copy_source_t *) = src;
    }

  env->DeleteLocalRef(clazz);

  return copySources;
}
svn_client_ctx_t *
ClientContext::getContext(CommitMessage *message, SVN::Pool &in_pool)
{
    apr_pool_t *pool = in_pool.getPool();
    svn_auth_baton_t *ab;
    svn_client_ctx_t *ctx = m_context;

    /* Make a temporary copy of ctx to restore at pool cleanup to avoid
       leaving references to dangling pointers.

       Note that this allows creating a stack of context changes if
       the function is invoked multiple times with different pools.
     */
    clearctx_baton_t *bt = (clearctx_baton_t *)apr_pcalloc(pool, sizeof(*bt));
    bt->ctx = ctx;
    bt->backup = (svn_client_ctx_t*)apr_pmemdup(pool, ctx, sizeof(*ctx));
    apr_pool_cleanup_register(in_pool.getPool(), bt, clear_ctx_ptrs,
                              clear_ctx_ptrs);


    if (!ctx->config)
      {
        const char *configDir = m_configDir.c_str();
        if (m_configDir.empty())
            configDir = NULL;
        SVN_JNI_ERR(svn_config_get_config(&(ctx->config), configDir,
                                          m_pool->getPool()),
                    NULL);

        bt->backup->config = ctx->config;
      }
    svn_config_t *config = (svn_config_t *) apr_hash_get(ctx->config,
                                                         SVN_CONFIG_CATEGORY_CONFIG,
                                                         APR_HASH_KEY_STRING);


    /* The whole list of registered providers */
    apr_array_header_t *providers;

    /* Populate the registered providers with the platform-specific providers */
    SVN_JNI_ERR(svn_auth_get_platform_specific_client_providers(&providers,
                                                                config,
                                                                pool),
                NULL);

    /* Use the prompter (if available) to prompt for password and cert
     * caching. */
    svn_auth_plaintext_prompt_func_t plaintext_prompt_func = NULL;
    void *plaintext_prompt_baton = NULL;
    svn_auth_plaintext_passphrase_prompt_func_t plaintext_passphrase_prompt_func;
    void *plaintext_passphrase_prompt_baton = NULL;

    if (m_prompter != NULL)
    {
        plaintext_prompt_func = Prompter::plaintext_prompt;
        plaintext_prompt_baton = m_prompter;
        plaintext_passphrase_prompt_func = Prompter::plaintext_passphrase_prompt;
        plaintext_passphrase_prompt_baton = m_prompter;
    }

    /* The main disk-caching auth providers, for both
     * 'username/password' creds and 'username' creds.  */
    svn_auth_provider_object_t *provider;

    svn_auth_get_simple_provider2(&provider, plaintext_prompt_func,
                                  plaintext_prompt_baton, pool);
    APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

    svn_auth_get_username_provider(&provider, pool);
    APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

    /* The server-cert, client-cert, and client-cert-password providers. */
    SVN_JNI_ERR(svn_auth_get_platform_specific_provider(&provider,
                                                        "windows",
                                                        "ssl_server_trust",
                                                        pool),
                NULL);

    if (provider)
        APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

    svn_auth_get_ssl_server_trust_file_provider(&provider, pool);
    APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;
    svn_auth_get_ssl_client_cert_file_provider(&provider, pool);
    APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;
    svn_auth_get_ssl_client_cert_pw_file_provider2(&provider,
                        plaintext_passphrase_prompt_func,
                        plaintext_passphrase_prompt_baton, pool);
    APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

    if (m_prompter != NULL)
    {
        /* Two basic prompt providers: username/password, and just username.*/
        provider = m_prompter->getProviderSimple(in_pool);

        APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

        provider = m_prompter->getProviderUsername(in_pool);
        APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

        /* Three ssl prompt providers, for server-certs, client-certs,
         * and client-cert-passphrases.  */
        provider = m_prompter->getProviderServerSSLTrust(in_pool);
        APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

        provider = m_prompter->getProviderClientSSL(in_pool);
        APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

        provider = m_prompter->getProviderClientSSLPassword(in_pool);
        APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;
    }

    /* Build an authentication baton to give to libsvn_client. */
    svn_auth_open(&ab, providers, pool);

    /* Place any default --username or --password credentials into the
     * auth_baton's run-time parameter hash.  ### Same with --no-auth-cache? */
    if (!m_userName.empty())
        svn_auth_set_parameter(ab, SVN_AUTH_PARAM_DEFAULT_USERNAME,
                               apr_pstrdup(in_pool.getPool(),
                                           m_userName.c_str()));
    if (!m_passWord.empty())
        svn_auth_set_parameter(ab, SVN_AUTH_PARAM_DEFAULT_PASSWORD,
                               apr_pstrdup(in_pool.getPool(),
                                           m_passWord.c_str()));
    /* Store where to retrieve authentication data? */
    if (!m_configDir.empty())
        svn_auth_set_parameter(ab, SVN_AUTH_PARAM_CONFIG_DIR,
                               apr_pstrdup(in_pool.getPool(),
                                           m_configDir.c_str()));

    ctx->auth_baton = ab;
    ctx->log_msg_baton3 = message;
    m_cancelOperation = false;

    SVN_JNI_ERR(svn_wc_context_create(&ctx->wc_ctx, NULL,
                                      in_pool.getPool(), in_pool.getPool()),
                NULL);

    return ctx;
}
svn_auth_baton_t *
OperationContext::getAuthBaton(SVN::Pool &in_pool)
{
  svn_auth_baton_t *ab;
  apr_pool_t *pool = in_pool.getPool();

  apr_hash_t * configData = getConfigData();

  if (configData == NULL)
    {
      return NULL;
    }

  svn_config_t *config = static_cast<svn_config_t *>(apr_hash_get(configData,
      SVN_CONFIG_CATEGORY_CONFIG, APR_HASH_KEY_STRING));

  const bool use_native_store = GlobalConfig::useNativeCredentialsStore();

  /* The whole list of registered providers */
  apr_array_header_t *providers;
  svn_auth_provider_object_t *provider;

  if (use_native_store)
    {
      /* Populate the registered providers with the platform-specific providers */
      SVN_JNI_ERR(
          svn_auth_get_platform_specific_client_providers(
              &providers, config, pool),
          NULL);

      /* Use the prompter (if available) to prompt for password and cert
       * caching. */
      svn_auth_plaintext_prompt_func_t plaintext_prompt_func;
      void *plaintext_prompt_baton;
      svn_auth_plaintext_passphrase_prompt_func_t plaintext_passphrase_prompt_func;
      void *plaintext_passphrase_prompt_baton;

      if (m_prompter.get())
        {
          plaintext_prompt_func = Prompter::plaintext_prompt;
          plaintext_prompt_baton = m_prompter.get();
          plaintext_passphrase_prompt_func = Prompter::plaintext_passphrase_prompt;
          plaintext_passphrase_prompt_baton = m_prompter.get();
        }
      else
        {
          plaintext_prompt_func = NULL;
          plaintext_prompt_baton = NULL;
          plaintext_passphrase_prompt_func = NULL;
          plaintext_passphrase_prompt_baton = NULL;
        }

      /* The main disk-caching auth providers, for both
       * 'username/password' creds and 'username' creds.  */

      svn_auth_get_simple_provider2(&provider, plaintext_prompt_func,
                                    plaintext_prompt_baton, pool);
      APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

      svn_auth_get_username_provider(&provider, pool);
      APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

      svn_auth_get_ssl_server_trust_file_provider(&provider, pool);
      APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;
      svn_auth_get_ssl_client_cert_file_provider(&provider, pool);
      APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;
      svn_auth_get_ssl_client_cert_pw_file_provider2(
          &provider,
          plaintext_passphrase_prompt_func, plaintext_passphrase_prompt_baton,
          pool);
      APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;
    }
  else
    {
      // Not using hte native credentials store, start with an empty
      // providers array.
      providers = apr_array_make(pool, 0, sizeof(svn_auth_provider_object_t *));
    }

  if (m_prompter.get())
    {
      /* Two basic prompt providers: username/password, and just username.*/
      provider = m_prompter->get_provider_simple(in_pool);
      APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

      provider = m_prompter->get_provider_username(in_pool);
      APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

      /* Three ssl prompt providers, for server-certs, client-certs,
       * and client-cert-passphrases.  */
      provider = m_prompter->get_provider_server_ssl_trust(in_pool);
      APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

      provider = m_prompter->get_provider_client_ssl(in_pool);
      APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;

      provider = m_prompter->get_provider_client_ssl_password(in_pool);
      APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider;
    }

  /* Build an authentication baton to give to libsvn_client. */
  svn_auth_open(&ab, providers, pool);

  /* Place any default --username or --password credentials into the
   * auth_baton's run-time parameter hash.  ### Same with --no-auth-cache? */
  if (!m_userName.empty())
    svn_auth_set_parameter(ab, SVN_AUTH_PARAM_DEFAULT_USERNAME,
        apr_pstrdup(in_pool.getPool(), m_userName.c_str()));
  if (!m_passWord.empty())
    svn_auth_set_parameter(ab, SVN_AUTH_PARAM_DEFAULT_PASSWORD,
        apr_pstrdup(in_pool.getPool(), m_passWord.c_str()));
  /* Store where to retrieve authentication data? */
  if (!m_configDir.empty())
    svn_auth_set_parameter(ab, SVN_AUTH_PARAM_CONFIG_DIR,
        apr_pstrdup(in_pool.getPool(), m_configDir.c_str()));
  return ab;
}