summaryrefslogtreecommitdiffstats
path: root/private/net/svcdlls/nwsap/server/sdmdsupp.c
blob: f68641a7992e415cb39703cfa6236bdd871f4d87 (plain) (blame)
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
/*++

Copyright (c) 1994  Microsoft Corporation
Copyright (c) 1993  Micro Computer Systems, Inc.

Module Name:

    net\svcdlls\nwsap\server\sdmdsupp.c

Abstract:

    This file contains support routines for SDMD.c

    SDMD = Specialized Dynamic Memory Database

Author:

    Brian Walker (MCS) 06-15-1993

Revision History:

--*/

#include "precomp.h"
#pragma hdrstop


/*++
*******************************************************************
        S d m d I n i t i a l i z e L i s t H e a d

Routine Description:

        This routine initializes a list structure that
        is used to keep track of a list with.  It sets the
        fwd and back links to point at nothing.

Arguments:

        ListIndex = Index of the list to initialize

Return Value:

        Nothing
*******************************************************************
--*/
VOID
SdmdInitializeListHead(
    INT ListIndex)
{
    SdmdLists[ListIndex].Flink = SDMD_ENDOFLIST;
    SdmdLists[ListIndex].Blink = SDMD_ENDOFLIST;
    SdmdLists[ListIndex].ListIndex = ListIndex;
    return;
}


/*++
*******************************************************************
        S d m d R e m o v e H e a d L i s t

Routine Description:

        This routine removes a record from the head of a list.

Arguments:

        ListIndex = List number to get entry from

Return Value:

        Ptr to SAP_RECORD structure of entry from head
        (NULL = List is empty)
*******************************************************************
--*/

PSAP_RECORD
SdmdRemoveHeadList(
    INT ListIndex)
{
    PSAP_RECORD Entry;
    PSAP_RECORD NextEntry;

    /** Get ptr to the entry - if none - error **/

    Entry = GETPTRFROMINDEX(SdmdLists[ListIndex].Flink);
    if (Entry == NULL)
        return NULL;

    /** Take this entry out of the list **/

    NextEntry = GETPTRFROMINDEX(Entry->Links[ListIndex].Flink);
    if (NextEntry) {
        NextEntry->Links[ListIndex].Blink = SDMD_ENDOFLIST;
        SdmdLists[ListIndex].Flink = NextEntry->Index;
    }
    else {
        SdmdLists[ListIndex].Flink = SDMD_ENDOFLIST;
        SdmdLists[ListIndex].Blink = SDMD_ENDOFLIST;
    }

    /** Return the pointer **/

    return Entry;
}


/*++
*******************************************************************
        S d m d R e m o v e T a i l L i s t

Routine Description:

        This routine removes a record from the tail of a list.

Arguments:

        ListIndex = List number to get entry from

Return Value:

        Ptr to SAP_RECORD structure of entry from tail
        (NULL = List is empty)
*******************************************************************
--*/

#if 0           /* Current unused so we save the space */

PSAP_RECORD
SdmdRemoveTailList(
    INT ListIndex)
{
    PSAP_RECORD Entry;
    PSAP_RECORD BackEntry;

    /** Get ptr to the entry - if none - error **/

    Entry = GETPTRFROMINDEX(SdmdLists[ListIndex].Blink);
    if (Entry == NULL)
        return NULL;

    /** Take this entry out of the list **/

    BackEntry = GETPTRFROMINDEX(Entry->Links[ListIndex].Blink);
    if (BackEntry) {
        BackEntry->Links[ListIndex].Flink = SDMD_ENDOFLIST;
        SdmdLists[ListIndex].Blink = BackEntry->Index;
    }
    else {
        SdmdLists[ListIndex].Flink = SDMD_ENDOFLIST;
        SdmdLists[ListIndex].Blink = SDMD_ENDOFLIST;
    }

    /** Return the pointer **/

    return Entry;
}

#endif


/*++
*******************************************************************
        S d m d R e m o v e E n t r y L i s t

Routine Description:

        This routine removes a specific entry from the given
        list.

Arguments:

        ListIndex = Index of the list to remove it from
        Entry     = Ptr to the entry to remove from the list.

Return Value:

        Nothing
*******************************************************************
--*/

VOID
SdmdRemoveEntryList(
    INT ListIndex,
    PSAP_RECORD Entry)
{
    PSAP_RECORD BackEntry;
    PSAP_RECORD NextEntry;

    /** Handle the forward link **/

    NextEntry = GETPTRFROMINDEX(Entry->Links[ListIndex].Flink);
    if (NextEntry)
        NextEntry->Links[ListIndex].Blink = Entry->Links[ListIndex].Blink;
    else
        SdmdLists[ListIndex].Blink = Entry->Links[ListIndex].Blink;

    /** Handle the back link **/

    BackEntry = GETPTRFROMINDEX(Entry->Links[ListIndex].Blink);
    if (BackEntry)
        BackEntry->Links[ListIndex].Flink = Entry->Links[ListIndex].Flink;
    else
        SdmdLists[ListIndex].Flink = Entry->Links[ListIndex].Flink;

    /** All Done **/

    return;
}


/*++
*******************************************************************
        S d m d I n s e r t T a i l L i s t

Routine Description:

        Add an entry to the end of a list.

Arguments:

        ListIndex = Index of the list to add this to.
        Entry     = Ptr to the entry to add

Return Value:

        Nothing
*******************************************************************
--*/

VOID
SdmdInsertTailList(
    INT ListIndex,
    PSAP_RECORD Entry)
{
    PSAP_RECORD TailEntry;

    /** Get ptr to last record in list **/

    TailEntry = GETPTRFROMINDEX(SdmdLists[ListIndex].Blink);

    /**
        If there is one - then point its forward link at my
        new entry.  If no entry - then point the list
        head forward entry at my new entry.
    **/

    if (TailEntry)
        TailEntry->Links[ListIndex].Flink = Entry->Index;
    else
        SdmdLists[ListIndex].Flink = Entry->Index;

    /** Point new entries BACK LINK to current list tail **/

    Entry->Links[ListIndex].Blink = SdmdLists[ListIndex].Blink;

    /** Make my entry the new tail **/

    SdmdLists[ListIndex].Blink = Entry->Index;

    /** Make new entry have no forward link **/

    Entry->Links[ListIndex].Flink = SDMD_ENDOFLIST;

    /** All Done **/

    return;
}


/*++
*******************************************************************
        S d m d I n s e r t H e a d L i s t

Routine Description:

        Add an entry to the head of a list.

Arguments:

        ListIndex = Index of the list to add this to.
        Entry     = Ptr to the entry to add

Return Value:

        Nothing
*******************************************************************
--*/

VOID
SdmdInsertHeadList(
    INT ListIndex,
    PSAP_RECORD Entry)
{
    PSAP_RECORD HeadEntry;

    /** Get ptr to first record in list **/

    HeadEntry = GETPTRFROMINDEX(SdmdLists[ListIndex].Flink);

    /**
        If there is one - then point its back link at my
        new entry.  If no entry - then point the list
        head back entry at my new entry.
    **/

    if (HeadEntry)
        HeadEntry->Links[ListIndex].Blink = Entry->Index;
    else
        SdmdLists[ListIndex].Blink = Entry->Index;

    /** Point new entries Front LINK to current list head **/

    Entry->Links[ListIndex].Flink = SdmdLists[ListIndex].Flink;

    /** Make my entry the new head **/

    SdmdLists[ListIndex].Flink = Entry->Index;

    /** Make new entry have no back link **/

    Entry->Links[ListIndex].Blink = SDMD_ENDOFLIST;

    /** All Done **/

    return;
}


/*++
*******************************************************************
        S d m d I n s e r t L i s t

Routine Description:

        This routine inserts an entry into a list at some point
        in the middle of a list.

Arguments:

        ListIndex  = Index of the list to add this to.
        Entry      = Ptr to the entry to add
        AfterIndex = Index to put new entry after.  -1 = At head

Return Value:

        Nothing
*******************************************************************
--*/

VOID
SdmdInsertList(
    INT ListIndex,
    PSAP_RECORD Entry,
    INT AfterIndex)
{
    PSAP_RECORD NextEntry;
    PSAP_RECORD BackEntry;

    /** If head - do it **/

    if (AfterIndex == SDMD_ENDOFLIST) {
        SdmdInsertHeadList(ListIndex, Entry);
    }
    else {

        /** Get ptr to entry that are inserting after **/

        BackEntry = GETPTRFROMINDEX(AfterIndex);

        /** Point new entry back at that entry **/

        Entry->Links[ListIndex].Blink = AfterIndex;

        /** Make new entry fwd ptr be back entry's fwd ptr **/

        Entry->Links[ListIndex].Flink = BackEntry->Links[ListIndex].Flink;

        /** Make back entry point fwd at new entry **/

        BackEntry->Links[ListIndex].Flink = Entry->Index;

        /** If we were at tail - make Entry the new tail **/

        if (Entry->Links[ListIndex].Flink == SDMD_ENDOFLIST)
            SdmdLists[ListIndex].Blink = Entry->Index;
        else {

            /** Make the entry after new one point back at us **/

            NextEntry = GETPTRFROMINDEX(Entry->Links[ListIndex].Flink);
            NextEntry->Links[ListIndex].Blink = Entry->Index;
        }
    }

    /** All Done **/

    return;
}


/*++
*******************************************************************
        S d m d I n s e r t T a i l S u b L i s t

Routine Description:

        Insert an entry at the tail of a sublist.

Arguments:

        HeadEntry = Ptr to the entry that is the head of the sub list
        ListIndex = List index that the list uses
        Entry     = Ptr to entry to insert

Return Value:

        None.
*******************************************************************
--*/

VOID
SdmdInsertTailSubList(
    PSAP_RECORD HeadEntry,
    INT ListIndex,
    PSAP_RECORD Entry)
{
    PSAP_RECORD TailEntry;

    /** Get ptr to last record in list **/

    TailEntry = GETPTRFROMINDEX(HeadEntry->Links[ListIndex].Blink);

    /**
        If there is one - then point its forward link at my
        new entry.  If no entry - then point the list
        head forward entry at my new entry.
    **/

    if (TailEntry)
        TailEntry->Links[ListIndex].Flink = Entry->Index;
    else
        HeadEntry->Links[ListIndex].Flink = Entry->Index;

    /** Point new entries BACK LINK to current list tail **/

    Entry->Links[ListIndex].Blink = HeadEntry->Links[ListIndex].Blink;

    /** Make my entry the new tail **/

    HeadEntry->Links[ListIndex].Blink = Entry->Index;

    /** Make new entry have no forward link **/

    Entry->Links[ListIndex].Flink = SDMD_ENDOFLIST;
    Entry->HeadIndex = HeadEntry->Index;

    /** All Done **/

    return;
}


/*++
*******************************************************************
        S d m d R e m o v e T a i l S u b E n t r y L i s t

Routine Description:

        Remove an entry from the tail of a sublist.

Arguments:

        HeadEntry = Ptr to the head entry that has the list
        ListIndex = The List index to get the entry from

Return Value:

        Ptr to the entry removed.
        (NULL = Empty List).
*******************************************************************
--*/

PSAP_RECORD
SdmdRemoveTailSubEntryList(
    PSAP_RECORD HeadEntry,
    INT ListIndex)
{
    PSAP_RECORD Entry;
    PSAP_RECORD BackEntry;

    /** Get ptr to the entry - if none - error **/

    Entry = GETPTRFROMINDEX(HeadEntry->Links[ListIndex].Blink);
    if (Entry == NULL)
        return NULL;

    /** Take this entry out of the list **/

    BackEntry = GETPTRFROMINDEX(Entry->Links[ListIndex].Blink);
    if (BackEntry) {
        BackEntry->Links[ListIndex].Flink = SDMD_ENDOFLIST;
        HeadEntry->Links[ListIndex].Blink = BackEntry->Index;
    }
    else {
        HeadEntry->Links[ListIndex].Flink = SDMD_ENDOFLIST;
        HeadEntry->Links[ListIndex].Blink = SDMD_ENDOFLIST;
    }

    /** Return the pointer **/

    return Entry;
}


/*++
*******************************************************************
        S d m d R e m o v e S u b E n t r y L i s t

Routine Description:

        This routine removes a specific entry from the given
        list.

Arguments:

        ListIndex = Index of the list to remove it from
        Entry     = Ptr to the entry to remove from the list.

Return Value:

        Nothing
*******************************************************************
--*/

VOID
SdmdRemoveSubEntryList(
    PSAP_RECORD HeadEntry,
    INT ListIndex,
    PSAP_RECORD Entry)
{
    PSAP_RECORD BackEntry;
    PSAP_RECORD NextEntry;

    /** Handle the forward link **/

    NextEntry = GETPTRFROMINDEX(Entry->Links[ListIndex].Flink);
    if (NextEntry)
        NextEntry->Links[ListIndex].Blink = Entry->Links[ListIndex].Blink;
    else
        HeadEntry->Links[ListIndex].Blink = Entry->Links[ListIndex].Blink;

    /** Handle the back link **/

    BackEntry = GETPTRFROMINDEX(Entry->Links[ListIndex].Blink);
    if (BackEntry)
        BackEntry->Links[ListIndex].Flink = Entry->Links[ListIndex].Flink;
    else
        HeadEntry->Links[ListIndex].Flink = Entry->Links[ListIndex].Flink;

    /** All Done **/

    return;
}


/*++
*******************************************************************
        S d m d R e m o v e E n t r y F r o m H a s h

Routine Description:

        This routine removes a specific entry from the given
        hash entry.

Arguments:

        ListHead = Ptr to the list head to remove from
        Entry    = Ptr to the entry to remove from the list.

Return Value:

        Nothing
*******************************************************************
--*/

VOID
SdmdRemoveEntryFromHash(
    PSDMD_LIST_ENTRY ListHead,
    PSAP_RECORD Entry)
{
    PSAP_RECORD BackEntry;
    PSAP_RECORD NextEntry;

    /** Handle the forward link **/

    NextEntry = GETPTRFROMINDEX(Entry->Links[SAP_HASHLIST_INDEX].Flink);
    if (NextEntry)
        NextEntry->Links[SAP_HASHLIST_INDEX].Blink = Entry->Links[SAP_HASHLIST_INDEX].Blink;
    else
        ListHead->Blink = Entry->Links[SAP_HASHLIST_INDEX].Blink;

    /** Handle the back link **/

    BackEntry = GETPTRFROMINDEX(Entry->Links[SAP_HASHLIST_INDEX].Blink);
    if (BackEntry)
        BackEntry->Links[SAP_HASHLIST_INDEX].Flink = Entry->Links[SAP_HASHLIST_INDEX].Flink;
    else
        ListHead->Flink = Entry->Links[SAP_HASHLIST_INDEX].Flink;

    /** All Done **/

    return;
}


/*++
*******************************************************************
        S d m d I n s e r t E n t r y I n H a s h

Routine Description:

        This routine inserts an entry into a hash list.

Arguments:

        ListHead   = Ptr to list head to insert this entry in
        Entry      = Ptr to the entry to add
        AfterIndex = Index to put new entry after.  -1 = At head

Return Value:

        Nothing
*******************************************************************
--*/

VOID
SdmdInsertEntryInHash(
    PSDMD_LIST_ENTRY ListHead,
    PSAP_RECORD Entry,
    INT AfterIndex)
{
    PSAP_RECORD NextEntry;
    PSAP_RECORD BackEntry;

    /** Set the hash index for this entry **/

    Entry->HashIndex = ListHead->ListIndex;

    /** Get ptr to entry that are inserting after **/

    BackEntry = GETPTRFROMINDEX(AfterIndex);

    /** If NULL - We are insertting at the head **/

    if (BackEntry == NULL) {

        /** Give this entry index of the old head **/

        Entry->Links[SAP_HASHLIST_INDEX].Blink = SDMD_ENDOFLIST;
        Entry->Links[SAP_HASHLIST_INDEX].Flink = ListHead->Flink;

        /** Make this entry the head of the list **/

        ListHead->Flink = Entry->Index;
    }
    else {

        /** Point new entry back at that entry **/

        Entry->Links[SAP_HASHLIST_INDEX].Blink = AfterIndex;

        /** Make new entry fwd ptr be back entry's fwd ptr **/

        Entry->Links[SAP_HASHLIST_INDEX].Flink = BackEntry->Links[SAP_HASHLIST_INDEX].Flink;

        /** Make back entry point fwd at new entry **/

        BackEntry->Links[SAP_HASHLIST_INDEX].Flink = Entry->Index;
    }

    /** If we were at tail - make Entry the new tail **/

    NextEntry = GETPTRFROMINDEX(Entry->Links[SAP_HASHLIST_INDEX].Flink);

    if (NextEntry == NULL) {

        /** Make this the new tail **/

        ListHead->Blink = Entry->Index;
    }
    else {

        /** Make the entry after new one point back at us **/

        NextEntry->Links[SAP_HASHLIST_INDEX].Blink = Entry->Index;
    }

    /** All Done **/

    return;
}