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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
|
/*-
* Copyright (C) 2007-2011 Peter de Ridder <peter@xfce.org>
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <glib.h>
#include <gtk/gtk.h>
#include <libxfce4util/libxfce4util.h>
#include <apr_lib.h>
#include <subversion-1/svn_cmdline.h>
#include <subversion-1/svn_client.h>
#include <subversion-1/svn_pools.h>
#include <subversion-1/svn_fs.h>
#include <subversion-1/svn_time.h>
#include <subversion-1/svn_props.h>
#include "tsh-dialog-common.h"
#include "tsh-login-dialog.h"
#include "tsh-file-dialog.h"
#include "tsh-trust-dialog.h"
#include "tsh-notify-dialog.h"
#include "tsh-status-dialog.h"
#include "tsh-log-message-dialog.h"
#include "tsh-log-dialog.h"
#include "tsh-blame-dialog.h"
#include "tsh-properties-dialog.h"
#include "tsh-common.h"
static svn_error_t* tsh_auth_simple_plaintext_prompt(svn_boolean_t*, const char*, void*, apr_pool_t*) G_GNUC_UNUSED;
static svn_error_t* tsh_auth_simple_prompt(svn_auth_cred_simple_t**, void*, const char*, const char*, svn_boolean_t, apr_pool_t*);
static svn_error_t* tsh_auth_username_prompt(svn_auth_cred_username_t**, void*, const char*, svn_boolean_t, apr_pool_t*);
static svn_error_t* tsh_auth_ssl_server_trust_prompt(svn_auth_cred_ssl_server_trust_t**, void*, const char*, apr_uint32_t, const svn_auth_ssl_server_cert_info_t*, svn_boolean_t, apr_pool_t*);
static svn_error_t* tsh_auth_ssl_client_cert_prompt(svn_auth_cred_ssl_client_cert_t**, void*, const char*, svn_boolean_t, apr_pool_t*);
static svn_error_t* tsh_auth_ssl_client_cert_pw_prompt(svn_auth_cred_ssl_client_cert_pw_t**, void*, const char*, svn_boolean_t, apr_pool_t*);
static svn_error_t* tsh_check_cancel(void*);
static gboolean cancelled = FALSE;
gboolean tsh_init (apr_pool_t **ppool, svn_error_t **perr)
{
apr_pool_t *pool;
svn_error_t *err;
if (perr)
*perr = NULL;
if (!ppool)
return FALSE;
/* Initialize svn stuff */
if (svn_cmdline_init (G_LOG_DOMAIN, stderr) != EXIT_SUCCESS)
{
*ppool = NULL;
return FALSE;
}
*ppool = pool = svn_pool_create (NULL);
/* Initialize utf routines.
* This is only for performance, don't think the plugin actualy uses it.
* Removed because of compile error with libsvn 1.6 */
/* svn_utf_initialize (pool); */
/* Initialize FS lib */
if ((err = svn_fs_initialize (pool)))
{
if (perr)
*perr = err;
return FALSE;
}
if ((err = svn_config_ensure (NULL, pool)))
{
if (perr)
*perr = err;
return FALSE;
}
#ifdef G_OS_WIN32
/* Set the working copy administrative directory name */
if (getenv ("SVN_ASP_DOT_NET_HACK"))
{
if(err = svn_wc_set_adm_dir ("_svn", pool))
{
if (perr)
*perr = err;
return FALSE;
}
}
#endif
return TRUE;
}
gboolean tsh_create_context (svn_client_ctx_t **pctx, apr_pool_t *pool, svn_error_t **perr)
{
svn_auth_provider_object_t *provider;
apr_array_header_t *providers;
svn_error_t *err;
svn_boolean_t cache = TRUE;
svn_auth_baton_t *ab;
svn_config_t *cfg;
svn_client_ctx_t *ctx;
if (perr)
*perr = NULL;
if (!pctx)
return FALSE;
if (!pool)
return FALSE;
/* Create the client context */
#if CHECK_SVN_VERSION_G(1,8)
if ((err = svn_client_create_context2 (pctx, NULL, pool)))
#else
if ((err = svn_client_create_context (pctx, pool)))
#endif
{
if (perr)
*perr = err;
return FALSE;
}
ctx = *pctx;
/* Get the config */
if ((err = svn_config_get_config(&(ctx->config), NULL, pool)))
{
if (perr)
*perr = err;
return FALSE;
}
cfg = apr_hash_get(ctx->config, SVN_CONFIG_CATEGORY_CONFIG,
APR_HASH_KEY_STRING);
/* Set cancel funvtion */
ctx->cancel_func = tsh_check_cancel;
#if CHECK_SVN_VERSION(1,5)
/* Create an array to hold the providers */
providers = apr_array_make (pool, 12, sizeof (svn_auth_provider_object_t *));
/* Disk caching auth providers */
#ifdef G_OS_WIN32
svn_auth_get_windows_simple_provider (&provider, pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
#endif
#ifdef SVN_HAVE_KEYCHAIN_SERVICES
svn_auth_get_keychain_simple_provider (&provider, pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
#endif
#else /* CHECK_SVN_VERSION(1,6)*/
/* Create an array to hold the providers */
svn_auth_get_platform_specific_client_providers (&providers, cfg, pool);
#endif
/* Disk caching auth providers */
#if CHECK_SVN_VERSION(1,5)
svn_auth_get_simple_provider (&provider, pool);
#else /* CHECK_SVN_VERSION(1,6)*/
svn_auth_get_simple_provider2 (&provider, tsh_auth_simple_plaintext_prompt, NULL, pool);
#endif
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
svn_auth_get_username_provider (&provider, pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
/* Cert auth providers */
#if CHECK_SVN_VERSION(1,5)
#ifdef G_OS_WIN32
svn_auth_get_windows_ssl_server_trust_provider (&provider, pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
#endif
#else /* CHECK_SVN_VERSION(1,6)*/
svn_auth_get_platform_specific_provider (&provider, "windows", "ssl_server_trust", pool);
if (provider)
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
#endif
svn_auth_get_ssl_server_trust_file_provider (&provider, pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
svn_auth_get_ssl_client_cert_file_provider (&provider, pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
#if CHECK_SVN_VERSION(1,5)
svn_auth_get_ssl_client_cert_pw_file_provider (&provider, pool);
#else /* CHECK_SVN_VERSION(1,6)*/
svn_auth_get_ssl_client_cert_pw_file_provider2 (&provider, tsh_auth_simple_plaintext_prompt, NULL, pool);
#endif
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
/* Prompt providers */
svn_auth_get_simple_prompt_provider (&provider,
tsh_auth_simple_prompt,
NULL,
2,
pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
svn_auth_get_username_prompt_provider (&provider,
tsh_auth_username_prompt,
NULL,
2,
pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
svn_auth_get_ssl_server_trust_prompt_provider (&provider,
tsh_auth_ssl_server_trust_prompt,
NULL,
pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
svn_auth_get_ssl_client_cert_prompt_provider (&provider,
tsh_auth_ssl_client_cert_prompt,
NULL,
2,
pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
svn_auth_get_ssl_client_cert_pw_prompt_provider (&provider,
tsh_auth_ssl_client_cert_pw_prompt,
NULL,
2,
pool);
APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
/* open the auth baton */
svn_auth_open(&ab, providers, pool);
ctx->auth_baton = ab;
/* Check config for cache settings */
if ((err = svn_config_get_bool (cfg, &cache,
SVN_CONFIG_SECTION_AUTH,
SVN_CONFIG_OPTION_STORE_PASSWORDS,
TRUE)))
{
if (perr)
*perr = err;
return FALSE;
}
if (!cache)
svn_auth_set_parameter(ab, SVN_AUTH_PARAM_DONT_STORE_PASSWORDS, "");
/* Check config for cache settings */
if ((err = svn_config_get_bool (cfg, &cache,
SVN_CONFIG_SECTION_AUTH,
SVN_CONFIG_OPTION_STORE_AUTH_CREDS,
TRUE)))
{
if (perr)
*perr = err;
return FALSE;
}
if (!cache)
svn_auth_set_parameter(ab, SVN_AUTH_PARAM_NO_AUTH_CACHE, "");
return TRUE;
}
static svn_error_t*
tsh_auth_simple_plaintext_prompt(svn_boolean_t *may_save_plaintext,
const char *realm,
void *baton,
apr_pool_t *pool)
{
GtkWidget *dialog;
gint result;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
G_GNUC_END_IGNORE_DEPRECATIONS
dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, _("Store password a plaintext?"));
result = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
*may_save_plaintext = (result == GTK_RESPONSE_YES);
return SVN_NO_ERROR;
}
static svn_error_t*
tsh_auth_simple_prompt(svn_auth_cred_simple_t **cred,
void *baton,
const char *realm,
const char *username,
svn_boolean_t may_save,
apr_pool_t *pool)
{
GtkWidget *dialog;
svn_auth_cred_simple_t *ret;
TshLoginDialog *login_dialog;
if(!username)
username = "";
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
G_GNUC_END_IGNORE_DEPRECATIONS
dialog = tsh_login_dialog_new(NULL, NULL, 0, username, TRUE, may_save);
if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
{
*cred = NULL;
gtk_widget_destroy(dialog);
tsh_cancel();
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
}
ret = apr_pcalloc(pool, sizeof(svn_auth_cred_simple_t));
login_dialog = TSH_LOGIN_DIALOG(dialog);
ret->username = apr_pstrdup(pool, tsh_login_dialog_get_username(login_dialog));
ret->password = apr_pstrdup(pool, tsh_login_dialog_get_password(login_dialog));
ret->may_save = tsh_login_dialog_get_may_save(login_dialog);
*cred = ret;
gtk_widget_destroy(dialog);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return SVN_NO_ERROR;
}
static svn_error_t*
tsh_auth_username_prompt(svn_auth_cred_username_t **cred,
void *baton,
const char *realm,
svn_boolean_t may_save,
apr_pool_t *pool)
{
GtkWidget *dialog;
svn_auth_cred_username_t *ret;
TshLoginDialog *login_dialog;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
G_GNUC_END_IGNORE_DEPRECATIONS
dialog = tsh_login_dialog_new(NULL, NULL, 0, "", FALSE, may_save);
if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
{
*cred = NULL;
gtk_widget_destroy(dialog);
tsh_cancel();
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
}
ret = apr_pcalloc(pool, sizeof(svn_auth_cred_username_t));
login_dialog = TSH_LOGIN_DIALOG(dialog);
ret->username = apr_pstrdup(pool, tsh_login_dialog_get_username(login_dialog));
ret->may_save = tsh_login_dialog_get_may_save(login_dialog);
*cred = ret;
gtk_widget_destroy(dialog);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return SVN_NO_ERROR;
}
static svn_error_t*
tsh_auth_ssl_server_trust_prompt(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 *cert_info,
svn_boolean_t may_save,
apr_pool_t *pool)
{
GtkWidget *dialog;
svn_auth_cred_ssl_server_trust_t *ret;
TshTrustDialog *trust_dialog;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
G_GNUC_END_IGNORE_DEPRECATIONS
dialog = tsh_trust_dialog_new(NULL, NULL, 0, failures, may_save);
if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
{
*cred = NULL;
gtk_widget_destroy(dialog);
tsh_cancel();
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
}
ret = apr_pcalloc(pool, sizeof(svn_auth_cred_ssl_server_trust_t));
trust_dialog = TSH_TRUST_DIALOG(dialog);
ret->may_save = tsh_trust_dialog_get_may_save(trust_dialog);
ret->accepted_failures = tsh_trust_dialog_get_accepted(trust_dialog);
*cred = ret;
gtk_widget_destroy(dialog);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return SVN_NO_ERROR;
}
static svn_error_t*
tsh_auth_ssl_client_cert_prompt(svn_auth_cred_ssl_client_cert_t **cred,
void *baton,
const char *realm,
svn_boolean_t may_save,
apr_pool_t *pool)
{
GtkWidget *dialog;
svn_auth_cred_ssl_client_cert_t *ret;
TshFileDialog *file_dialog;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
G_GNUC_END_IGNORE_DEPRECATIONS
dialog = tsh_file_dialog_new(NULL, NULL, 0, may_save);
if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
{
*cred = NULL;
gtk_widget_destroy(dialog);
tsh_cancel();
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
}
ret = apr_pcalloc(pool, sizeof(svn_auth_cred_ssl_client_cert_t));
file_dialog = TSH_FILE_DIALOG(dialog);
ret->cert_file = apr_pstrdup(pool, tsh_file_dialog_get_filename(file_dialog));
ret->may_save = tsh_file_dialog_get_may_save(file_dialog);
*cred = ret;
gtk_widget_destroy(dialog);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return SVN_NO_ERROR;
}
static svn_error_t*
tsh_auth_ssl_client_cert_pw_prompt(svn_auth_cred_ssl_client_cert_pw_t **cred,
void *baton,
const char *realm,
svn_boolean_t may_save,
apr_pool_t *pool)
{
GtkWidget *dialog;
svn_auth_cred_ssl_client_cert_pw_t *ret;
TshLoginDialog *login_dialog;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
G_GNUC_END_IGNORE_DEPRECATIONS
dialog = tsh_login_dialog_new(NULL, NULL, 0, NULL, TRUE, may_save);
if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
{
*cred = NULL;
gtk_widget_destroy(dialog);
tsh_cancel();
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
}
ret = apr_pcalloc(pool, sizeof(svn_auth_cred_ssl_client_cert_pw_t));
login_dialog = TSH_LOGIN_DIALOG(dialog);
ret->password = apr_pstrdup(pool, tsh_login_dialog_get_password(login_dialog));
ret->may_save = tsh_login_dialog_get_may_save(login_dialog);
*cred = ret;
gtk_widget_destroy(dialog);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return SVN_NO_ERROR;
}
void
tsh_cancel(void)
{
cancelled = TRUE;
}
static svn_error_t*
tsh_check_cancel(void *baton)
{
if(cancelled)
return svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
return SVN_NO_ERROR;
}
void
tsh_reset_cancel(void)
{
cancelled = FALSE;
}
static const gchar *
tsh_action_to_string(svn_wc_notify_action_t action)
{
static const gchar * const action_table[] = {
N_("Added"),
N_("Copied"),
N_("Deleted"),
N_("Restored"),
N_("Reverted"),
N_("Revert failed"),
N_("Resolved"),
N_("Skipped"),
N_("Deleted"),
N_("Added"),
N_("Updated"),
N_("Completed"),
N_("External"),
N_("Completed"),
N_("External"),
N_("Modified"),
N_("Added"),
N_("Deleted"),
N_("Replaced"),
N_("Transmitting"),
("Revision"),
N_("Locked"),
N_("Unlocked"),
N_("Lock failed"),
N_("Unlock failed"),
N_("Exists"),
N_("Changelist set"),
N_("Changelist cleared"),
N_("Changelist moved"),
N_("Merge begin"),
N_("Foreign merge begin"),
N_("Replace"),
#if CHECK_SVN_VERSION_G(1,6)
N_("Property added"),
N_("Property modified"),
N_("Property deleted"),
N_("Property nonexisting"),
N_("Revision property set"),
N_("Revision property deleted"),
N_("Merge completed"),
N_("Tree conflict"),
N_("External failed"),
#endif
#if CHECK_SVN_VERSION_G(1,7)
N_("Started"),
N_("Skipped obstruction"),
N_("Skipped working only"),
N_("Skipped access denied"),
N_("External removed"),
N_("Shadowed add"),
N_("Shadowed update"),
N_("Shadowed delete"),
N_("Merge record info"),
N_("Upgraded path"),
N_("Merge record info begin"),
N_("Merge elide info"),
N_("Patch"),
N_("Applied hunk"),
N_("Rejected hunk"),
N_("Hunk already applied"),
N_("Copied"),
N_("Copied replaced"),
N_("URL redirect"),
N_("Path nonexistent"),
N_("Exclude"),
N_("Conflict"),
N_("Missing"),
N_("Out of date"),
N_("No parent"),
N_("Locked"),
N_("Forbidden by server"),
N_("Skipped conflicted"),
#endif
};
const gchar *action_string = N_("Unknown");
switch(action)
{
case svn_wc_notify_add:
case svn_wc_notify_copy:
case svn_wc_notify_delete:
case svn_wc_notify_restore:
case svn_wc_notify_revert:
case svn_wc_notify_failed_revert:
case svn_wc_notify_resolved:
case svn_wc_notify_skip:
case svn_wc_notify_update_delete:
case svn_wc_notify_update_add:
case svn_wc_notify_update_update:
case svn_wc_notify_update_completed:
case svn_wc_notify_update_external:
case svn_wc_notify_status_completed:
case svn_wc_notify_status_external:
case svn_wc_notify_commit_modified:
case svn_wc_notify_commit_added:
case svn_wc_notify_commit_deleted:
case svn_wc_notify_commit_replaced:
case svn_wc_notify_commit_postfix_txdelta:
case svn_wc_notify_blame_revision:
case svn_wc_notify_locked:
case svn_wc_notify_unlocked:
case svn_wc_notify_failed_lock:
case svn_wc_notify_failed_unlock:
case svn_wc_notify_exists:
case svn_wc_notify_changelist_set:
case svn_wc_notify_changelist_clear:
case svn_wc_notify_changelist_moved:
case svn_wc_notify_merge_begin:
case svn_wc_notify_foreign_merge_begin:
case svn_wc_notify_update_replace:
#if CHECK_SVN_VERSION_G(1,6)
case svn_wc_notify_property_added:
case svn_wc_notify_property_modified:
case svn_wc_notify_property_deleted:
case svn_wc_notify_property_deleted_nonexistent:
case svn_wc_notify_revprop_set:
case svn_wc_notify_revprop_deleted:
case svn_wc_notify_merge_completed:
case svn_wc_notify_tree_conflict:
case svn_wc_notify_failed_external:
#endif
#if CHECK_SVN_VERSION_G(1,7)
case svn_wc_notify_update_started:
case svn_wc_notify_update_skip_obstruction:
case svn_wc_notify_update_skip_working_only:
case svn_wc_notify_update_skip_access_denied:
case svn_wc_notify_update_external_removed:
case svn_wc_notify_update_shadowed_add:
case svn_wc_notify_update_shadowed_update:
case svn_wc_notify_update_shadowed_delete:
case svn_wc_notify_merge_record_info:
case svn_wc_notify_upgraded_path:
case svn_wc_notify_merge_record_info_begin:
case svn_wc_notify_merge_elide_info:
case svn_wc_notify_patch:
case svn_wc_notify_patch_applied_hunk:
case svn_wc_notify_patch_rejected_hunk:
case svn_wc_notify_patch_hunk_already_applied:
case svn_wc_notify_commit_copied:
case svn_wc_notify_commit_copied_replaced:
case svn_wc_notify_url_redirect:
case svn_wc_notify_path_nonexistent:
case svn_wc_notify_exclude:
case svn_wc_notify_failed_conflict:
case svn_wc_notify_failed_missing:
case svn_wc_notify_failed_out_of_date:
case svn_wc_notify_failed_no_parent:
case svn_wc_notify_failed_locked:
case svn_wc_notify_failed_forbidden_by_server:
case svn_wc_notify_skip_conflicted:
#endif
action_string = action_table[action];
break;
}
return _(action_string);
}
static const gchar *
tsh_notify_state_to_string(enum svn_wc_notify_state_t state)
{
static const gchar * const state_table[] = {
N_("Inapplicable"),
N_("Unknown"),
N_("Unchanged"),
N_("Missing"),
N_("Obstructed"),
N_("Changed"),
N_("Merged"),
N_("Conflicted"),
#if CHECK_SVN_VERSION_G(1,7)
N_("Source missing"),
#endif
};
const gchar *state_string = N_("Unknown");
switch(state)
{
case svn_wc_notify_state_inapplicable:
case svn_wc_notify_state_unknown:
case svn_wc_notify_state_unchanged:
case svn_wc_notify_state_missing:
case svn_wc_notify_state_obstructed:
case svn_wc_notify_state_changed:
case svn_wc_notify_state_merged:
case svn_wc_notify_state_conflicted:
#if CHECK_SVN_VERSION_G(1,7)
case svn_wc_notify_state_source_missing:
#endif
state_string = state_table[state];
break;
}
return _(state_string);
}
const gchar *
tsh_status_to_string(enum svn_wc_status_kind status)
{
static const gchar * const status_table[] = {
N_("Unknown"),
(""),//N_("None"),
(""),//N_("Unversioned"),
N_("Normal"),
N_("Added"),
N_("Missing"),
N_("Deleted"),
N_("Replaced"),
N_("Modified"),
N_("Merged"),
N_("Conflicted"),
N_("Ignored"),
N_("Obstructed"),
N_("External"),
N_("Incomplete")
};
const gchar *status_string = N_("Unknown");
switch(status)
{
case svn_wc_status_none:
case svn_wc_status_unversioned:
case svn_wc_status_normal:
case svn_wc_status_added:
case svn_wc_status_missing:
case svn_wc_status_deleted:
case svn_wc_status_replaced:
case svn_wc_status_modified:
case svn_wc_status_merged:
case svn_wc_status_conflicted:
case svn_wc_status_ignored:
case svn_wc_status_obstructed:
case svn_wc_status_external:
case svn_wc_status_incomplete:
status_string = status_table[status];
break;
}
/* Check for None and Unversioned empty strings */
return status_string[0]?_(status_string):"";
}
static const gchar *
tsh_char_to_string(gchar status)
{
const gchar *status_string = _("Unknown");
switch(status)
{
case 'A':
status_string = _("Added");
break;
case 'D':
status_string = _("Deleted");
break;
case 'M':
status_string = _("Modified");
break;
case 'R':
status_string = _("Replaced");
break;
}
return status_string;
}
void
tsh_notify_func2(void *baton, const svn_wc_notify_t *notify, apr_pool_t *pool)
{
TshNotifyDialog *dialog = TSH_NOTIFY_DIALOG (baton);
gchar buffer[256];
const gchar *action;
const gchar *path;
const gchar *mime;
action = tsh_action_to_string(notify->action);
path = notify->path;
mime = notify->mime_type;
switch(notify->content_state)
{
case svn_wc_notify_state_obstructed:
case svn_wc_notify_state_merged:
case svn_wc_notify_state_conflicted:
action = tsh_notify_state_to_string(notify->content_state);
break;
default:
break;
}
switch(notify->action)
{
case svn_wc_notify_update_completed:
g_snprintf(buffer, 256, _("At revision: %ld"), notify->revision);
path = buffer;
break;
default:
break;
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
tsh_notify_dialog_add(dialog, action, path, mime);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
}
void
tsh_status_func2(void *baton, const char *path, svn_wc_status2_t *status)
{
TshStatusDialog *dialog = TSH_STATUS_DIALOG (baton);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
if (tsh_status_dialog_get_show_unversioned (dialog) || status->entry)
tsh_status_dialog_add(dialog, path, tsh_status_to_string(status->text_status), tsh_status_to_string(status->prop_status), tsh_status_to_string(status->repos_text_status), tsh_status_to_string(status->repos_prop_status));
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
}
svn_error_t *
tsh_status_func3(void *baton, const char *path, svn_wc_status2_t *status, apr_pool_t *pool)
{
tsh_status_func2(baton, path, status);
return SVN_NO_ERROR;
}
svn_error_t *
tsh_status_func(void *baton, const char *path, const svn_client_status_t *status, apr_pool_t *pool)
{
TshStatusDialog *dialog = TSH_STATUS_DIALOG (baton);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
if (tsh_status_dialog_get_show_unversioned (dialog) || status->versioned)
tsh_status_dialog_add(dialog, path, tsh_status_to_string(status->text_status), tsh_status_to_string(status->prop_status), tsh_status_to_string(status->repos_text_status), tsh_status_to_string(status->repos_prop_status));
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return SVN_NO_ERROR;
}
svn_error_t*
tsh_log_msg_func2(const char **log_msg, const char **tmp_file, const apr_array_header_t *commit_items, void *baton, apr_pool_t *pool)
{
int i;
GtkWidget *dialog = baton;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
gtk_widget_show (dialog);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
if(commit_items)
{
for(i = 0; i < commit_items->nelts; i++)
{
const gchar *state = _("Unknown");
svn_client_commit_item2_t *item = APR_ARRAY_IDX(commit_items, i, svn_client_commit_item2_t*);
if((item->state_flags & SVN_CLIENT_COMMIT_ITEM_ADD) &&
(item->state_flags & SVN_CLIENT_COMMIT_ITEM_DELETE))
state = _("Replaced");
else if(item->state_flags & SVN_CLIENT_COMMIT_ITEM_ADD)
state = _("Added");
else if(item->state_flags & SVN_CLIENT_COMMIT_ITEM_DELETE)
state = _("Deleted");
else if((item->state_flags & SVN_CLIENT_COMMIT_ITEM_TEXT_MODS) ||
(item->state_flags & SVN_CLIENT_COMMIT_ITEM_PROP_MODS))
state = _("Modified");
//else if(item->state_flags & SVN_CLIENT_COMMIT_ITEM_PROP_MODS)
// state = _("Modified");
else if(item->state_flags & SVN_CLIENT_COMMIT_ITEM_IS_COPY)
state = _("Copied");
else if(item->state_flags & SVN_CLIENT_COMMIT_ITEM_LOCK_TOKEN)
state = _("Unlocked");
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
tsh_log_message_dialog_add(TSH_LOG_MESSAGE_DIALOG(dialog), state, item->path);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
if(gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK)
{
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
tsh_cancel();
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
gtk_widget_hide (dialog);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_leave();
gdk_threads_enter();
*log_msg = tsh_log_message_dialog_get_message(TSH_LOG_MESSAGE_DIALOG(dialog));
*tmp_file = NULL;
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
gtk_widget_hide (dialog);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
return SVN_NO_ERROR;
}
svn_error_t *
tsh_log_func (void *baton, svn_log_entry_t *log_entry, apr_pool_t *pool)
{
apr_hash_t *changed_paths = log_entry->changed_paths;
apr_hash_t *revprops = log_entry->revprops;
apr_time_t date_val;
svn_string_t *value;
gchar *author = NULL;
gchar *date = NULL;
gchar *message = NULL;
GSList *files = NULL;
const gchar *parent = NULL;
gchar *path = NULL;
TshLogDialog *dialog = TSH_LOG_DIALOG (baton);
if (log_entry->revision == SVN_INVALID_REVNUM)
{
tsh_log_dialog_pop (dialog);
return SVN_NO_ERROR;
}
value = apr_hash_get(revprops, SVN_PROP_REVISION_AUTHOR, APR_HASH_KEY_STRING);
if(value)
author = g_strndup (value->data, value->len);
value = apr_hash_get(revprops, SVN_PROP_REVISION_DATE, APR_HASH_KEY_STRING);
if(value)
{
date = g_strndup (value->data, value->len);
svn_time_from_cstring(&date_val, date, pool);
g_free(date);
apr_ctime((date = g_new0(gchar, APR_CTIME_LEN)), date_val);
}
value = apr_hash_get(revprops, SVN_PROP_REVISION_LOG, APR_HASH_KEY_STRING);
if(value)
message = g_strndup (value->data, value->len);
if(changed_paths)
{
apr_hash_index_t *hi;
for (hi = apr_hash_first(pool, changed_paths); hi; hi = apr_hash_next(hi)) {
const svn_log_changed_path_t *changed;
const char *path_;
TshLogFile *file;
apr_hash_this(hi, (const void**)&path_, NULL, (void**)&changed);
file = g_new(TshLogFile, 1);
file->action = tsh_char_to_string (changed->action);
file->file = g_strdup (path_);
files = g_slist_prepend (files, file);
}
}
parent = tsh_log_dialog_top (dialog);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
path = tsh_log_dialog_add(dialog, parent, files, log_entry->revision, author, date, message);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
if (log_entry->has_children)
tsh_log_dialog_push (dialog, path);
else
g_free (path);
g_free(author);
g_free(date);
g_free(message);
return SVN_NO_ERROR;
}
svn_error_t *
tsh_blame_func2 (void *baton, apr_int64_t line_no, svn_revnum_t revision, const char *author, const char *date, svn_revnum_t merged_revision, const char *merged_author, const char *merged_date, const char *merged_path, const char *line, apr_pool_t *pool)
{
apr_time_t date_val;
gchar *date_str = NULL;
TshBlameDialog *dialog = TSH_BLAME_DIALOG (baton);
if(date)
{
svn_time_from_cstring(&date_val, date, pool);
apr_ctime((date_str = g_new0(gchar, APR_CTIME_LEN)), date_val);
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
tsh_blame_dialog_add(dialog, line_no, revision, author, date_str, line);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
g_free(date_str);
return SVN_NO_ERROR;
}
svn_error_t *
tsh_blame_func3 (void *baton, svn_revnum_t start_revision, svn_revnum_t end_revision, apr_int64_t line_no, svn_revnum_t revision, apr_hash_t *revprops, svn_revnum_t merged_revision, apr_hash_t *merged_rev_props, const char *merged_path, const char *line, svn_boolean_t local_change, apr_pool_t *pool)
{
apr_time_t date_val;
svn_string_t *value;
gchar *author = NULL;
gchar *date = NULL;
TshBlameDialog *dialog = TSH_BLAME_DIALOG (baton);
value = apr_hash_get(revprops, SVN_PROP_REVISION_AUTHOR, APR_HASH_KEY_STRING);
if(value)
author = g_strndup (value->data, value->len);
value = apr_hash_get(revprops, SVN_PROP_REVISION_DATE, APR_HASH_KEY_STRING);
if(value)
{
date = g_strndup (value->data, value->len);
svn_time_from_cstring(&date_val, date, pool);
g_free(date);
apr_ctime((date = g_new0(gchar, APR_CTIME_LEN)), date_val);
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
tsh_blame_dialog_add(dialog, line_no, revision, author, date, line);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
g_free(author);
g_free(date);
return SVN_NO_ERROR;
}
svn_error_t *
tsh_proplist_func (void *baton, const char *path, apr_hash_t *prop_hash, apr_pool_t *pool)
{
TshPropertiesDialog *dialog = TSH_PROPERTIES_DIALOG (baton);
apr_hash_index_t *hi;
for (hi = apr_hash_first(pool, prop_hash); hi; hi = apr_hash_next(hi)) {
const char *name;
svn_string_t *value;
gchar *str_value;
apr_hash_this(hi, (const void**)&name, NULL, (void**)&value);
str_value = g_strndup (value->data, value->len);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
tsh_properties_dialog_add (dialog, name, str_value);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
g_free (str_value);
}
return SVN_NO_ERROR;
}
svn_error_t *
tsh_commit_func2 (const svn_commit_info_t *commit_info, void *baton, apr_pool_t *pool)
{
TshNotifyDialog *dialog = TSH_NOTIFY_DIALOG (baton);
gchar buffer[256];
gchar *message;
if(commit_info->post_commit_err)
{
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
tsh_notify_dialog_add(dialog, _("Error"), commit_info->post_commit_err, NULL);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
}
else
{
if(SVN_IS_VALID_REVNUM(commit_info->revision))
{
g_snprintf(buffer, 256, _("At revision: %ld"), commit_info->revision);
message = buffer;
}
else
{
message = _("Local action");
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gdk_threads_enter();
tsh_notify_dialog_add(dialog, _("Completed"), message, NULL);
gdk_threads_leave();
G_GNUC_END_IGNORE_DEPRECATIONS
}
return SVN_NO_ERROR;
}
gchar *
tsh_strerror(svn_error_t *err)
{
GSList *iter, *done = NULL;
gboolean skip;
gchar *error = NULL;
gchar *freeme;
char message[256];
while(err)
{
if(err->message)
{
if(error)
{
freeme = error;
error = g_strconcat(error, "\r\n", err->message, NULL);
g_free(freeme);
}
else
error = g_strdup(err->message);
}
else
{
skip = FALSE;
for(iter = done; iter; iter = g_slist_next(iter))
{
if(GPOINTER_TO_INT(iter->data) == err->apr_err)
{
skip = TRUE;
break;
}
}
if(!skip)
{
done = g_slist_prepend(done, GINT_TO_POINTER(err->apr_err));
svn_strerror(err->apr_err, message, sizeof(message));
if(error)
{
freeme = error;
error = g_strconcat(error, "\r\n", message, NULL);
g_free(freeme);
}
else
error = g_strdup(message);
}
}
err = err->child;
}
g_slist_free(done);
return error;
}
gchar *
tsh_is_working_copy (const gchar *uri, apr_pool_t *pool)
{
gchar *path;
svn_error_t *err;
int wc_format;
#if CHECK_SVN_VERSION_G(1,7)
svn_wc_context_t *wc_ctx;
#endif
/* strip the "file://" part of the uri */
if (strncmp (uri, "file://", 7) == 0)
{
uri += 7;
}
path = g_strdup (uri);
/* remove trailing '/' cause svn_wc_check_wc can't handle that */
if (strlen (path) > 1 && path[strlen (path) - 1] == '/')
{
path[strlen (path) - 1] = '\0';
}
#if CHECK_SVN_VERSION_S(1,6)
/* check for the path is a working copy */
err = svn_wc_check_wc (path, &wc_format, pool);
#else /* CHECK_SVN_VERSION(1,7) */
err = svn_wc_context_create (&wc_ctx, NULL, pool, pool);
if (!err)
{
err = svn_wc_check_wc2 (&wc_format, wc_ctx, path, pool);
}
#endif
/* if an error occured or wc_format in not set it is no working copy */
if(err || !wc_format)
{
g_free (path);
svn_error_clear (err);
return NULL;
}
return path;
}
|