summaryrefslogtreecommitdiff
path: root/subversion/bindings/javahl/native/Prompter.h
blob: 722abce31cda29bab0be4a692fd7e8002ac8ea22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
 * @copyright
 * ====================================================================
 *    Licensed to the Apache Software Foundation (ASF) under one
 *    or more contributor license agreements.  See the NOTICE file
 *    distributed with this work for additional information
 *    regarding copyright ownership.  The ASF licenses this file
 *    to you 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.
 * ====================================================================
 * @endcopyright
 *
 * @file Prompter.h
 * @brief Interface of the class Prompter
 */

#ifndef PROMPTER_H
#define PROMPTER_H

#include <jni.h>
#include "svn_auth.h"
#include <string>
#include "Pool.h"
/**
 * This class requests username/password and informations about
 * ssl-certificates from the user.
 */
class Prompter
{
 private:
  /**
   * The Java callback object.
   */
  jobject m_prompter;

  /**
   * Tntermediate storage for an answer.
   */
  std::string m_answer;

  /**
   * Flag is the user allowed, that the last answer is stored in the
   * configuration.
   */
  bool m_maySave;

  Prompter(jobject jprompter);
  bool prompt(const char *realm, const char *pi_username, bool maySave);
  bool askYesNo(const char *realm, const char *question, bool yesIsDefault);
  const char *askQuestion(const char *realm, const char *question,
                          bool showAnswer, bool maySave);
  int askTrust(const char *question, bool maySave);
  jstring password();
  jstring username();
  static svn_error_t *simple_prompt(svn_auth_cred_simple_t **cred_p,
                                    void *baton, const char *realm,
                                    const char *username,
                                    svn_boolean_t may_save,
                                    apr_pool_t *pool);
  static svn_error_t *username_prompt
    (svn_auth_cred_username_t **cred_p,
     void *baton,
     const char *realm,
     svn_boolean_t may_save,
     apr_pool_t *pool);
  static svn_error_t *ssl_server_trust_prompt
    (svn_auth_cred_ssl_server_trust_t **cred_p,
     void *baton,
     const char *realm,
     apr_uint32_t failures,
     const svn_auth_ssl_server_cert_info_t *cert_info,
     svn_boolean_t may_save,
     apr_pool_t *pool);
  static svn_error_t *ssl_client_cert_prompt
    (svn_auth_cred_ssl_client_cert_t **cred_p,
     void *baton,
     const char *realm,
     svn_boolean_t may_save,
     apr_pool_t *pool);
  static svn_error_t *ssl_client_cert_pw_prompt
    (svn_auth_cred_ssl_client_cert_pw_t **cred_p,
     void *baton,
     const char *realm,
     svn_boolean_t may_save,
     apr_pool_t *pool);
 public:
  static Prompter *makeCPrompter(jobject jprompter);
  ~Prompter();
  svn_auth_provider_object_t *getProviderUsername(SVN::Pool &in_pool);
  svn_auth_provider_object_t *getProviderSimple(SVN::Pool &in_pool);
  svn_auth_provider_object_t *getProviderServerSSLTrust(SVN::Pool &in_pool);
  svn_auth_provider_object_t *getProviderClientSSL(SVN::Pool &in_pool);
  svn_auth_provider_object_t *getProviderClientSSLPassword(SVN::Pool &in_pool);

  static svn_error_t *plaintext_prompt(svn_boolean_t *may_save_plaintext,
                                       const char *realmstring,
                                       void *baton,
                                       apr_pool_t *pool);
  static svn_error_t *plaintext_passphrase_prompt(
                                      svn_boolean_t *may_save_plaintext,
                                      const char *realmstring,
                                      void *baton,
                                      apr_pool_t *pool);
};

#endif // PROMPTER_H