File indexing completed on 2024-04-28 05:42:09
0001 /*************************************************************************** 0002 * Copyright (C) 2005-2009 by Rajko Albrecht * 0003 * ral@alwins-world.de * 0004 * * 0005 * This program is free software; you can redistribute it and/or * 0006 * modify it under the terms of the GNU Lesser General Public * 0007 * License as published by the Free Software Foundation; either * 0008 * version 2.1 of the License, or (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0013 * Lesser General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU Lesser General Public * 0016 * License along with this program (in the file LGPL.txt); if not, * 0017 * write to the Free Software Foundation, Inc., 51 Franklin St, * 0018 * Fifth Floor, Boston, MA 02110-1301 USA * 0019 * * 0020 * This software consists of voluntary contributions made by many * 0021 * individuals. For exact contribution history, see the revision * 0022 * history and logs, available at https://commits.kde.org/kdesvn. * 0023 ***************************************************************************/ 0024 #ifndef SVNCONTEXTDATA_HPP 0025 #define SVNCONTEXTDATA_HPP 0026 0027 #include <svnqt/apr.h> 0028 #include <svnqt/commititem.h> 0029 #include <svnqt/pool.h> 0030 #include <svnqt/svnqt_defines.h> 0031 0032 #include <svn_auth.h> 0033 #include <svn_client.h> 0034 0035 #include <QString> 0036 0037 struct svn_wc_conflict_result_t; 0038 struct svn_wc_conflict_description_t; 0039 0040 namespace svn 0041 { 0042 0043 class ContextListener; 0044 /** 0045 @author Rajko Albrecht <ral@alwins-world.de> 0046 */ 0047 0048 class SVNQT_NOEXPORT ContextData 0049 { 0050 public: 0051 explicit ContextData(const QString &configDir_); 0052 ~ContextData(); 0053 0054 // data methods 0055 svn_client_ctx_t *ctx(); 0056 const QString &configDir() const; 0057 void setListener(ContextListener *listener); 0058 ContextListener *getListener() const; 0059 void reset(); 0060 0061 // svn methods 0062 void setAuthCache(bool value); 0063 /** @see Context::setLogin */ 0064 void setLogin(const QString &usr, const QString &pwd); 0065 /** @see Context::setLogMessage */ 0066 void setLogMessage(const QString &msg); 0067 const QString &getLogMessage() const; 0068 /** 0069 * if the @a listener is set, use it to retrieve the log 0070 * message using ContextListener::contextGetLogMessage. 0071 * This return values is given back, then. 0072 * 0073 * if the @a listener is not set the its checked whether 0074 * the log message has been set using @a setLogMessage 0075 * yet. If not, return false otherwise true 0076 * 0077 * @param msg log message 0078 * @retval false cancel 0079 */ 0080 bool retrieveLogMessage(QString &msg, const CommitItemList &); 0081 0082 bool contextAddListItem(DirEntries *entries, const svn_dirent_t *dirent, const svn_lock_t *lock, const QString &path); 0083 0084 /** 0085 * if the @a listener is set call the method 0086 * @a contextNotify 0087 */ 0088 void notify(const char *path, 0089 svn_wc_notify_action_t action, 0090 svn_node_kind_t kind, 0091 const char *mime_type, 0092 svn_wc_notify_state_t content_state, 0093 svn_wc_notify_state_t prop_state, 0094 svn_revnum_t revision); 0095 void notify(const svn_wc_notify_t *action); 0096 /** 0097 * if the @a listener is set call the method 0098 * @a contextCancel 0099 */ 0100 bool cancel(); 0101 const QString &getUsername() const; 0102 const QString &getPassword() const; 0103 0104 /** 0105 * if the @a listener is set and no password has been 0106 * set yet, use it to retrieve login and password using 0107 * ContextListener::contextGetLogin. 0108 * 0109 * if the @a listener is not set, check if setLogin 0110 * has been called yet. 0111 * 0112 * @return continue? 0113 * @retval false cancel 0114 */ 0115 bool retrieveLogin(const char *username_, const char *realm, bool &may_save); 0116 /** 0117 * if the @a listener is set and no password has been 0118 * set yet, use it to retrieve login and password using 0119 * ContextListener::contextGetSavedLogin. 0120 * 0121 * if the @a listener is not set, check if setLogin 0122 * has been called yet. 0123 * 0124 * @return continue? 0125 * @retval false cancel 0126 */ 0127 bool retrieveSavedLogin(const char *username_, const char *realm, bool &may_save); 0128 /** 0129 * if the @a listener is set and no password has been 0130 * set yet, use it to retrieve login and password using 0131 * ContextListener::contextGetCachedLogin. 0132 * 0133 * if the @a listener is not set, check if setLogin 0134 * has been called yet. 0135 * 0136 * @return continue? 0137 * @retval false cancel 0138 */ 0139 bool retrieveCachedLogin(const char *username_, const char *realm, bool &may_save); 0140 0141 protected: 0142 // static methods 0143 /** 0144 * the @a baton is interpreted as ContextData * 0145 * Several checks are performed on the baton: 0146 * - baton == 0? 0147 * - baton->Data 0148 * - listener set? 0149 * 0150 * @param baton 0151 * @param data returned data if everything is OK 0152 * @retval SVN_NO_ERROR if everything is fine 0153 * @retval SVN_ERR_CANCELLED on invalid values 0154 */ 0155 static svn_error_t *getContextData(void *baton, ContextData **data); 0156 0157 /** 0158 * this function gets called by the subversion api function 0159 * when a log message is needed. This is the case on a commit 0160 * for example 0161 */ 0162 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); 0163 0164 /** 0165 * this function gets called by the subversion api function 0166 * when a log message is needed. This is the case on a commit 0167 * for example 0168 */ 0169 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); 0170 0171 /** 0172 * this function gets called by the subversion api function 0173 * when a log message is needed. This is the case on a commit 0174 * for example 0175 */ 0176 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); 0177 0178 /** 0179 * this is the callback function for the subversion 0180 * api functions to signal the progress of an action 0181 */ 0182 static void onNotify(void *baton, 0183 const char *path, 0184 svn_wc_notify_action_t action, 0185 svn_node_kind_t kind, 0186 const char *mime_type, 0187 svn_wc_notify_state_t content_state, 0188 svn_wc_notify_state_t prop_state, 0189 svn_revnum_t revision); 0190 /** 0191 * this is the callback function for the subversion 1.2 0192 * api functions to signal the progress of an action 0193 * 0194 * @todo right now we forward only to @a onNotify, 0195 * but maybe we should a notify2 to the listener 0196 * @since subversion 1.2 0197 */ 0198 static void onNotify2(void *baton, const svn_wc_notify_t *action, apr_pool_t * /*tpool*/); 0199 /** 0200 * this is the callback function for the subversion 0201 * api functions to signal the progress of an action 0202 * @param baton pointer to a ContextData instance 0203 */ 0204 static svn_error_t *onCancel(void *baton); 0205 0206 /** 0207 * @see svn_auth_simple_prompt_func_t 0208 * this method is an alternate and called ONEs before onSimplePrompt. 0209 * So we can try load password from other source. 0210 */ 0211 static svn_error_t * 0212 onCachedPrompt(svn_auth_cred_simple_t **cred, void *baton, const char *realm, const char *username, svn_boolean_t _may_save, apr_pool_t *pool); 0213 0214 /** 0215 * @see svn_auth_simple_prompt_func_t 0216 * this method is an alternate and called ONEs before onSimplePrompt. 0217 * So we can try load password from other source. 0218 */ 0219 static svn_error_t * 0220 onSavedPrompt(svn_auth_cred_simple_t **cred, void *baton, const char *realm, const char *username, svn_boolean_t _may_save, apr_pool_t *pool); 0221 /** 0222 * @see svn_auth_simple_prompt_func_t 0223 */ 0224 static svn_error_t * 0225 onSimplePrompt(svn_auth_cred_simple_t **cred, void *baton, const char *realm, const char *username, svn_boolean_t _may_save, apr_pool_t *pool); 0226 /** 0227 * @see svn_auth_ssl_server_trust_prompt_func_t 0228 */ 0229 static svn_error_t *onSslServerTrustPrompt(svn_auth_cred_ssl_server_trust_t **cred, 0230 void *baton, 0231 const char *realm, 0232 apr_uint32_t failures, 0233 const svn_auth_ssl_server_cert_info_t *info, 0234 svn_boolean_t may_save, 0235 apr_pool_t *pool); 0236 static svn_error_t *onSslClientCertPrompt(svn_auth_cred_ssl_client_cert_t **cred, void *baton, apr_pool_t *pool); 0237 /** 0238 * @see svn_auth_ssl_client_cert_pw_prompt_func_t 0239 */ 0240 static svn_error_t * 0241 onFirstSslClientCertPw(svn_auth_cred_ssl_client_cert_pw_t **cred, void *baton, const char *realm, svn_boolean_t maySave, apr_pool_t *pool); 0242 0243 /** 0244 * @see svn_auth_ssl_client_cert_pw_prompt_func_t 0245 */ 0246 static svn_error_t * 0247 onSslClientCertPwPrompt(svn_auth_cred_ssl_client_cert_pw_t **cred, void *baton, const char *realm, svn_boolean_t maySave, apr_pool_t *pool); 0248 0249 /** 0250 * @see svn_client_ctx_t::progress_func 0251 */ 0252 static void onProgress(apr_off_t progress, apr_off_t total, void *baton, apr_pool_t *pool); 0253 0254 /** 0255 * @see svn_wc_conflict_resolver_func_t 0256 * @since subversion 1.5 0257 */ 0258 static svn_error_t * 0259 onWcConflictResolver(svn_wc_conflict_result_t **result, const svn_wc_conflict_description_t *description, void *baton, apr_pool_t *pool); 0260 0261 /** 0262 * @see svn_wc_conflict_resolver_func2_t 0263 * @since subversion 1.7 0264 */ 0265 static svn_error_t *onWcConflictResolver2(svn_wc_conflict_result_t **result, 0266 const svn_wc_conflict_description2_t *description, 0267 void *baton, 0268 apr_pool_t *result_pool, 0269 apr_pool_t * /*scratch_pool*/); 0270 0271 /** 0272 * @see svn_auth_plaintext_prompt_func_t 0273 * @since subversion 1.6 0274 */ 0275 static svn_error_t *maySavePlaintext(svn_boolean_t *may_save_plaintext, const char *realmstring, void *baton, apr_pool_t *pool); 0276 0277 // extra methods 0278 svn_error_t *generate_cancel_error(); 0279 0280 /** read in mimetypes map 0281 * @since subversion 1.5 0282 */ 0283 void initMimeTypes(); 0284 0285 protected: 0286 Apr apr; 0287 0288 ContextListener *listener; 0289 bool logIsSet; 0290 int m_promptCounter; 0291 Pool pool; 0292 svn_client_ctx_t *m_ctx; 0293 QString username; 0294 QString password; 0295 QString logMessage; 0296 QString m_ConfigDir; 0297 }; 0298 0299 } 0300 0301 #endif