Changeset 1725
- Timestamp:
- 03/14/07 21:48:44
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/libtinymail/tny-account.c (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r1723 r1725 3 3 * tny_folder_store_remove now specifies and its implementation will 4 4 unsubscribe all the observers of the folder being removed. 5 * Design by contract assertions 5 6 6 7 * This was a major API change trunk/libtinymail/tny-account.c
r1718 r1725 20 20 #include <config.h> 21 21 22 #ifdef DBC 23 #include <string.h> 24 #endif 25 22 26 #include <tny-account.h> 23 24 27 25 28 /** … … 44 47 tny_account_matches_url_string (TnyAccount *self, const gchar *url_string) 45 48 { 46 #ifdef DEBUG 47 if (!TNY_ACCOUNT_GET_IFACE (self)->matches_url_string_func) 48 g_critical ("You must implement tny_account_matches_url_string\n"); 49 #endif 50 51 return TNY_ACCOUNT_GET_IFACE (self)->matches_url_string_func (self, url_string); 49 gboolean retval; 50 51 #ifdef DBC /* require */ 52 g_assert (TNY_IS_ACCOUNT (self)); 53 g_assert (url_string); 54 g_assert (strlen (url_string) > 0); 55 g_assert (TNY_ACCOUNT_GET_IFACE (self)->matches_url_string_func != NULL); 56 #endif 57 58 retval = TNY_ACCOUNT_GET_IFACE (self)->matches_url_string_func (self, url_string); 59 60 #ifdef DBC /* ensure*/ 61 #endif 62 63 return retval; 52 64 } 53 65 … … 62 74 tny_account_cancel (TnyAccount *self) 63 75 { 64 #ifdef D EBUG65 if (!TNY_ACCOUNT_GET_IFACE (self)->cancel_func)66 g_critical ("You must implement tny_account_cancel\n");76 #ifdef DBC /* require */ 77 g_assert (TNY_IS_ACCOUNT (self)); 78 g_assert (TNY_ACCOUNT_GET_IFACE (self)->cancel_func != NULL); 67 79 #endif 68 80 69 81 TNY_ACCOUNT_GET_IFACE (self)->cancel_func (self); 82 83 #ifdef BDC /* ensure */ 84 #endif 85 70 86 return; 71 87 } … … 89 105 tny_account_get_account_type (TnyAccount *self) 90 106 { 91 #ifdef DEBUG 92 if (!TNY_ACCOUNT_GET_IFACE (self)->get_account_type_func) 93 g_critical ("You must implement tny_account_get_account_type\n"); 94 #endif 95 96 return TNY_ACCOUNT_GET_IFACE (self)->get_account_type_func (self); 107 TnyAccountType retval; 108 109 #ifdef DBC /* require */ 110 g_assert (TNY_IS_ACCOUNT (self)); 111 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_account_type_func != NULL); 112 #endif 113 114 retval = TNY_ACCOUNT_GET_IFACE (self)->get_account_type_func (self); 115 116 #ifdef DBC /* ensure */ 117 #endif 118 119 return retval; 97 120 } 98 121 … … 109 132 tny_account_is_connected (TnyAccount *self) 110 133 { 111 #ifdef DEBUG 112 if (!TNY_ACCOUNT_GET_IFACE (self)->is_connected_func) 113 g_critical ("You must implement tny_account_is_connected\n"); 114 #endif 115 116 return TNY_ACCOUNT_GET_IFACE (self)->is_connected_func (self); 134 gboolean retval; 135 136 #ifdef DBC /* require */ 137 g_assert (TNY_IS_ACCOUNT (self)); 138 g_assert (TNY_ACCOUNT_GET_IFACE (self)->is_connected_func != NULL); 139 #endif 140 141 retval = TNY_ACCOUNT_GET_IFACE (self)->is_connected_func (self); 142 143 #ifdef DBC /* ensure */ 144 #endif 145 146 return retval; 117 147 } 118 148 … … 133 163 tny_account_get_id (TnyAccount *self) 134 164 { 135 #ifdef DEBUG 136 if (!TNY_ACCOUNT_GET_IFACE (self)->get_id_func) 137 g_critical ("You must implement tny_account_get_id\n"); 138 #endif 139 140 return TNY_ACCOUNT_GET_IFACE (self)->get_id_func (self); 165 const gchar *retval; 166 167 #ifdef DBC /* require */ 168 g_assert (TNY_IS_ACCOUNT (self)); 169 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_id_func != NULL); 170 #endif 171 172 retval = TNY_ACCOUNT_GET_IFACE (self)->get_id_func (self); 173 174 #ifdef DBC /* ensure */ 175 g_assert (retval); 176 g_assert (strlen (retval) > 0); 177 #endif 178 179 return retval; 141 180 } 142 181 … … 152 191 tny_account_set_name (TnyAccount *self, const gchar *name) 153 192 { 154 #ifdef DEBUG 155 if (!TNY_ACCOUNT_GET_IFACE (self)->set_name_func) 156 g_critical ("You must implement tny_account_set_name\n"); 193 #ifdef DBC /* require */ 194 g_assert (TNY_IS_ACCOUNT (self)); 195 g_assert (name); 196 g_assert (strlen (name) > 0); 197 g_assert (TNY_ACCOUNT_GET_IFACE (self)->set_name_func != NULL); 157 198 #endif 158 199 159 200 TNY_ACCOUNT_GET_IFACE (self)->set_name_func (self, name); 201 202 #ifdef DBC /* require */ 203 g_assert (!strcmp (tny_account_get_name (self), name)); 204 #endif 205 160 206 return; 161 207 } … … 175 221 tny_account_set_mech (TnyAccount *self, const gchar *mech) 176 222 { 177 #ifdef DEBUG 178 if (!TNY_ACCOUNT_GET_IFACE (self)->set_mech_func) 179 g_critical ("You must implement tny_account_set_mech\n"); 223 #ifdef DBC /* require */ 224 g_assert (TNY_IS_ACCOUNT (self)); 225 g_assert (mech); 226 g_assert (strlen (mech) > 0); 227 g_assert (TNY_ACCOUNT_GET_IFACE (self)->set_mech_func != NULL); 180 228 #endif 181 229 182 230 TNY_ACCOUNT_GET_IFACE (self)->set_mech_func (self, mech); 231 232 #ifdef DBC /* require */ 233 g_assert (!strcmp (tny_account_get_mech (self), mech)); 234 #endif 235 183 236 return; 184 237 } … … 197 250 tny_account_set_id (TnyAccount *self, const gchar *id) 198 251 { 199 #ifdef DEBUG 200 if (!TNY_ACCOUNT_GET_IFACE (self)->set_id_func) 201 g_critical ("You must implement tny_account_set_id\n"); 252 #ifdef DBC /* require */ 253 g_assert (TNY_IS_ACCOUNT (self)); 254 g_assert (id); 255 g_assert (strlen (id) > 0); 256 g_assert (TNY_ACCOUNT_GET_IFACE (self)->set_id_func != NULL); 202 257 #endif 203 258 204 259 TNY_ACCOUNT_GET_IFACE (self)->set_id_func (self, id); 260 261 262 #ifdef DBC /* require */ 263 g_assert (!strcmp (tny_account_get_id (self), id)); 264 #endif 265 205 266 return; 206 267 } … … 253 314 tny_account_set_forget_pass_func (TnyAccount *self, TnyForgetPassFunc forget_pass_func) 254 315 { 255 #ifdef D EBUG256 if (!TNY_ACCOUNT_GET_IFACE (self)->set_forget_pass_func_func)257 g_critical ("You must implement tny_account_set_forget_pass_func\n");316 #ifdef DBC /* require */ 317 g_assert (TNY_IS_ACCOUNT (self)); 318 g_assert (TNY_ACCOUNT_GET_IFACE (self)->set_forget_pass_func_func != NULL); 258 319 #endif 259 320 260 321 TNY_ACCOUNT_GET_IFACE (self)->set_forget_pass_func_func (self, forget_pass_func); 322 323 #ifdef DBC /* ensure */ 324 g_assert (tny_account_get_forget_pass_func (self) == forget_pass_func); 325 #endif 326 261 327 return; 262 328 } … … 272 338 tny_account_get_forget_pass_func (TnyAccount *self) 273 339 { 274 #ifdef DEBUG 275 if (!TNY_ACCOUNT_GET_IFACE (self)->get_forget_pass_func_func) 276 g_critical ("You must implement tny_account_get_forget_pass_func\n"); 277 #endif 278 279 return TNY_ACCOUNT_GET_IFACE (self)->get_forget_pass_func_func (self); 340 TnyForgetPassFunc retval; 341 342 #ifdef DBC /* require */ 343 g_assert (TNY_IS_ACCOUNT (self)); 344 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_forget_pass_func_func != NULL); 345 #endif 346 347 retval = TNY_ACCOUNT_GET_IFACE (self)->get_forget_pass_func_func (self); 348 349 #ifdef DBC /* ensure */ 350 #endif 351 352 return retval; 280 353 } 281 354 … … 297 370 tny_account_set_url_string (TnyAccount *self, const gchar *url_string) 298 371 { 299 #ifdef DEBUG 300 if (!TNY_ACCOUNT_GET_IFACE (self)->set_url_string_func) 301 g_critical ("You must implement tny_account_set_url_string\n"); 372 #ifdef DBC /* require */ 373 g_assert (TNY_IS_ACCOUNT (self)); 374 g_assert (url_string); 375 g_assert (strlen (url_string) > 0); 376 g_assert (strstr (url_string, "://") != NULL); 377 g_assert (TNY_ACCOUNT_GET_IFACE (self)->set_url_string_func != NULL); 302 378 #endif 303 379 304 380 TNY_ACCOUNT_GET_IFACE (self)->set_url_string_func (self, url_string); 381 382 #ifdef DBC /* ensure */ 383 /* TNY TODO: It's possible that tny_account_get_url_string strips the 384 * password. It would be interesting to have a contract check that 385 * deals with this. */ 386 #endif 387 305 388 return; 306 389 } … … 319 402 tny_account_set_proto (TnyAccount *self, const gchar *proto) 320 403 { 321 #ifdef DEBUG 322 if (!TNY_ACCOUNT_GET_IFACE (self)->set_proto_func) 323 g_critical ("You must implement tny_account_set_proto\n"); 404 #ifdef DBC /* require */ 405 g_assert (TNY_IS_ACCOUNT (self)); 406 g_assert (proto); 407 g_assert (strlen (proto) > 0); 408 g_assert (TNY_ACCOUNT_GET_IFACE (self)->set_proto_func != NULL); 324 409 #endif 325 410 326 411 TNY_ACCOUNT_GET_IFACE (self)->set_proto_func (self, proto); 412 413 #ifdef DBC /* ensure */ 414 g_assert (!strcmp (tny_account_get_proto (self), proto)); 415 #endif 416 327 417 return; 328 418 } … … 341 431 tny_account_set_user (TnyAccount *self, const gchar *user) 342 432 { 343 #ifdef DEBUG 344 if (!TNY_ACCOUNT_GET_IFACE (self)->set_user_func) 345 g_critical ("You must implement tny_account_set_user\n"); 433 #ifdef DBC /* require */ 434 g_assert (TNY_IS_ACCOUNT (self)); 435 g_assert (user); 436 g_assert (strlen (user) > 0); 437 g_assert (TNY_ACCOUNT_GET_IFACE (self)->set_user_func != NULL); 346 438 #endif 347 439 348 440 TNY_ACCOUNT_GET_IFACE (self)->set_user_func (self, user); 441 442 #ifdef DBC /* ensure */ 443 g_assert (!strcmp (tny_account_get_user (self), user)); 444 #endif 445 349 446 return; 350 447 } … … 363 460 tny_account_set_hostname (TnyAccount *self, const gchar *host) 364 461 { 365 #ifdef DEBUG 366 if (!TNY_ACCOUNT_GET_IFACE (self)->set_hostname_func) 367 g_critical ("You must implement tny_account_set_hostname\n"); 462 #ifdef DBC /* require */ 463 g_assert (TNY_IS_ACCOUNT (self)); 464 g_assert (host); 465 g_assert (strlen (host) > 0); 466 g_assert (TNY_ACCOUNT_GET_IFACE (self)->set_hostname_func != NULL); 368 467 #endif 369 468 370 469 TNY_ACCOUNT_GET_IFACE (self)->set_hostname_func (self, host); 470 471 #ifdef DBC /* ensure */ 472 g_assert (!strcmp (tny_account_get_hostname (self), host)); 473 #endif 474 371 475 return; 372 476 } … … 386 490 tny_account_set_port (TnyAccount *self, guint port) 387 491 { 388 #ifdef DEBUG 389 if (!TNY_ACCOUNT_GET_IFACE (self)->set_port_func) 390 g_critical ("You must implement tny_account_set_port\n"); 492 #ifdef DBC /* require */ 493 g_assert (TNY_IS_ACCOUNT (self)); 494 g_assert (port <= 65536); 495 g_assert (TNY_ACCOUNT_GET_IFACE (self)->set_port_func != NULL); 391 496 #endif 392 497 393 498 TNY_ACCOUNT_GET_IFACE (self)->set_port_func (self, port); 499 500 #ifdef DBC /* ensure */ 501 g_assert (tny_account_get_port (self) == port); 502 #endif 503 394 504 return; 395 505 } … … 457 567 tny_account_set_pass_func (TnyAccount *self, TnyGetPassFunc get_pass_func) 458 568 { 459 #ifdef D EBUG460 if (!TNY_ACCOUNT_GET_IFACE (self)->set_pass_func_func)461 g_critical ("You must implement tny_account_set_pass_func\n");569 #ifdef DBC /* require */ 570 g_assert (TNY_IS_ACCOUNT (self)); 571 g_assert (TNY_ACCOUNT_GET_IFACE (self)->set_pass_func_func != NULL); 462 572 #endif 463 573 464 574 TNY_ACCOUNT_GET_IFACE (self)->set_pass_func_func (self, get_pass_func); 575 576 #ifdef DBC /* ensure */ 577 g_assert (tny_account_get_pass_func (self) == get_pass_func); 578 #endif 579 465 580 return; 466 581 } … … 478 593 tny_account_get_proto (TnyAccount *self) 479 594 { 480 #ifdef DEBUG 481 if (!TNY_ACCOUNT_GET_IFACE (self)->get_proto_func) 482 g_critical ("You must implement tny_account_get_proto\n"); 483 #endif 484 485 return TNY_ACCOUNT_GET_IFACE (self)->get_proto_func (self); 595 const gchar *retval; 596 597 #ifdef DBC /* require */ 598 g_assert (TNY_IS_ACCOUNT (self)); 599 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_proto_func != NULL); 600 #endif 601 602 retval = TNY_ACCOUNT_GET_IFACE (self)->get_proto_func (self); 603 604 #ifdef DBC /* ensure */ 605 #endif 606 607 return retval; 486 608 } 487 609 … … 504 626 tny_account_get_url_string (TnyAccount *self) 505 627 { 506 #ifdef DEBUG 507 if (!TNY_ACCOUNT_GET_IFACE (self)->get_url_string_func) 508 g_critical ("You must implement tny_account_get_url_string\n"); 509 #endif 510 511 return TNY_ACCOUNT_GET_IFACE (self)->get_url_string_func (self); 628 gchar *retval; 629 630 #ifdef DBC /* require */ 631 g_assert (TNY_IS_ACCOUNT (self)); 632 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_url_string_func != NULL); 633 #endif 634 635 retval = TNY_ACCOUNT_GET_IFACE (self)->get_url_string_func (self); 636 637 #ifdef DBC /* ensure */ 638 if (retval) 639 g_assert (strstr (retval, "://") != NULL); 640 #endif 641 642 return retval; 643 512 644 } 513 645 … … 516 648 * @self: a #TnyAccount object 517 649 * 518 * Get the user or login of @self. The returned value should not be freed. 650 * Get the user or login of @self. The returned value should not be freed. The 651 * returned value van be NULL in case of no user. 519 652 * 520 653 * Return value: the user as a read-only string … … 524 657 tny_account_get_user (TnyAccount *self) 525 658 { 526 #ifdef DEBUG 527 if (!TNY_ACCOUNT_GET_IFACE (self)->get_user_func) 528 g_critical ("You must implement tny_account_get_user\n"); 529 #endif 530 531 return TNY_ACCOUNT_GET_IFACE (self)->get_user_func (self); 659 const gchar *retval; 660 661 #ifdef DBC /* require */ 662 g_assert (TNY_IS_ACCOUNT (self)); 663 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_user_func != NULL); 664 #endif 665 666 retval = TNY_ACCOUNT_GET_IFACE (self)->get_user_func (self); 667 668 #ifdef DBC /* ensure */ 669 #endif 670 671 return retval; 532 672 } 533 673 … … 537 677 * 538 678 * Get the human readable name of @self. The returned value should not 539 * be freed. 679 * be freed. The returned value van be NULL in case of no human reabable name. 540 680 * 541 681 * Return value: the human readable name as a read-only string … … 545 685 tny_account_get_name (TnyAccount *self) 546 686 { 547 #ifdef DEBUG 548 if (!TNY_ACCOUNT_GET_IFACE (self)->get_name_func) 549 g_critical ("You must implement tny_account_get_name\n"); 550 #endif 551 552 return TNY_ACCOUNT_GET_IFACE (self)->get_name_func (self); 687 const gchar *retval; 688 689 #ifdef DBC /* require */ 690 g_assert (TNY_IS_ACCOUNT (self)); 691 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_name_func != NULL); 692 #endif 693 694 retval = TNY_ACCOUNT_GET_IFACE (self)->get_name_func (self); 695 696 #ifdef DBC /* ensure */ 697 #endif 698 699 return retval; 553 700 } 554 701 … … 558 705 * @self: a #TnyAccount object 559 706 * 560 * Get the authentication mechanism for this account. Default is "PLAIN". 707 * Get the authentication mechanism for this account. Default is "PLAIN". The 708 * returned value can be NULL, in which case a undefined default is used. 561 709 * 562 710 * Return value: the authentication mechanism as a read-only string … … 566 714 tny_account_get_mech (TnyAccount *self) 567 715 { 568 #ifdef DEBUG 569 if (!TNY_ACCOUNT_GET_IFACE (self)->get_mech_func) 570 g_critical ("You must implement tny_account_get_mech\n"); 571 #endif 572 573 return TNY_ACCOUNT_GET_IFACE (self)->get_mech_func (self); 716 const gchar *retval; 717 718 #ifdef DBC /* require */ 719 g_assert (TNY_IS_ACCOUNT (self)); 720 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_mech_func != NULL); 721 #endif 722 723 retval = TNY_ACCOUNT_GET_IFACE (self)->get_mech_func (self); 724 725 #ifdef DBC /* ensure */ 726 #endif 727 728 return retval; 574 729 } 575 730 … … 579 734 * @self: a #TnyAccount object 580 735 * 581 * Get the hostname of @self. The returned value should not be freed. 736 * Get the hostname of @self. The returned value should not be freed. The 737 * returned value can be NULL, in which case no hostname is set (for example 738 * for a local account). 582 739 * 583 740 * Return value: the hostname as a read-only string … … 587 744 tny_account_get_hostname (TnyAccount *self) 588 745 { 589 #ifdef DEBUG 590 if (!TNY_ACCOUNT_GET_IFACE (self)->get_hostname_func) 591 g_critical ("You must implement tny_account_get_hostname\n"); 592 #endif 593 594 return TNY_ACCOUNT_GET_IFACE (self)->get_hostname_func (self); 746 const gchar *retval; 747 748 #ifdef DBC /* require */ 749 g_assert (TNY_IS_ACCOUNT (self)); 750 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_hostname_func != NULL); 751 #endif 752 753 retval = TNY_ACCOUNT_GET_IFACE (self)->get_hostname_func (self); 754 755 #ifdef DBC /* ensure */ 756 #endif 757 758 return retval; 595 759 } 596 760 … … 607 771 tny_account_get_port (TnyAccount *self) 608 772 { 609 #ifdef DEBUG 610 if (!TNY_ACCOUNT_GET_IFACE (self)->get_port_func) 611 g_critical ("You must implement tny_account_get_port\n"); 612 #endif 613 614 return TNY_ACCOUNT_GET_IFACE (self)->get_port_func (self); 773 guint retval; 774 775 #ifdef DBC /* require */ 776 g_assert (TNY_IS_ACCOUNT (self)); 777 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_port_func != NULL); 778 #endif 779 780 retval = TNY_ACCOUNT_GET_IFACE (self)->get_port_func (self); 781 782 #ifdef DBC /* ensure */ 783 g_assert (retval <= 65536); 784 #endif 785 786 return retval; 615 787 } 616 788 /** … … 624 796 tny_account_get_pass_func (TnyAccount *self) 625 797 { 626 #ifdef DEBUG 627 if (!TNY_ACCOUNT_GET_IFACE (self)->get_pass_func_func) 628 g_critical ("You must implement tny_account_get_pass_func\n"); 629 #endif 630 631 return TNY_ACCOUNT_GET_IFACE (self)->get_pass_func_func (self); 798 TnyGetPassFunc retval; 799 800 #ifdef DBC /* require */ 801 g_assert (TNY_IS_ACCOUNT (self)); 802 g_assert (TNY_ACCOUNT_GET_IFACE (self)->get_port_func != NULL); 803 #endif 804 805 retval = TNY_ACCOUNT_GET_IFACE (self)->get_pass_func_func (self); 806 807 #ifdef DBC /* ensure */ 808 #endif 809 810 return retval; 632 811 } 633 812
