summaryrefslogtreecommitdiffstats
path: root/src/svnqt/contextdata.hpp
blob: e38c6f2a1f3121dea8cfc545079f1186c5d2ebd6 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/***************************************************************************
 *   Copyright (C) 2005-2007 by Rajko Albrecht                             *
 *   ral@alwins-world.de                                                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/
#ifndef SVNCONTEXTDATA_HPP
#define SVNCONTEXTDATA_HPP

#include "svnqt/pool.hpp"
#include "svnqt/apr.hpp"
#include "svnqt/commititem.hpp"
#include "svnqt/svnqt_defines.hpp"

#include <svn_client.h>
#if (SVN_VER_MAJOR >= 1) && (SVN_VER_MINOR >= 4)
#include <svn_auth.h>
#endif
#include <tqstring.h>

struct svn_wc_conflict_result_t;
struct svn_wc_conflict_description_t;

namespace svn {

    class ContextListener;
/**
	@author Rajko Albrecht <ral@alwins-world.de>
*/

class SVNTQT_NOEXPORT ContextData{
public:
    ContextData(const TQString & configDir_);
    ~ContextData();

    // data methods
    svn_client_ctx_t*ctx();
    const TQString&configDir()const;
    void setListener (ContextListener * listener);
    ContextListener * getListener () const;
    void reset();

    // svn methods
    void setAuthCache(bool value);
    /** @see Context::setLogin */
    void setLogin (const TQString& usr, const TQString& pwd);
    /** @see Context::setLogMessage */
    void setLogMessage (const TQString& msg);
    const TQString&getLogMessage ()const;
    /**
     * if the @a listener is set, use it to retrieve the log
     * message using ContextListener::contextGetLogMessage.
     * This return values is given back, then.
     *
     * if the @a listener is not set the its checked whether
     * the log message has been set using @a setLogMessage
     * yet. If not, return false otherwise true
     *
     * @param msg log message
     * @retval false cancel
     */
    bool retrieveLogMessage (TQString & msg,const CommitItemList&);

    /**
     * if the @a listener is set call the method
     * @a contextNotify
     */
    void notify (const char *path,
            svn_wc_notify_action_t action,
            svn_node_kind_t kind,
            const char *mime_type,
            svn_wc_notify_state_t content_state,
            svn_wc_notify_state_t prop_state,
            svn_revnum_t revision);
    void notify (const svn_wc_notify_t *action);
    /**
     * if the @a listener is set call the method
     * @a contextCancel
     */
    bool cancel();
    const TQString& getUsername () const;
    const TQString& getPassword () const;

    /**
     * if the @a listener is set and no password has been
     * set yet, use it to retrieve login and password using
     * ContextListener::contextGetLogin.
     *
     * if the @a listener is not set, check if setLogin
     * has been called yet.
     *
     * @return continue?
     * @retval false cancel
     */
    bool
    retrieveLogin (const char * username_,
                   const char * realm,
                   bool &may_save);
    /**
     * if the @a listener is set and no password has been
     * set yet, use it to retrieve login and password using
     * ContextListener::contextGetSavedLogin.
     *
     * if the @a listener is not set, check if setLogin
     * has been called yet.
     *
     * @return continue?
     * @retval false cancel
     */
    bool
    retrieveSavedLogin(const char * username_,
                       const char * realm,
                       bool &may_save);
    /**
     * if the @a listener is set and no password has been
     * set yet, use it to retrieve login and password using
     * ContextListener::contextGetCachedLogin.
     *
     * if the @a listener is not set, check if setLogin
     * has been called yet.
     *
     * @return continue?
     * @retval false cancel
     */
    bool
    retrieveCachedLogin(const char * username_,
                       const char * realm,
                       bool &may_save);

protected:
    // static methods
    /**
     * the @a baton is interpreted as ContextData *
     * Several checks are performed on the baton:
     * - baton == 0?
     * - baton->Data
     * - listener set?
     *
     * @param baton
     * @param data returned data if everything is OK
     * @retval SVN_NO_ERROR if everything is fine
     * @retval SVN_ERR_CANCELLED on invalid values
     */
    static svn_error_t *
    getContextData (void * baton, ContextData ** data);

    /**
     * this function gets called by the subversion api function
     * when a log message is needed. This is the case on a commit
     * for example
     */
    static svn_error_t *
    onLogMsg (const char **log_msg,
              const char **tmp_file,
              apr_array_header_t * commit_items,
              void *baton,
              apr_pool_t * pool);

    /**
     * this function gets called by the subversion api function
     * when a log message is needed. This is the case on a commit
     * for example
     */
    static svn_error_t *
    onLogMsg2 (const char **log_msg,
              const char **tmp_file,
              const apr_array_header_t * commit_items,
              void *baton,
              apr_pool_t * pool);

#if  ((SVN_VER_MAJOR == 1) && (SVN_VER_MINOR >= 5) || (SVN_VER_MAJOR > 2))
    /**
     * this function gets called by the subversion api function
     * when a log message is needed. This is the case on a commit
     * for example
     */
    static svn_error_t *
    onLogMsg3 (const char **log_msg,
              const char **tmp_file,
              const apr_array_header_t * commit_items,
              void *baton,
              apr_pool_t * pool);
#endif

    /**
     * this is the callback function for the subversion
     * api functions to signal the progress of an action
     */
    static void
    onNotify (void * baton,
              const char *path,
              svn_wc_notify_action_t action,
              svn_node_kind_t kind,
              const char *mime_type,
              svn_wc_notify_state_t content_state,
              svn_wc_notify_state_t prop_state,
              svn_revnum_t revision);
    /**
     * this is the callback function for the subversion 1.2
     * api functions to signal the progress of an action
     *
     * @todo right now we forward only to @a onNotify,
     *       but maybe we should a notify2 to the listener
     * @since subversion 1.2
     */
    static void
    onNotify2(void*baton,const svn_wc_notify_t *action,apr_pool_t */*tpool*/);
    /**
     * this is the callback function for the subversion
     * api functions to signal the progress of an action
     * @param baton pointer to a ContextData instance
     */
    static svn_error_t * onCancel (void * baton);

    /**
     * @see svn_auth_simple_prompt_func_t
     * this method is an alternate and called ONEs before onSimplePrompt.
     * So we can try load password from other source.
     */
    static svn_error_t *
    onCachedPrompt(svn_auth_cred_simple_t **cred,
                           void *baton,
                           const char *realm,
                           const char *username,
                           svn_boolean_t _may_save,
                           apr_pool_t *pool);

    /**
     * @see svn_auth_simple_prompt_func_t
     * this method is an alternate and called ONEs before onSimplePrompt.
     * So we can try load password from other source.
     */
    static svn_error_t *
    onSavedPrompt(svn_auth_cred_simple_t **cred,
                           void *baton,
                           const char *realm,
                           const char *username,
                           svn_boolean_t _may_save,
                           apr_pool_t *pool);
    /**
     * @see svn_auth_simple_prompt_func_t
     */
    static svn_error_t *
    onSimplePrompt (svn_auth_cred_simple_t **cred,
                    void *baton,
                    const char *realm,
                    const char *username,
                    svn_boolean_t _may_save,
                    apr_pool_t *pool);
    /**
     * @see svn_auth_ssl_server_trust_prompt_func_t
     */
    static svn_error_t *
    onSslServerTrustPrompt (svn_auth_cred_ssl_server_trust_t **cred,
                            void *baton,
                            const char *realm,
                            apr_uint32_t failures,
                            const svn_auth_ssl_server_cert_info_t *info,
                            svn_boolean_t may_save,
                            apr_pool_t *pool);
    static svn_error_t *
    onSslClientCertPrompt (svn_auth_cred_ssl_client_cert_t **cred,
                           void *baton,
                           apr_pool_t *pool);
    /**
     * @see svn_auth_ssl_client_cert_pw_prompt_func_t
     */
    static svn_error_t *
    onFirstSslClientCertPw (
            svn_auth_cred_ssl_client_cert_pw_t **cred,
            void *baton,
            const char *realm,
            svn_boolean_t maySave,
            apr_pool_t *pool);

    /**
     * @see svn_auth_ssl_client_cert_pw_prompt_func_t
     */
    static svn_error_t *
    onSslClientCertPwPrompt (
            svn_auth_cred_ssl_client_cert_pw_t **cred,
            void *baton,
            const char *realm,
            svn_boolean_t maySave,
            apr_pool_t *pool);

    /**
     * @see svn_client_ctx_t::progress_func
     */
    static void onProgress(apr_off_t progress, apr_off_t total, void *baton, apr_pool_t *pool);

    /**
     * @see svn_wc_conflict_resolver_func_t
     * @since subversion 1.5
     */
    static svn_error_t* onWcConflictResolver(svn_wc_conflict_result_t**result,const svn_wc_conflict_description_t *description, void *baton, apr_pool_t *pool);

    // extra methods
    svn_error_t *
        generate_cancel_error();

#if  ((SVN_VER_MAJOR == 1) && (SVN_VER_MINOR >= 5) || (SVN_VER_MAJOR > 2))
    /** read in mimetypes map
     * @since subversion 1.5
     */
    void initMimeTypes();
#endif
protected:
    Apr apr;

    ContextListener * listener;
    bool logIsSet;
    int m_promptCounter;
    Pool pool;
    svn_client_ctx_t*m_ctx;
    TQString username;
    TQString password;
    TQString logMessage;
    TQString m_ConfigDir;

};

}

#endif