-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP2Pmsg_Ext.cpp
More file actions
753 lines (709 loc) · 24.8 KB
/
Copy pathP2Pmsg_Ext.cpp
File metadata and controls
753 lines (709 loc) · 24.8 KB
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
// Copyright © 2013, 2026 Ivyware Pty Ltd, Khrustal & Mann
// MELBOURNE, VICTORIA, AUSTRALIA, 3000
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
// P2Pmsg extension definitions and prototypes
//
#include "stdafx.h"
#include "P2Pmsg.h"
#include "MsgAttr.h"
#include "MsgList.h"
#include "MsgVect.h"
#include "MsgCurs.h"
#include "P2PmsgMgr.h"
#include "P2Pmsg_Ext.h"
#include "P2PmsgBSTR.h"
#include "Msgexception.h"
///////////////////////////////////////////////////////////////////////
// Recursive P2Pmsg[Field,Node,Attr]_Merge Utilities and helpers
// NOTES: For clarity and simplicity operations isolated in series
// of self contained static functions
P3PmsgField&
P2PmsgField_Merge ( P3PmsgField& oField, const P3PmsgField& rhs )
{
// Field assignment
(P3PmsgData&)oField = rhs;
// Attribute assignment
if ( !((P3PmsgField&)rhs).r_Attr().IsEmpty() )
P2PmsgAttr_Merge ( oField.r_Attr(P3PmsgField::AttrCMD_Create)
, ((P3PmsgField&)rhs).r_Attr() );
// Tidy up, and
return oField;
}
/*P3PmsgNode&
P2PmsgNode_Merge ( P3PmsgNode& oItem, const P3PmsgNode& rhs )
{
// Recursive copy
P3PmsgCurs& oCurs = ((P3PmsgNode&)rhs).r_Curs();
for ( int i = 0; oCurs.Goto(i); i++ )
{
//oCurs.AssertValid();
ASSERT(oCurs.Item()==i);
if ( oCurs.IsNode() )
{
LPCWSTR lpszNodename = oCurs.r_node().c_name();
if ( oItem.Exists(lpszNodename) )
P2PmsgNode_Merge ( oItem.SelectNode(lpszNodename), oCurs.r_node() );
else
oItem += oCurs.r_node();
}
else if ( oCurs.IsList() )
{
ASSERT(0);
oItem += oCurs.r_list();
}
else if ( oCurs.IsVect() )
{
ASSERT(0);
oItem += oCurs.r_vect();
}
else if ( oCurs.IsItem() )
{
LPCWSTR lpszFieldname = oCurs.r_item().c_name();
if ( oItem.Exists(lpszFieldname) )
P2PmsgField_Merge ( oItem.SelectItem(lpszFieldname), oCurs.r_item() );
else
oItem += oCurs.r_item();
}
else
ASSERT(0);
//oItem.assertValid();//TODO:LJM delete, testing
}
// Tidy up, and
return oItem;
}*/
/*P3PmsgAttr&
P2PmsgAttr_Merge ( P3PmsgAttr& oAttrLHS, const P3PmsgNode& rhs )
{
// Recursive copy
P3PmsgCurs& oCurs = ((P3PmsgNode&)rhs).r_Curs();
for ( int i = 0; oCurs.Goto(i); i++ )
{
//oCurs.AssertValid();
ASSERT(oCurs.Item()==i);
if ( oCurs.IsNode() )
{
LPCWSTR lpszNodename = oCurs.r_node().c_name();
//oAttrLHS.AssertValid();
if ( oAttrLHS.Exists(lpszNodename) )
P2PmsgNode_Merge ( oAttrLHS.SelectNode(lpszNodename), oCurs.r_node() );
else
oAttrLHS += oCurs.r_node();
}
else if ( oCurs.IsList() )
{
ASSERT(0);
oAttrLHS += oCurs.r_list();
}
else if ( oCurs.IsVect() )
{
ASSERT(0);
oAttrLHS += oCurs.r_vect();
}
else if ( oCurs.IsItem() )
{
LPCWSTR lpszFieldname = oCurs.r_item().c_name();
if ( oAttrLHS.Exists(lpszFieldname) )
P2PmsgField_Merge ( oAttrLHS.SelectItem(lpszFieldname), oCurs.r_item() );
else
oAttrLHS += oCurs.r_item();
}
else
ASSERT(0);
//oAttrLHS.AssertValid();//TODO:LJM delete, testing
}
// Tidy up, and
return oAttrLHS;
}*/
P3PmsgAttr&
P2PmsgAttr_Merge ( P3PmsgAttr& oAttr, const P3PmsgAttr& rhs )
{
// Recursive copy
P3PmsgCurs& oCurs = ((P3PmsgAttr&)rhs).r_Curs();
for ( int i = 0; oCurs.Goto(i); i++ )
{
//oCurs.AssertValid();
ASSERT(oCurs.Item()==i);
/*if ( oCurs.IsNode() )
{
LPCWSTR lpszNodename = oCurs.r_node().c_name();
if ( oAttrLHS.Exists(lpszNodename) )
P2PmsgNode_Merge ( oAttrLHS.SelectNode(lpszNodename), oCurs.r_node() );
else
oAttrLHS += oCurs.r_node();
}
else*/ if ( oCurs.IsList() )
{
ASSERT(0);
oAttr += oCurs.r_list();
}
else if ( oCurs.IsVect() )
{
ASSERT(0);
oAttr += oCurs.r_vect();
}
else if ( oCurs.IsItem() )
{
// COPY, never the bare c_name() pointer. c_name() ends in
// p2p_wstr_from_store(), which off Win32 hands back a slot of a 16-entry
// thread-local widening RING (Platform/p2pstr.h:629-651). Exists() and
// SelectItem() each rescan oAttr BY NAME, and every comparison in that
// scan spends one more slot (P3PmsgCurs::Goto -> c_wcsicmp -> c_name), so
// from about the eighth item on the held pointer is recycled mid-scan -
// and when the recycled slot is the one c_name() has just written, the
// comparison reads equal and the WRONG item is merged. Win32 returns the
// store pointer unchanged, so this is byte-identical there.
CString strFieldname = oCurs.r_item().c_name();
LPCWSTR lpszFieldname = strFieldname;
if ( oAttr.Exists(lpszFieldname) )
P2PmsgField_Merge ( oAttr.SelectItem(lpszFieldname), oCurs.r_item() );
else
oAttr += oCurs.r_item();
}
else
ASSERT(0);
//oAttrLHS.AssertValid();//TODO:LJM delete, testing
}
// Tidy up, and
return oAttr;
}
//
// Absolute merge for P3PmsgAttr objects
// NOTES: Should the same label be encountered in both the oAttrLHS
// and oAttrRHS instances, the oAttrLHS instance will totally
// over-written by the contents of the oAttrRHS label.
//
// Parameters: P3PmsgAttr& oAttrLHS
// Destination or left hand side of the assignment
//
// P3PmsgAttr& oAttrRHS
// Source or right hand side of the assignment (pre-dominates)
//
// Returns: P3PmsgAttr&
// Effectively oAttrLHS
P3PmsgAttr&
P2PmsgAttr_AbsoluteMerge ( P3PmsgAttr& oAttrLHS, const P3PmsgAttr& oRHS )
{
// Recursive copy
P3PmsgCurs& oCurs = ((P3PmsgAttr&)oRHS).r_Curs();
for ( int i = 0; oCurs.Goto(i); i++ )
{
// COPY - see the P3PmsgCurs widening-ring note in P2PmsgAttr_Merge above.
// Delete() is the call that needs it most: it rescans oAttrLHS BY NAME,
// spending one ring slot per comparison, so a bare c_name() argument dies
// inside the very scan that is reading it.
CString strFieldname = oCurs.r_item().c_name();
LPCWSTR lpszFieldname = strFieldname;
if ( oAttrLHS.Exists(lpszFieldname) )
{
CString strDelname = oCurs.r_name().c_name();
oAttrLHS.Delete ( strDelname );
}
oAttrLHS += oCurs.r_item();
}
// Tidy up, and
return oAttrLHS;
}
///////////////////////////////////////////////////////////////////////
// P2Pmsg serialisation helpers
// NOTES: Perform standard activities
P3PmsgItem&
P3PmsgField_SERIALISE ( P3PmsgItem& oItem
, LPCWSTR lpszFieldname, const P3PmsgData& oData
, BOOL bDscAttr, LPCWSTR lpszDescription )
{
P3PmsgField oField ( lpszFieldname, oData );
if ( bDscAttr )
oField.r_Attr(P3PmsgField::AttrCMD_Create)
+= P3PmsgField ( L"Dsc", lpszDescription );
oItem += oField;
return oItem;
}
P3PmsgAttr&
P2PmsgAttr_SERIALISE ( P3PmsgAttr& oAttr, BOOL bOverwrite
, LPCWSTR lpszFieldname, const P3PmsgData& oData
, BOOL bDscAttr, LPCWSTR lpszDescription )
{
P3PmsgField oField ( lpszFieldname, oData );
if ( bDscAttr )
oField.r_Attr(P3PmsgField::AttrCMD_Create)
+= P3PmsgField ( L"Dsc", lpszDescription );
if ( !oAttr.Exists(lpszFieldname) )
oAttr += oField;
else if ( bOverwrite )
oAttr.SelectItem(lpszFieldname) = oField;
else
EVERR->MODULE
->AFP(lpszFieldname)
->Message(L"Field already exists, no overwrite permission" )
->Throw();
return oAttr;
}
///////////////////////////////////////////////////////////////////////
// P3PmsgObject extractions
//
// Recursively searches backwards for parent with specified attribute
//
// Parameters: const P3PmsgObject& oObject
// Search base point
//
// LPCWSTR lpszAttributeName
// Name of attribute to be searched for
//
// Returns: P3PmsgObject
// Located object, null object flags failed search
//
P3PmsgObject
P3Pmsg_FindParentWithAttr ( const P3PmsgObject& oObject, LPCWSTR lpszAttributeName )
{
if ( !oObject.HasParent() )
return P3PmsgObject(); // Has no parent
P3PmsgObject oParentObject = oObject.GetParent();
if ( oParentObject.IsAttr() )
oParentObject = oParentObject.GetParent( );
if ( oParentObject.IsDesc() )
oParentObject = oParentObject.GetParent( );
if ( !oParentObject )
return oParentObject;
//if ( oParentObject.IsNode() )
//{
// P3PmsgNode oNodeParent = oParentObject;
// if ( oNodeParent.r_Attr().Exists(lpszAttributeName) )
// return oParentObject;
//}
if ( oParentObject.IsField() )
{
P3PmsgField oFieldParent = oParentObject;
if ( oFieldParent.r_Attr().Exists(lpszAttributeName) )
return oParentObject;
}
else if ( oParentObject.IsList() )
{
ASSERT(0);
//P3PmsgList oListParent = oParentObject;
//if ( oListParent.r_Attr().Exists(lpszAttributeName) )
// return oParentObject;
}
else if ( oParentObject.IsVect() )
{
ASSERT(0);
//P3PmsgVect oVectParent = oParentObject;
//if ( oVectParent.r_Attr().Exists(lpszAttributeName) )
// return oParentObject;
}
return P3Pmsg_FindParentWithAttr ( oParentObject, lpszAttributeName );
}
//
// Recursively searches backwards for specified attribute
//
// Parameters: const P3PmsgObject& oObject
// Search base point
//
// LPCWSTR lpszAttributeName
// Name of attribute to be searched for
//
// Returns: P3PmsgObject
// Located attribute, null object flags failed search
//
P3PmsgObject
P3Pmsg_FindParentAttr ( const P3PmsgObject& oObject, LPCWSTR lpszAttributeName )
{
// Delegate
P3PmsgItem oParent = P3Pmsg_FindParentWithAttr ( oObject, lpszAttributeName );
if ( !oParent.IsVoid() )
return oParent.ATTR.SelectObject(lpszAttributeName);
return oParent.r_Object();
}
//
// Recursively searches forwards for specified attribute
//
// Parameters: const P3PmsgItem& oItem
// Search base point
//
// LPCWSTR lpszAttributeName
// Name of attribute to be searched for
//
// LPCWSTR lpszChildname
// Matching name wildcard
// Returns: P3PmsgObject
// Located attribute, null object flags failed search
//
P3PmsgObject
P3Pmsg_FindChildWithAttr ( const P3PmsgItem& oItem
, LPCWSTR lpszAttributeName, LPCWSTR lpszChildname )
{
if ( lpszChildname == 0 || wcslen(lpszChildname) <= 0 )
lpszChildname = nullptr;
// Both names are held across scans that spend a ring slot per sibling --
// c_wcsicmpWC() widens each sibling's stored name through
// p2p_wstr_from_store (Platform/p2pstr.h), and Exists() rescans the whole
// attribute set by name on every iteration. A caller passing some other
// item's c_name() would have its key recycled part-way through, and the
// recycled slot compares EQUAL to whatever overwrote it. Snapshotting here
// covers the recursion too: the grandchild pass below hands these on, so
// one copy at the top protects the whole subtree walk.
// : A P3PmsgName COPY IS NOT A SNAPSHOT. It copies the name out of the
// caller's storage, but c_name() returns a RING SLOT (P2Pmsg.cpp:1131),
// so the key goes straight back into the ring the copy exists to escape
// -- and the first loop below spends a slot per sibling. p2p_wkey copies
// into its own inline buffer instead, which is the whole point of it.
// NULL-NESS IS LOAD-BEARING: the normalisation above collapses an empty name to
// nullptr, and both name tests below read that nullptr as "no name supplied,
// match every sibling". P3PmsgName does not preserve it -- c_name() hands back
// L"" for a null-constructed name, so taking it unconditionally turned every
// no-name search into a wildcard match against the EMPTY STRING, which matches
// nothing: P3Pmsg_FindChildWithAttr(oItem,attr) then returned void for a tree
// that does carry the attribute. p2p_wkey passes a null key through untouched
// (Platform/p2pstr.h), so the snapshot and the null-ness cost one line each.
const p2p_wkey oAttrKey ( lpszAttributeName );
const p2p_wkey oChildKey ( lpszChildname );
LPCWSTR lpszAttr = oAttrKey;
LPCWSTR lpszChild = oChildKey;
// NAME TEST SENSE. c_wcsicmpWC() is a PREDICATE, not a comparison:
// it returns MsgcoreWildcard(pattern,name) (P2Pmsg.cpp:2099-2103), so
// NON-ZERO means the name MATCHES. The `cmp` in the spelling reads like
// wcsicmp, where zero means equal, and both tests here were written that
// way round -- so the base item was accepted only when its name did NOT
// match, and the child loop `continue`d past exactly the children that DID.
// With a name supplied this function could not find a child by name at all:
// it skipped every match, fell through to the grandchild pass, and
// descended into leaf children. Measured, not read: a 4-child tree with the
// attribute on `Item03` and lpszChildname="Item03" reported cmp=1 for that
// child and 0 for the other three.
// : Callers that pass NO name (the default, and every caller in this
// tree) are unaffected either way -- the name test is skipped
// entirely for them. Only a caller supplying lpszChildname sees a
// behaviour change, and for those the old answer was indefensible.
// Check passed P3PmsgItem
if ( ( lpszChild == nullptr ||
oItem.r_name().c_wcsicmpWC(lpszChild) ) &&
oItem.r_Attr().Exists(lpszAttr) )
return oItem.r_Object();
// Search all immediate children
P3PmsgCurs oCurs((P3PmsgItem&)oItem);
for ( int i = 0; oCurs.Goto(i); i++ )
{
if ( lpszChild &&
!oCurs.r_name().c_wcsicmpWC(lpszChild) )
continue;
if ( oCurs.r_attr().Exists(lpszAttr) )
return oCurs.r_Object();
}
// Search all immediate grandchildren
//
// IsDescendant() as well as IsItem(). Recursing needs a cursor over the
// child, and P3PmsgCurs(P3PmsgItem&) takes r_Desc() of it (MsgCurs.cpp:71-77)
// - which a LEAF child does not have. Every leaf therefore asserted at
// P2Pmsg.cpp:1814 (VBLock_IsAlloc) and fell through VBLock_pName
// (P2PmsgVBLock.cpp:601); in a Release build that fall-through now throws
// (session 27), so a search that simply did not match at the first level
// raised rather than returning void. Reached on EVERY failed search, since
// that is exactly when this loop runs.
P3PmsgObject oObject;
for ( int i = 0; oCurs.Goto(i) && oObject.IsVoid(); i++ )
{
if ( oCurs.IsItem() && oCurs.r_item().IsDescendant() )
oObject = P3Pmsg_FindChildWithAttr ( oCurs.r_item(), lpszAttr, lpszChild );
}
//oObject.AssertValid();
return oObject;
}
///////////////////////////////////////////////////////////////////////
// Boolean operations
/*P3PmsgNode&
P2PmsgNode_AND ( P3PmsgNode& oItem, const P3PmsgNode& rhs )
{
// Immediate P3PmsgData AND operation
if ( oItem.r_data().DataType() == rhs.r_data().DataType() )
oItem.r_data() = rhs.r_data();
// Immediate P3PmsgAttr AND operation
if ( !oItem.IsAttributed() || !rhs.IsAttributed() )
P2PmsgAttr_AND ( oItem.r_Attr(), rhs.r_Attr() );
// Recursive AND operation
P3PmsgCurs& oCurs = ((P3PmsgNode&)rhs).r_Curs();
for ( int i = 0; oCurs.Goto(i); i++ )
{
//oCurs.AssertValid();
ASSERT(oCurs.Item()==i);
if ( oCurs.IsNode() )
{
P3PmsgNode& oNodeRValue = oCurs.r_node();
LPCWSTR lpszNodename = oNodeRValue.c_name();
if ( !oItem.Exists(lpszNodename) )
continue;
P3PmsgObject oObjectLValue = oItem.SelectObject(lpszNodename);
if ( !oObjectLValue.IsNode() )
continue;
P3PmsgNode oNodeLValue ( oObjectLValue );
P2PmsgNode_AND ( oNodeLValue, oNodeRValue );
}
else if ( oCurs.IsList() )
{
ASSERT(0);
}
else if ( oCurs.IsVect() )
{
ASSERT(0);
}
else if ( oCurs.IsItem() )
{
LPCWSTR lpszFieldname = oCurs.r_item().c_name();
if ( !oItem.Exists(lpszFieldname) )
continue;
P2PmsgField_AND ( oItem.SelectItem(lpszFieldname), oCurs.r_item() );
}
else
ASSERT(0);
//oItem.AssertValid();//TODO:LJM delete, testing
}
// Tidy up, and
return oItem;
}*/
P3PmsgField&
P2PmsgField_AND ( P3PmsgField& oField, const P3PmsgField& rhs )
{
// Immediate P3PmsgData AND operation
if ( oField.r_data().DataType() == rhs.r_data().DataType() )
oField.r_data() = rhs.r_data();
// Immediate P3PmsgAttr AND operation
if ( oField.IsAttributed() && rhs.IsAttributed() )
P2PmsgAttr_AND ( oField.r_Attr(), rhs.r_Attr() );
// Immediate P3PmsgDesc AND operation
if ( oField.IsDescendant() && rhs.IsDescendant() )
P2PmsgDesc_AND ( oField.r_Desc(), rhs.r_Desc() );
// Tidy up, and
return oField;
}
P3PmsgAttr&
P2PmsgAttr_AND ( P3PmsgAttr& oAttr, const P3PmsgAttr& rhs )
{
// Recursive copy
P3PmsgCurs& oCurs = ((P3PmsgAttr&)rhs).r_Curs();
for ( int i = 0; oCurs.Goto(i); i++ )
{
//oCurs.AssertValid();
ASSERT(oCurs.Item()==i);
//if ( oCurs.IsNode() )
//{
// P3PmsgNode& oNodeRValue = oCurs.r_node();
// LPCWSTR lpszNodename = oNodeRValue.c_name();
// if ( !oAttrLHS.Exists(lpszNodename) )
// continue;
// P3PmsgObject oObjectLValue = oAttrLHS.SelectObject(lpszNodename);
// if ( !oObjectLValue.IsNode() )
// continue;
// P3PmsgNode oNodeLValue ( oObjectLValue );
// P2PmsgNode_AND ( oNodeLValue, oNodeRValue );
//}
if ( oCurs.IsList() )
{
ASSERT(0);
oAttr += oCurs.r_list();
}
else if ( oCurs.IsVect() )
{
ASSERT(0);
oAttr += oCurs.r_vect();
}
else if ( oCurs.IsItem() )
{
// COPY - see the P3PmsgCurs widening-ring note in P2PmsgAttr_Merge above.
CString strFieldname = oCurs.r_item().c_name();
LPCWSTR lpszFieldname = strFieldname;
if ( !oAttr.Exists(lpszFieldname) )
continue;
P2PmsgField_AND ( oAttr.SelectItem(lpszFieldname), oCurs.r_item() );
}
else
ASSERT(0);
//oAttrLHS.AssertValid();//TODO:LJM delete, testing
}
// Tidy up, and
return oAttr;
}
P3PmsgDesc&
P2PmsgDesc_AND ( P3PmsgDesc& oDesc, const P3PmsgDesc& rhs )
{
// Recursive copy
P3PmsgCurs& oCurs = ((P3PmsgDesc&)rhs).r_Curs();
for ( int i = 0; oCurs.Goto(i); i++ )
{
//oCurs.AssertValid();
ASSERT(oCurs.Item()==i);
//if ( oCurs.IsNode() )
//{
// P3PmsgNode& oNodeRValue = oCurs.r_node();
// LPCWSTR lpszNodename = oNodeRValue.c_name();
// if ( !oDesc.Exists(lpszNodename) )
// continue;
// P3PmsgObject oObjectLValue = oDesc.SelectObject(lpszNodename);
// if ( !oObjectLValue.IsNode() )
// continue;
// P3PmsgNode oNodeLValue ( oObjectLValue );
// P2PmsgNode_AND ( oNodeLValue, oNodeRValue );
//}
if ( oCurs.IsList() )
{
ASSERT(0);
oDesc += oCurs.r_list();
}
else if ( oCurs.IsVect() )
{
ASSERT(0);
oDesc += oCurs.r_vect();
}
else if ( oCurs.IsItem() )
{
// COPY - see the P3PmsgCurs widening-ring note in P2PmsgAttr_Merge above.
CString strFieldname = oCurs.r_item().c_name();
LPCWSTR lpszFieldname = strFieldname;
if ( !oDesc.Exists(lpszFieldname) )
continue;
P2PmsgField_AND ( oDesc.SelectItem(lpszFieldname), oCurs.r_item() );
}
else
ASSERT(0);
//oAttrLHS.AssertValid();//TODO:LJM delete, testing
}
// Tidy up, and
return oDesc;
}
//
// P3PmsgDesc additions
// NOTES: May result in duplicate enteries
//
// Parameters: P3PmsgDesc& oDesc
// Destination descendant. r_Name(), r_Data() and r_Attr()
// contents not copied.
//
// const P3PmsgDesc& rhs
// Source descendant to be copied in full
P3PmsgDesc&
P2PmsgDesc_ADD ( P3PmsgDesc& oDesc, const P3PmsgDesc& rhs )
{
// Recursive addition
P3PmsgCurs& oCurs = ((P3PmsgDesc&)rhs).r_Curs();
for ( int i = 0; oCurs.Goto(i); i++ )
{
//oCurs.AssertValid();
ASSERT(oCurs.Item()==i);
//if ( oCurs.IsNode() )
//{
// P3PmsgNode& oNodeRValue = oCurs.r_node();
// LPCWSTR lpszNodename = oNodeRValue.c_name();
// if ( !oDesc.Exists(lpszNodename) )
// continue;
// P3PmsgObject oObjectLValue = oDesc.SelectObject(lpszNodename);
// if ( !oObjectLValue.IsNode() )
// continue;
// P3PmsgNode oNodeLValue ( oObjectLValue );
// P2PmsgNode_AND ( oNodeLValue, oNodeRValue );
//}
if ( oCurs.IsList() )
{
ASSERT(0);
oDesc += oCurs.r_list();
}
else if ( oCurs.IsVect() )
{
ASSERT(0);
oDesc += oCurs.r_vect();
}
else if ( oCurs.IsItem() )
{
oDesc += oCurs.r_item();
}
else
ASSERT(0);
//oAttrLHS.AssertValid();//TODO:LJM delete, testing
}
// Tidy up, and
return oDesc;
}
CString bytetohex(byte item)
{
CString result;
result.Format(L"%02.2x",item);
return result.Right(2);
}
void
GuidToString ( GUID& oGUID, LPWSTR lpszGUID )
{
byte *pbyGUID = (byte *)&oGUID;
lpszGUID [0] = L'0' + pbyGUID [3] / 16;
lpszGUID [1] = L'0' + pbyGUID [3] % 16;
lpszGUID [2] = L'0' + pbyGUID [2] / 16;
lpszGUID [3] = L'0' + pbyGUID [2] % 16;
lpszGUID [4] = L'0' + pbyGUID [1] / 16;
lpszGUID [5] = L'0' + pbyGUID [1] % 16;
lpszGUID [6] = L'0' + pbyGUID [0] / 16;
lpszGUID [7] = L'0' + pbyGUID [0] % 16;
lpszGUID [8] = L'-';
lpszGUID [9] = L'0' + pbyGUID [5] / 16;
lpszGUID[10] = L'0' + pbyGUID [5] % 16;
lpszGUID[11] = L'0' + pbyGUID [4] / 16;
lpszGUID[12] = L'0' + pbyGUID [4] % 16;
lpszGUID[13] = L'-';
lpszGUID[14] = L'0' + pbyGUID [7] / 16;
lpszGUID[15] = L'0' + pbyGUID [7] % 16;
lpszGUID[16] = L'0' + pbyGUID [6] / 16;
lpszGUID[17] = L'0' + pbyGUID [6] % 16;
lpszGUID[18] = L'-';
lpszGUID[19] = L'0' + pbyGUID [8] / 16;
lpszGUID[20] = L'0' + pbyGUID [8] % 16;
lpszGUID[21] = L'0' + pbyGUID [9] / 16;
lpszGUID[22] = L'0' + pbyGUID [9] % 16;
lpszGUID[23] = L'-';
lpszGUID[24] = L'0' + pbyGUID[10] / 16;
lpszGUID[25] = L'0' + pbyGUID[10] % 16;
lpszGUID[26] = L'0' + pbyGUID[11] / 16;
lpszGUID[27] = L'0' + pbyGUID[11] % 16;
lpszGUID[28] = L'0' + pbyGUID[12] / 16;
lpszGUID[29] = L'0' + pbyGUID[12] % 16;
lpszGUID[30] = L'0' + pbyGUID[13] / 16;
lpszGUID[31] = L'0' + pbyGUID[13] % 16;
lpszGUID[32] = L'0' + pbyGUID[14] / 16;
lpszGUID[33] = L'0' + pbyGUID[14] % 16;
lpszGUID[34] = L'0' + pbyGUID[15] / 16;
lpszGUID[35] = L'0' + pbyGUID[15] % 16;
lpszGUID[36] = 0;
}
///////////////////////////////////////////////////////////////////////
// Movement operations
// NOTES: Move P3PmsgObject from source to destination. Effectively
// cut and paste operations
//
// Performs P3PmsgItem upgrade type move
// NOTES: Move negated if destination item already exists
// : Source item deleted after move sequence
//
// Parameters: LPCWSTR lpszItemname
// Name of item to be moved
//
// P3PmsgItem& oItemSource
// Move source
//
// P3PmsgAttr& oAttrDestin
// Move destination
BOOL
P2Pmsg_UpgradeMove ( LPCWSTR lpszItemname, P3PmsgItem& oItemSource, P3PmsgAttr& oAttrDestin )
{
if ( !oItemSource.Exists(lpszItemname) )
return FALSE;
P3PmsgItem oItemMove = oItemSource.SelectItem(lpszItemname).r_Object();
if ( !oAttrDestin.Exists(lpszItemname) )
oAttrDestin += oItemMove;
oItemSource.r_Desc().Delete ( oItemMove );
return TRUE;
}