File indexing completed on 2024-05-12 17:16:23
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 http://kdesvn.alwins-world.de. * 0023 ***************************************************************************/ 0024 #ifndef SVNCONTEXTDATA_HPP 0025 #define SVNCONTEXTDATA_HPP 0026 0027 #include <svnqt/pool.h> 0028 #include <svnqt/apr.h> 0029 #include <svnqt/commititem.h> 0030 #include <svnqt/svnqt_defines.h> 0031 0032 #include <svn_client.h> 0033 #include <svn_auth.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 0116 retrieveLogin(const char *username_, 0117 const char *realm, 0118 bool &may_save); 0119 /** 0120 * if the @a listener is set and no password has been 0121 * set yet, use it to retrieve login and password using 0122 * ContextListener::contextGetSavedLogin. 0123 * 0124 * if the @a listener is not set, check if setLogin 0125 * has been called yet. 0126 * 0127 * @return continue? 0128 * @retval false cancel 0129 */ 0130 bool 0131 retrieveSavedLogin(const char *username_, 0132 const char *realm, 0133 bool &may_save); 0134 /** 0135 * if the @a listener is set and no password has been 0136 * set yet, use it to retrieve login and password using 0137 * ContextListener::contextGetCachedLogin. 0138 * 0139 * if the @a listener is not set, check if setLogin 0140 * has been called yet. 0141 * 0142 * @return continue? 0143 * @retval false cancel 0144 */ 0145 bool 0146 retrieveCachedLogin(const char *username_, 0147 const char *realm, 0148 bool &may_save); 0149 0150 protected: 0151 // static methods 0152 /** 0153 * the @a baton is interpreted as ContextData * 0154 * Several checks are performed on the baton: 0155 * - baton == 0? 0156 * - baton->Data 0157 * - listener set? 0158 * 0159 * @param baton 0160 * @param data returned data if everything is OK 0161 * @retval SVN_NO_ERROR if everything is fine 0162 * @retval SVN_ERR_CANCELLED on invalid values 0163 */ 0164 static svn_error_t * 0165 getContextData(void *baton, ContextData **data); 0166 0167 /** 0168 * this function gets called by the subversion api function 0169 * when a log message is needed. This is the case on a commit 0170 * for example 0171 */ 0172 static svn_error_t * 0173 onLogMsg(const char **log_msg, 0174 const char **tmp_file, 0175 apr_array_header_t *commit_items, 0176 void *baton, 0177 apr_pool_t *pool); 0178 0179 /** 0180 * this function gets called by the subversion api function 0181 * when a log message is needed. This is the case on a commit 0182 * for example 0183 */ 0184 static svn_error_t * 0185 onLogMsg2(const char **log_msg, 0186 const char **tmp_file, 0187 const apr_array_header_t *commit_items, 0188 void *baton, 0189 apr_pool_t *pool); 0190 0191 /** 0192 * this function gets called by the subversion api function 0193 * when a log message is needed. This is the case on a commit 0194 * for example 0195 */ 0196 static svn_error_t * 0197 onLogMsg3(const char **log_msg, 0198 const char **tmp_file, 0199 const apr_array_header_t *commit_items, 0200 void *baton, 0201 apr_pool_t *pool); 0202 0203 /** 0204 * this is the callback function for the subversion 0205 * api functions to signal the progress of an action 0206 */ 0207 static void 0208 onNotify(void *baton, 0209 const char *path, 0210 svn_wc_notify_action_t action, 0211 svn_node_kind_t kind, 0212 const char *mime_type, 0213 svn_wc_notify_state_t content_state, 0214 svn_wc_notify_state_t prop_state, 0215 svn_revnum_t revision); 0216 /** 0217 * this is the callback function for the subversion 1.2 0218 * api functions to signal the progress of an action 0219 * 0220 * @todo right now we forward only to @a onNotify, 0221 * but maybe we should a notify2 to the listener 0222 * @since subversion 1.2 0223 */ 0224 static void 0225 onNotify2(void *baton, const svn_wc_notify_t *action, apr_pool_t */*tpool*/); 0226 /** 0227 * this is the callback function for the subversion 0228 * api functions to signal the progress of an action 0229 * @param baton pointer to a ContextData instance 0230 */ 0231 static svn_error_t *onCancel(void *baton); 0232 0233 /** 0234 * @see svn_auth_simple_prompt_func_t 0235 * this method is an alternate and called ONEs before onSimplePrompt. 0236 * So we can try load password from other source. 0237 */ 0238 static svn_error_t * 0239 onCachedPrompt(svn_auth_cred_simple_t **cred, 0240 void *baton, 0241 const char *realm, 0242 const char *username, 0243 svn_boolean_t _may_save, 0244 apr_pool_t *pool); 0245 0246 /** 0247 * @see svn_auth_simple_prompt_func_t 0248 * this method is an alternate and called ONEs before onSimplePrompt. 0249 * So we can try load password from other source. 0250 */ 0251 static svn_error_t * 0252 onSavedPrompt(svn_auth_cred_simple_t **cred, 0253 void *baton, 0254 const char *realm, 0255 const char *username, 0256 svn_boolean_t _may_save, 0257 apr_pool_t *pool); 0258 /** 0259 * @see svn_auth_simple_prompt_func_t 0260 */ 0261 static svn_error_t * 0262 onSimplePrompt(svn_auth_cred_simple_t **cred, 0263 void *baton, 0264 const char *realm, 0265 const char *username, 0266 svn_boolean_t _may_save, 0267 apr_pool_t *pool); 0268 /** 0269 * @see svn_auth_ssl_server_trust_prompt_func_t 0270 */ 0271 static svn_error_t * 0272 onSslServerTrustPrompt(svn_auth_cred_ssl_server_trust_t **cred, 0273 void *baton, 0274 const char *realm, 0275 apr_uint32_t failures, 0276 const svn_auth_ssl_server_cert_info_t *info, 0277 svn_boolean_t may_save, 0278 apr_pool_t *pool); 0279 static svn_error_t * 0280 onSslClientCertPrompt(svn_auth_cred_ssl_client_cert_t **cred, 0281 void *baton, 0282 apr_pool_t *pool); 0283 /** 0284 * @see svn_auth_ssl_client_cert_pw_prompt_func_t 0285 */ 0286 static svn_error_t * 0287 onFirstSslClientCertPw( 0288 svn_auth_cred_ssl_client_cert_pw_t **cred, 0289 void *baton, 0290 const char *realm, 0291 svn_boolean_t maySave, 0292 apr_pool_t *pool); 0293 0294 /** 0295 * @see svn_auth_ssl_client_cert_pw_prompt_func_t 0296 */ 0297 static svn_error_t * 0298 onSslClientCertPwPrompt( 0299 svn_auth_cred_ssl_client_cert_pw_t **cred, 0300 void *baton, 0301 const char *realm, 0302 svn_boolean_t maySave, 0303 apr_pool_t *pool); 0304 0305 /** 0306 * @see svn_client_ctx_t::progress_func 0307 */ 0308 static void onProgress(apr_off_t progress, apr_off_t total, void *baton, apr_pool_t *pool); 0309 0310 /** 0311 * @see svn_wc_conflict_resolver_func_t 0312 * @since subversion 1.5 0313 */ 0314 static svn_error_t *onWcConflictResolver(svn_wc_conflict_result_t **result, const svn_wc_conflict_description_t *description, void *baton, apr_pool_t *pool); 0315 0316 /** 0317 * @see svn_wc_conflict_resolver_func2_t 0318 * @since subversion 1.7 0319 */ 0320 static svn_error_t *onWcConflictResolver2(svn_wc_conflict_result_t **result, 0321 const svn_wc_conflict_description2_t *description, 0322 void *baton, 0323 apr_pool_t *result_pool, 0324 apr_pool_t */*scratch_pool*/); 0325 0326 /** 0327 * @see svn_auth_plaintext_prompt_func_t 0328 * @since subversion 1.6 0329 */ 0330 static svn_error_t *maySavePlaintext(svn_boolean_t *may_save_plaintext, const char *realmstring, void *baton, apr_pool_t *pool); 0331 0332 // extra methods 0333 svn_error_t * 0334 generate_cancel_error(); 0335 0336 /** read in mimetypes map 0337 * @since subversion 1.5 0338 */ 0339 void initMimeTypes(); 0340 0341 protected: 0342 Apr apr; 0343 0344 ContextListener *listener; 0345 bool logIsSet; 0346 int m_promptCounter; 0347 Pool pool; 0348 svn_client_ctx_t *m_ctx; 0349 QString username; 0350 QString password; 0351 QString logMessage; 0352 QString m_ConfigDir; 0353 0354 }; 0355 0356 } 0357 0358 #endif