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
|
/* MAPIStoreTable.m - this file is part of SOGo
*
* Copyright (C) 2010-2012 Inverse inc
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
*
* This file 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 3, or (at your option)
* any later version.
*
* This file 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; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#import <Foundation/NSException.h>
#import <NGExtensions/NSObject+Logs.h>
#import <EOControl/EOQualifier.h>
#import <SOGo/EOBitmaskQualifier.h>
#import "MAPIStoreActiveTables.h"
#import "MAPIStoreObject.h"
#import "MAPIStoreTypes.h"
#import "NSData+MAPIStore.h"
#import "NSString+MAPIStore.h"
#import "MAPIStoreContext.h"
#import "MAPIStoreObject.h"
#import "MAPIStoreTable.h"
#undef DEBUG
#include <mapistore/mapistore.h>
#include <mapistore/mapistore_errors.h>
#include <libmapiproxy.h>
@interface MAPIStoreTable (Private)
- (MAPIRestrictionState) evaluateRestriction: (const struct mapi_SRestriction *) res
intoQualifier: (EOQualifier **) qualifier;
@end
static Class NSDataK, NSStringK;
// static NSString *
// MAPIStringForRestrictionState (MAPIRestrictionState state)
// {
// NSString *stateStr;
// if (state == MAPIRestrictionStateAlwaysTrue)
// stateStr = @"always true";
// else if (state == MAPIRestrictionStateAlwaysFalse)
// stateStr = @"always false";
// else
// stateStr = @"needs eval";
// return stateStr;
// }
// static NSString *
// MAPIStringForRestriction (const struct mapi_SRestriction *resPtr);
// static NSString *
// _MAPIIndentString(int indent)
// {
// NSString *spaces;
// char *buffer;
// if (indent > 0)
// {
// buffer = malloc (indent + 1);
// memset (buffer, 32, indent);
// *(buffer+indent) = 0;
// spaces = [NSString stringWithFormat: @"%s", buffer];
// free (buffer);
// }
// else
// spaces = @"";
// return spaces;
// }
// static NSString *
// MAPIStringForAndRestriction (const struct mapi_SAndRestriction *resAnd)
// {
// NSMutableArray *restrictions;
// uint16_t count;
// restrictions = [NSMutableArray arrayWithCapacity: 8];
// for (count = 0; count < resAnd->cRes; count++)
// [restrictions addObject: MAPIStringForRestriction ((struct mapi_SRestriction *) resAnd->res + count)];
// return [NSString stringWithFormat: @"(%@)", [restrictions componentsJoinedByString: @" && "]];
// }
// static NSString *
// MAPIStringForOrRestriction (const struct mapi_SOrRestriction *resOr)
// {
// NSMutableArray *restrictions;
// uint16_t count;
// restrictions = [NSMutableArray arrayWithCapacity: 8];
// for (count = 0; count < resOr->cRes; count++)
// [restrictions addObject: MAPIStringForRestriction ((struct mapi_SRestriction *) resOr->res + count)];
// return [NSString stringWithFormat: @"(%@)", [restrictions componentsJoinedByString: @" || "]];
// }
// static NSString *
// MAPIStringForNotRestriction (const struct mapi_SNotRestriction *resNot)
// {
// return [NSString stringWithFormat: @"!(%@)",
// MAPIStringForRestriction ((struct mapi_SRestriction *) &resNot->res)];
// }
// static NSString *
// MAPIStringForContentRestriction (const struct mapi_SContentRestriction *resContent)
// {
// NSString *eqMatch, *caseMatch;
// id value;
// const char *propName;
// switch (resContent->fuzzy & 0xf)
// {
// case 0: eqMatch = @"eq"; break;
// case 1: eqMatch = @"substring"; break;
// case 2: eqMatch = @"prefix"; break;
// default: eqMatch = @"[unknown]";
// }
// switch (((resContent->fuzzy) >> 16) & 0xf)
// {
// case 0: caseMatch = @"fl"; break;
// case 1: caseMatch = @"nc"; break;
// case 2: caseMatch = @"ns"; break;
// case 4: caseMatch = @"lo"; break;
// default: caseMatch = @"[unknown]";
// }
// propName = get_proptag_name (resContent->ulPropTag);
// if (!propName)
// propName = "<unknown>";
// value = NSObjectFromMAPISPropValue (&resContent->lpProp);
// return [NSString stringWithFormat: @"%s(0x%.8x) %@,%@ %@",
// propName, resContent->ulPropTag, eqMatch, caseMatch, value];
// }
// static NSString *
// MAPIStringForExistRestriction (const struct mapi_SExistRestriction *resExist)
// {
// const char *propName;
// propName = get_proptag_name (resExist->ulPropTag);
// if (!propName)
// propName = "<unknown>";
// return [NSString stringWithFormat: @"%s(0x%.8x) IS NOT NULL", propName, resExist->ulPropTag];
// }
// static NSString *
// MAPIStringForPropertyRestriction (const struct mapi_SPropertyRestriction *resProperty)
// {
// static NSString *operators[] = { @"<", @"<=", @">", @">=", @"==", @"!=",
// @"=~" };
// NSString *operator;
// id value;
// const char *propName;
// propName = get_proptag_name (resProperty->ulPropTag);
// if (!propName)
// propName = "<unknown>";
// if (resProperty->relop >= 0 && resProperty->relop < 7)
// operator = operators[resProperty->relop];
// else
// operator = [NSString stringWithFormat: @"<invalid op %d>", resProperty->relop];
// value = NSObjectFromMAPISPropValue (&resProperty->lpProp);
// return [NSString stringWithFormat: @"%s(0x%.8x) %@ %@",
// propName, resProperty->ulPropTag, operator, value];
// }
// static NSString *
// MAPIStringForBitmaskRestriction (const struct mapi_SBitmaskRestriction *resBitmask)
// {
// NSString *format;
// const char *propName;
// propName = get_proptag_name (resBitmask->ulPropTag);
// if (!propName)
// propName = "<unknown>";
// if (resBitmask->relMBR == 0)
// format = @"((%s(0x%.8x) & 0x%.8x) == 0)";
// else
// format = @"((%s(0x%.8x) & 0x%.8x) != 0)";
// return [NSString stringWithFormat: format,
// propName, resBitmask->ulPropTag, resBitmask->ulMask];
// }
// static NSString *
// MAPIStringForRestriction (const struct mapi_SRestriction *resPtr)
// {
// NSString *restrictionStr;
// if (resPtr)
// {
// switch (resPtr->rt)
// {
// // RES_CONTENT=(int)(0x3),
// // RES_BITMASK=(int)(0x6),
// // RES_EXIST=(int)(0x8),
// case 0: restrictionStr = MAPIStringForAndRestriction(&resPtr->res.resAnd); break;
// case 1: restrictionStr = MAPIStringForOrRestriction(&resPtr->res.resOr); break;
// case 2: restrictionStr = MAPIStringForNotRestriction(&resPtr->res.resNot); break;
// case 3: restrictionStr = MAPIStringForContentRestriction(&resPtr->res.resContent); break;
// case 4: restrictionStr = MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
// case 6: restrictionStr = MAPIStringForBitmaskRestriction(&resPtr->res.resBitmask); break;
// case 8: restrictionStr = MAPIStringForExistRestriction(&resPtr->res.resExist); break;
// // case 5: MAPIStringForComparePropsRestriction(&resPtr->res.resCompareProps); break;
// // case 7: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
// // case 9: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
// // case 10: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
// default:
// restrictionStr
// = [NSString stringWithFormat: @"[unhandled restriction type: %d]",
// resPtr->rt];
// }
// }
// else
// restrictionStr = @"[unrestricted]";
// return restrictionStr;
// }
@implementation MAPIStoreTable
+ (void) initialize
{
NSDataK = [NSData class];
NSStringK = [NSString class];
}
+ (id) tableForContainer: (MAPIStoreObject *) newContainer
{
MAPIStoreTable *newTable;
newTable = [[self alloc] initForContainer: newContainer];
[newTable autorelease];
return newTable;
}
+ (Class) childObjectClass
{
[self subclassResponsibility: _cmd];
return Nil;
}
- (id) init
{
if ((self = [super init]))
{
// [self logWithFormat: @"-init"];
tableType = MAPISTORE_MESSAGE_TABLE;
handleId = -1;
container = nil;
childKeys = nil;
restrictedChildKeys = nil;
currentRow = (uint32_t) -1;
currentChild = nil;
restriction = nil;
restrictionState = MAPIRestrictionStateAlwaysTrue;
sortOrderings = nil;
columns = NULL;
columnsCount = 0;
}
return self;
}
- (id) initForContainer: (MAPIStoreObject *) newContainer
{
if ((self = [self init]))
{
container = newContainer;
}
return self;
}
// - (id) retain
// {
// [self logWithFormat: @"-retain"];
// return [super retain];
// }
// - (void) release
// {
// [self logWithFormat: @"-release"];
// [super release];
// }
- (void) dealloc
{
// [self logWithFormat: @"-dealloc"];
if (columns)
NSZoneFree (NULL, columns);
[currentChild release];
[childKeys release];
[restrictedChildKeys release];
[sortOrderings release];
[restriction release];
[super dealloc];
}
- (id) container
{
return container;
}
- (enum mapistore_table_type) tableType
{
return tableType;
}
- (void) setHandleId: (uint32_t) newHandleId
{
handleId = newHandleId;
if (newHandleId)
[[MAPIStoreActiveTables activeTables] registerTable: self];
}
- (void) destroyHandle: (uint32_t) tableHandleId
{
if (tableHandleId && (handleId == tableHandleId))
[[MAPIStoreActiveTables activeTables] unregisterTable: self];
}
- (void) cleanupCaches
{
[restrictedChildKeys release];
restrictedChildKeys = nil;
[childKeys release];
childKeys = nil;
[currentChild release];
currentChild = nil;
currentRow = (uint32_t) -1;
}
- (int) getAvailableProperties: (struct SPropTagArray **) propertiesP
inMemCtx: (TALLOC_CTX *) memCtx
{
return [[isa childObjectClass] getAvailableProperties: propertiesP
inMemCtx: memCtx];
}
- (void) setRestrictions: (const struct mapi_SRestriction *) res
{
//EOQualifier *oldRestriction;
// [self logWithFormat: @"set restriction to (table type: %d): %@",
// type, MAPIStringForRestriction (res)];
//oldRestriction = restriction;
[restriction autorelease];
if (res)
restrictionState = [self evaluateRestriction: res
intoQualifier: &restriction];
else
restrictionState = MAPIRestrictionStateAlwaysTrue;
if (restrictionState == MAPIRestrictionStateNeedsEval)
[restriction retain];
else
restriction = nil;
// FIXME: we should not flush the caches if the restrictions matches
[self cleanupCaches];
//if (restriction)
// [self logWithFormat: @"restriction set to EOQualifier: %@",
// restriction];
// else if (oldRestriction)
// [self logWithFormat: @"restriction unset (was %@)", oldRestriction];
}
- (MAPIRestrictionState) evaluateNotRestriction: (struct mapi_SNotRestriction *) res
intoQualifier: (EOQualifier **) qualifierPtr
{
MAPIRestrictionState state, subState;
EONotQualifier *qualifier;
EOQualifier *subQualifier;
subState = [self evaluateRestriction: (struct mapi_SRestriction *)&res->res
intoQualifier: &subQualifier];
if (subState == MAPIRestrictionStateAlwaysTrue)
state = MAPIRestrictionStateAlwaysFalse;
else if (subState == MAPIRestrictionStateAlwaysFalse)
state = MAPIRestrictionStateAlwaysTrue;
else
{
state = MAPIRestrictionStateNeedsEval;
qualifier = [[EONotQualifier alloc] initWithQualifier: subQualifier];
[qualifier autorelease];
*qualifierPtr = qualifier;
}
return state;
}
- (MAPIRestrictionState) evaluateAndRestriction: (struct mapi_SAndRestriction *) res
intoQualifier: (EOQualifier **) qualifierPtr
{
MAPIRestrictionState state, subState;
EOAndQualifier *qualifier;
EOQualifier *subQualifier;
NSMutableArray *subQualifiers;
uint16_t count;
state = MAPIRestrictionStateNeedsEval;
subQualifiers = [NSMutableArray arrayWithCapacity: 8];
for (count = 0;
state == MAPIRestrictionStateNeedsEval && count < res->cRes;
count++)
{
subState = [self evaluateRestriction: (struct mapi_SRestriction *) res->res + count
intoQualifier: &subQualifier];
if (subState == MAPIRestrictionStateNeedsEval)
[subQualifiers addObject: subQualifier];
else if (subState == MAPIRestrictionStateAlwaysFalse)
state = MAPIRestrictionStateAlwaysFalse;
}
if (state == MAPIRestrictionStateNeedsEval)
{
if ([subQualifiers count] == 0)
state = MAPIRestrictionStateAlwaysTrue;
else
{
qualifier = [[EOAndQualifier alloc]
initWithQualifierArray: subQualifiers];
[qualifier autorelease];
*qualifierPtr = qualifier;
}
}
return state;
}
- (MAPIRestrictionState) evaluateOrRestriction: (struct mapi_SOrRestriction *) res
intoQualifier: (EOQualifier **) qualifierPtr
{
MAPIRestrictionState state, subState;
EOOrQualifier *qualifier;
EOQualifier *subQualifier;
NSMutableArray *subQualifiers;
uint16_t count, falseCount;
state = MAPIRestrictionStateNeedsEval;
falseCount = 0;
subQualifiers = [NSMutableArray arrayWithCapacity: 8];
for (count = 0;
state == MAPIRestrictionStateNeedsEval && count < res->cRes;
count++)
{
subState = [self evaluateRestriction: (struct mapi_SRestriction *) res->res + count
intoQualifier: &subQualifier];
if (subState == MAPIRestrictionStateNeedsEval)
[subQualifiers addObject: subQualifier];
else if (subState == MAPIRestrictionStateAlwaysTrue)
state = MAPIRestrictionStateAlwaysTrue;
else
falseCount++;
}
if (falseCount == res->cRes)
state = MAPIRestrictionStateAlwaysFalse;
else if ([subQualifiers count] == 0)
state = MAPIRestrictionStateAlwaysTrue;
if (state == MAPIRestrictionStateNeedsEval)
{
qualifier = [[EOOrQualifier alloc]
initWithQualifierArray: subQualifiers];
[qualifier autorelease];
*qualifierPtr = qualifier;
}
return state;
}
- (void) warnUnhandledProperty: (enum MAPITAGS) property
inFunction: (const char *) function
{
const char *propName;
propName = get_proptag_name (property);
if (!propName)
propName = "<unknown>";
[self warnWithFormat:
@"property %s (%.8x) has no matching field name (%@) in '%s'",
propName, property, self, function];
}
- (MAPIRestrictionState) evaluateContentRestriction: (struct mapi_SContentRestriction *) res
intoQualifier: (EOQualifier **) qualifier
{
NSString *property;
// SEL operator;
id value;
MAPIRestrictionState rc;
property = [self backendIdentifierForProperty: res->ulPropTag];
if (property)
{
value = NSObjectFromMAPISPropValue (&res->lpProp);
if ([value isKindOfClass: NSDataK])
{
value = [[NSString alloc] initWithData: value
encoding: NSUTF8StringEncoding];
[value autorelease];
}
else if (![value isKindOfClass: NSStringK])
[NSException raise: @"MAPIStoreTypeConversionException"
format: @"unhandled content restriction for class '%@'",
NSStringFromClass ([value class])];
// switch (res->fuzzy & 0xf)
// {
// case 0:
// operator = EOQualifierOperatorEqual;
// break;
// case 1:
// operator = EOQualifierOperatorLike;
// value = [NSString stringWithFormat: @"%%%@%%", value];
// break;
// case 2:
// operator = EOQualifierOperatorEqual;
// value = [NSString stringWithFormat: @"%@%%", value];
// break;
// default: [NSException raise: @"MAPIStoreInvalidOperatorException"
// format: @"fuzzy operator value '%.4x' is invalid",
// res->fuzzy];
// }
*qualifier = [[EOKeyValueQualifier alloc] initWithKey: property
operatorSelector: EOQualifierOperatorCaseInsensitiveLike
value: value];
[*qualifier autorelease];
[self logWithFormat: @"%s: resulting qualifier: %@",
__PRETTY_FUNCTION__, *qualifier];
rc = MAPIRestrictionStateNeedsEval;
}
else
{
[self warnUnhandledProperty: res->ulPropTag
inFunction: __FUNCTION__];
rc = MAPIRestrictionStateAlwaysFalse;
}
return rc;
}
- (SEL) operatorFromRestrictionOperator: (uint32_t) resOp
{
static SEL operators[] = { EOQualifierOperatorLessThan,
EOQualifierOperatorLessThanOrEqualTo,
EOQualifierOperatorGreaterThan,
EOQualifierOperatorGreaterThanOrEqualTo,
EOQualifierOperatorEqual,
EOQualifierOperatorNotEqual,
EOQualifierOperatorContains };
SEL operator;
if (resOp < 7)
operator = operators[resOp];
else
{
operator = NULL;
[NSException raise: @"MAPIStoreRestrictionException"
format: @"unhandled operator type number %d", resOp];
}
return operator;
}
- (MAPIRestrictionState) evaluatePropertyRestriction: (struct mapi_SPropertyRestriction *) res
intoQualifier: (EOQualifier **) qualifier
{
SEL operator;
id value;
NSString *property;
MAPIRestrictionState rc;
property = [self backendIdentifierForProperty: res->ulPropTag];
if (property)
{
operator = [self operatorFromRestrictionOperator: res->relop];
value = NSObjectFromMAPISPropValue (&res->lpProp);
*qualifier = [[EOKeyValueQualifier alloc] initWithKey: property
operatorSelector: operator
value: value];
[*qualifier autorelease];
rc = MAPIRestrictionStateNeedsEval;
}
else
{
[self warnUnhandledProperty: res->ulPropTag
inFunction: __FUNCTION__];
rc = MAPIRestrictionStateAlwaysFalse;
}
return rc;
}
- (MAPIRestrictionState) evaluateBitmaskRestriction: (struct mapi_SBitmaskRestriction *) res
intoQualifier: (EOQualifier **) qualifier
{
NSString *property;
MAPIRestrictionState rc;
property = [self backendIdentifierForProperty: res->ulPropTag];
if (property)
{
*qualifier = [[EOBitmaskQualifier alloc] initWithKey: property
mask: res->ulMask
isZero: (res->relMBR == BMR_EQZ)];
[*qualifier autorelease];
rc = MAPIRestrictionStateNeedsEval;
}
else
{
[self warnUnhandledProperty: res->ulPropTag
inFunction: __FUNCTION__];
rc = MAPIRestrictionStateAlwaysFalse;
}
return rc;
}
- (MAPIRestrictionState) evaluateExistRestriction: (struct mapi_SExistRestriction *) res
intoQualifier: (EOQualifier **) qualifier
{
NSString *property;
MAPIRestrictionState rc;
property = [self backendIdentifierForProperty: res->ulPropTag];
if (property)
{
*qualifier = [[EOKeyValueQualifier alloc] initWithKey: property
operatorSelector: EOQualifierOperatorNotEqual
value: nil];
[*qualifier autorelease];
rc = MAPIRestrictionStateNeedsEval;
}
else
{
[self warnUnhandledProperty: res->ulPropTag
inFunction: __FUNCTION__];
rc = MAPIRestrictionStateAlwaysFalse;
}
return rc;
}
- (MAPIRestrictionState) evaluateRestriction: (struct mapi_SRestriction *) res
intoQualifier: (EOQualifier **) qualifier
{
MAPIRestrictionState state;
switch (res->rt)
{
/* basic operators */
case RES_AND: state = [self evaluateAndRestriction: &res->res.resAnd
intoQualifier: qualifier];
break;
case RES_OR: state = [self evaluateOrRestriction: &res->res.resOr
intoQualifier: qualifier];
break;
case RES_NOT: state = [self evaluateNotRestriction: &res->res.resNot
intoQualifier: qualifier];
break;
/* content restrictions */
case RES_CONTENT: state = [self evaluateContentRestriction: &res->res.resContent
intoQualifier: qualifier];
break;
case RES_PROPERTY: state = [self evaluatePropertyRestriction: &res->res.resProperty
intoQualifier: qualifier];
break;
case RES_BITMASK: state = [self evaluateBitmaskRestriction: &res->res.resBitmask
intoQualifier: qualifier];
break;
case RES_SIZE: state = MAPIRestrictionStateAlwaysTrue; /* let's cheat a little */
break;
case RES_EXIST: state = [self evaluateExistRestriction: &res->res.resExist
intoQualifier: qualifier];
break;
case RES_COMMENT:
if (res->res.resComment.RestrictionPresent)
state = [self evaluateRestriction: (struct mapi_SRestriction *) res->res.resComment.Restriction.res
intoQualifier: qualifier];
else
state = MAPIRestrictionStateAlwaysTrue;
break;
// case 5: MAPIStringForComparePropsRestriction(&resPtr->res.resCompareProps); break;
// case 7: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
// case 9: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
// case 10: MAPIStringForPropertyRestriction(&resPtr->res.resProperty); break;
default:
[NSException raise: @"MAPIStoreRestrictionException"
format: @"unhandled restriction type: %.2x", res->rt];
state = MAPIRestrictionStateAlwaysTrue;
}
// [self logRestriction: res withState: state];
return state;
}
/* proof of concept */
- (int) setColumns: (enum MAPITAGS *) newColumns
withCount: (uint16_t) newColumnsCount
{
NSUInteger count;
if (columns)
NSZoneFree (NULL, columns);
columns = NSZoneMalloc (NULL, newColumnsCount * sizeof (enum MAPITAGS));
for (count = 0; count < newColumnsCount; count++)
columns[count] = newColumns[count];
columnsCount = newColumnsCount;
return MAPISTORE_SUCCESS;
}
- (id) childAtRowID: (uint32_t) rowId
forQueryType: (enum mapistore_query_type) queryType
{
id child;
NSArray *children, *restrictedChildren;
NSString *childKey;
if (rowId == currentRow)
child = currentChild;
else
{
[currentChild release];
child = nil;
if (queryType == MAPISTORE_PREFILTERED_QUERY)
{
children = [self restrictedChildKeys];
restrictedChildren = nil;
}
else
{
children = [self childKeys];
restrictedChildren = [self restrictedChildKeys];
}
if ([children count] > rowId)
{
childKey = [children objectAtIndex: rowId];
if (queryType == MAPISTORE_PREFILTERED_QUERY
|| [restrictedChildren containsObject: childKey])
child = [self lookupChild: childKey];
}
currentChild = child;
[currentChild retain];
if (child)
currentRow = rowId;
else
currentRow = (uint32_t) -1;
}
return child;
}
- (NSArray *) childKeys
{
[self subclassResponsibility: _cmd];
return nil;
}
- (NSArray *) restrictedChildKeys
{
[self subclassResponsibility: _cmd];
return nil;
}
- (id) lookupChild: (NSString *) childKey
{
[self subclassResponsibility: _cmd];
return nil;
}
- (int) getRow: (struct mapistore_property_data **) dataP
withRowID: (uint32_t) rowId
andQueryType: (enum mapistore_query_type) queryType
inMemCtx: (TALLOC_CTX *) memCtx
{
NSUInteger count;
MAPIStoreObject *child;
struct mapistore_property_data *rowData;
int rc;
child = [self childAtRowID: rowId forQueryType: queryType];
if (child)
{
rowData = talloc_array(memCtx, struct mapistore_property_data, columnsCount);
for (count = 0; count < columnsCount; count++)
rowData[count].error = [child getProperty: &rowData[count].data
withTag: columns[count]
inMemCtx: memCtx];
*dataP = rowData;
rc = MAPISTORE_SUCCESS;
}
else
rc = MAPISTORE_ERR_NOT_FOUND;
return rc;
}
- (int) getRowCount: (uint32_t *) countP
withQueryType: (enum mapistore_query_type) queryType
{
NSArray *children;
if (queryType == MAPISTORE_PREFILTERED_QUERY)
children = [self restrictedChildKeys];
else
children = [self childKeys];
*countP = [children count];
return MAPISTORE_SUCCESS;
}
/* subclasses */
- (NSString *) backendIdentifierForProperty: (enum MAPITAGS) property
{
[self subclassResponsibility: _cmd];
return nil;
}
- (void) setSortOrder: (const struct SSortOrderSet *) set
{
[self subclassResponsibility: _cmd];
}
@end
|