1 /**
2  * @copyright
3  * ====================================================================
4  *    Licensed to the Apache Software Foundation (ASF) under one
5  *    or more contributor license agreements.  See the NOTICE file
6  *    distributed with this work for additional information
7  *    regarding copyright ownership.  The ASF licenses this file
8  *    to you under the Apache License, Version 2.0 (the
9  *    "License"); you may not use this file except in compliance
10  *    with the License.  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *    Unless required by applicable law or agreed to in writing,
15  *    software distributed under the License is distributed on an
16  *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  *    KIND, either express or implied.  See the License for the
18  *    specific language governing permissions and limitations
19  *    under the License.
20  * ====================================================================
21  * @endcopyright
22  *
23  * @file OperationContext.h
24  * @brief Interface of the class OperationContext
25  */
26 
27 #ifndef JAVAHL_OPERATION_CONTEXT_H
28 #define JAVAHL_OPERATION_CONTEXT_H
29 
30 #include <string>
31 #include <memory>
32 
33 #include "svn_types.h"
34 #include "svn_client.h"
35 #include "private/svn_atomic.h"
36 
37 #include <jni.h>
38 #include "Pool.h"
39 #include "JNIStringHolder.h"
40 #include "CxxCompat.hpp"
41 
42 class Prompter;
43 
44 /**
45  * This class contains a Java objects implementing the interface RaSharedContext
46  */
47 class OperationContext
48 {
49  private:
50   std::string m_userName;
51   std::string m_passWord;
52   std::string m_configDir;
53 
54   apr_hash_t * m_config;
55 
56   JavaHL::cxx::owned_ptr<Prompter> m_prompter;
57   svn_atomic_t m_cancelOperation;
58 
59  protected:
60   SVN::Pool *m_pool;
61 
62   jobject m_jctx;
63   jobject m_jcfgcb;
64   jobject m_jtunnelcb;
65 
66   static void progress(apr_off_t progressVal, apr_off_t total,
67                        void *baton, apr_pool_t *pool);
68   void notifyConfigLoad();
69 
70   static svn_boolean_t checkTunnel(
71       void *tunnel_baton, const char *tunnel_name);
72 
73   static svn_error_t *openTunnel(
74       svn_stream_t **request, svn_stream_t **response,
75       svn_ra_close_tunnel_func_t *close_func, void **close_baton,
76       void *tunnel_baton,
77       const char *tunnel_name, const char *user,
78       const char *hostname, int port,
79       svn_cancel_func_t cancel_func, void *cancel_baton,
80       apr_pool_t *pool);
81 
82   static void closeTunnel(
83       void *tunnel_context, void *tunnel_baton);
84 
85  public:
86   OperationContext(SVN::Pool &pool);
87   void attachJavaObject(jobject contextHolder, const char *contextClassType, const char *contextFieldName, jfieldID * ctxFieldID);
88   virtual ~OperationContext();
89 
90   static svn_error_t *checkCancel(void *cancelBaton);
91 
92   virtual void username(const char *pi_username);
93   virtual void password(const char *pi_password);
94   virtual void setPrompt(JavaHL::cxx::owned_ptr<Prompter> prompter);
95   svn_auth_baton_t *getAuthBaton(SVN::Pool &in_pool);
96 
97   void cancelOperation();
98   void resetCancelRequest();
99   virtual bool isCancelledOperation();
100   jobject getSelf() const;
101   const char *getConfigDirectory() const;
102   const char *getUsername() const;
103   const char *getPassword() const;
104   JavaHL::cxx::owned_ptr<Prompter> clonePrompter() const;
105 
106   /**
107    * Set the configuration directory, taking the usual steps to
108    * ensure that Subversion's config file templates exist in the
109    * specified location.
110    */
111   void setConfigDirectory(const char *configDir);
112 
113   /**
114    * Return configuration data for the context.
115    * Read it from config directory if necessary
116    */
117   apr_hash_t *getConfigData();
118 
119   void setConfigEventHandler(jobject jcfgcb);
120   jobject getConfigEventHandler() const;
121 
122   static svn_error_t * clientName(void *baton, const char **name, apr_pool_t *pool);
123   virtual const char * getClientName() const;
124 
125   virtual void setTunnelCallback(jobject jtunnelcb);
126   jobject getTunnelCallback() const;
127 };
128 
129 #endif // JAVAHL_OPERATION_CONTEXT_H
130