summaryrefslogtreecommitdiffstats
path: root/private/net/svcdlls/repl/repltest/dispmail.c
blob: f3888bc0f1722cd040dfd28ab3e5261a111b2d9c (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
/*++

******************************************************************
*                     Microsoft LAN Manager                      *
*               Copyright(c) Microsoft Corp., 1987-1993          *
******************************************************************


Module : DisplMail.c  (extracted from LM 2.x test2.c)

BUGBUG: Assumes little-ending machine!

--*/


// These must be included first:

#include <windows.h>    // DWORD, etc.
#include <lmcons.h>     // NET_API_STATUS.

// These may be included in any order:

#include <netdebug.h>   // NetpKdPrint(), FORMAT_ equates.
#include "repldefs.h"   // DIR_NOT_SUPPORTED, etc.
#include <replpack.h>   // LPPACK_MSG_HEADER, etc.
#include <repltest.h>   // DisplayPackedReplMailslotMsg().
#include <stdio.h>      // printf().


VOID
DisplayMessageType(
    IN DWORD MessageType
    )
{
#define TRY_TYPE( equate ) \
    { \
        if (MessageType == equate) { \
            (VOID) printf( #equate ); \
            goto Cleanup; \
        } \
    }

    // Update messages:
    TRY_TYPE( SYNC_MSG )
    TRY_TYPE( GUARD_MSG )
    TRY_TYPE( PULSE_MSG )

    // Query messages:
    TRY_TYPE( DIR_NOT_SUPPORTED )
    TRY_TYPE( DIR_SUPPORTED )
    TRY_TYPE( NOT_MASTER_DIR )
    TRY_TYPE( MASTER_DIR )
    TRY_TYPE( IS_DIR_SUPPORTED )
    TRY_TYPE( IS_MASTER )
    TRY_TYPE( DIR_COLLIDE )

    // None of the above:
    (VOID) printf( "UNEXPECTED MSG TYPE (" FORMAT_DWORD ")",
            MessageType );

Cleanup:
    return;

}


VOID
DisplayPackedReplMailslotMsg(
    IN LPVOID Message,
    IN DWORD  MessageSize,
    IN BOOL   Verbose
    )
{
    LPPACK_MSG_HEADER      hmsg = (LPVOID) Message;
    DWORD                  i;
    WORD                   MessageType;
    LPBYTE                 MessageByteArray = (LPVOID) Message;
    LPPACK_QUERY_MSG       qmsg;
    LPPACK_SYNCMSG         smsg;
    LPPACK_MSG_STATUS_REC  upd;

    if (Verbose) {
        (VOID) printf(
                "Got message, size is " FORMAT_DWORD ".\n", MessageSize );
    }

    MessageType = hmsg->msg_type;   // BUGBUG: Assumes little-endian!

    (VOID) printf( "MSG type: " );
    DisplayMessageType( MessageType );

    switch (MessageType) {
    case SYNC_MSG:              /*FALLTHROUGH*/
    case GUARD_MSG:             /*FALLTHROUGH*/
    case PULSE_MSG:

        smsg = (LPVOID) Message;

        (VOID) printf(
                ", from: '" FORMAT_LPSTR "' in domain '" FORMAT_LPSTR "'",
                smsg->header.sender, smsg->header.senders_domain );
        if (Verbose) {
            (VOID) printf(
                    ", COUNT: " FORMAT_DWORD ", rand: " FORMAT_DWORD
                    ", sync: " FORMAT_DWORD ", pulse: " FORMAT_DWORD
                    ", guard: " FORMAT_DWORD,
                    smsg->update_count, smsg->info.random,
                    smsg->info.sync_rate, smsg->info.pulse_rate,
                    smsg->info.guard_time);
        }
        (VOID) printf( "\n" );


        upd = (LPVOID) (MessageByteArray + sizeof(*smsg));

        for (i = 0; i < smsg->update_count; i++) {

            LPSTR fnp =
                    (LPVOID) (MessageByteArray + (upd + i)->dir_name_offset);

            (VOID) printf(
                    "DIR: " FORMAT_LPSTR ", code: " FORMAT_DWORD
                    ", cksum: " FORMAT_HEX_DWORD ", count: " FORMAT_DWORD
                    ", integ: " FORMAT_DWORD ", ext: " FORMAT_DWORD "\n",
                    fnp, (upd + i)->opcode,
                        (upd + i)->checksum, (upd + i)->count,
                        (upd + i)->integrity, (upd + i)->extent );
        }

        break;

    case IS_DIR_SUPPORTED:      /*FALLTHROUGH*/
    case IS_MASTER:             /*FALLTHROUGH*/
    case DIR_NOT_SUPPORTED:     /*FALLTHROUGH*/
    case DIR_SUPPORTED:         /*FALLTHROUGH*/
    case NOT_MASTER_DIR:        /*FALLTHROUGH*/
    case MASTER_DIR:            /*FALLTHROUGH*/
    case DIR_COLLIDE:

        qmsg = (LPVOID) Message;

        (VOID) printf(
                ", from: " FORMAT_LPSTR
                ", DIR: " FORMAT_LPSTR "\n",
                qmsg->header.sender,
                qmsg->dir_name);

        break;

    default:

            (VOID) printf( "UNEXPECTED MSG TYPE: " FORMAT_DWORD ".\n",
                    hmsg->msg_type );

        break;

    }   // switch 

}