### ms-msrp_msgsvc.idl
"""
RPC definitions for the following interfaces:
- msgsvc (v1.0): 17FDD703-1827-4E34-79D4-24A55C53BB37
This file is auto-generated by midl-to-scapy, do not modify.
"""

import uuid

from scapy.fields import StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfPacketListField,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRIntField,
    NDRPacketField,
    NDRUnionField,
    register_dcerpc_interface,
)


class NetrMessageNameAdd_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRConfVarStrNullFieldUtf16("MsgName", ""),
    ]


class NetrMessageNameAdd_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class LPMSG_INFO_0(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("msgi0_name", ""), deferred=True
        )
    ]


class LPMSG_INFO_0_CONTAINER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("EntriesRead", None, size_of="Buffer"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Buffer",
                [LPMSG_INFO_0()],
                LPMSG_INFO_0,
                size_is=lambda pkt: pkt.EntriesRead,
            ),
            deferred=True,
        ),
    ]


class LPMSG_INFO_1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("msgi1_name", ""), deferred=True
        ),
        NDRIntField("msgi1_forward_flag", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("msgi1_forward", ""), deferred=True
        ),
    ]


class LPMSG_INFO_1_CONTAINER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("EntriesRead", None, size_of="Buffer"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Buffer",
                [LPMSG_INFO_1()],
                LPMSG_INFO_1,
                size_is=lambda pkt: pkt.EntriesRead,
            ),
            deferred=True,
        ),
    ]


class LPMSG_ENUM_STRUCT(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Level", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "MsgInfo", LPMSG_INFO_0_CONTAINER(), LPMSG_INFO_0_CONTAINER
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 0),
                        (lambda _, val: val.tag == 0),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "MsgInfo", LPMSG_INFO_1_CONTAINER(), LPMSG_INFO_1_CONTAINER
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
            ],
            StrFixedLenField("MsgInfo", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class NetrMessageNameEnum_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRPacketField("InfoStruct", LPMSG_ENUM_STRUCT(), LPMSG_ENUM_STRUCT),
        NDRIntField("PrefMaxLen", 0),
        NDRFullPointerField(NDRIntField("ResumeHandle", 0)),
    ]


class NetrMessageNameEnum_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("InfoStruct", LPMSG_ENUM_STRUCT(), LPMSG_ENUM_STRUCT),
        NDRIntField("TotalEntries", 0),
        NDRFullPointerField(NDRIntField("ResumeHandle", 0)),
        NDRIntField("status", 0),
    ]


class NetrMessageNameGetInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRConfVarStrNullFieldUtf16("MsgName", ""),
        NDRIntField("Level", 0),
    ]


class NetrMessageNameGetInfo_Response(NDRPacket):
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField("InfoStruct", LPMSG_INFO_0(), LPMSG_INFO_0)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 0),
                        (lambda _, val: val.tag == 0),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("InfoStruct", LPMSG_INFO_1(), LPMSG_INFO_1)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
            ],
            StrFixedLenField("InfoStruct", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class NetrMessageNameDel_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerName", "")),
        NDRConfVarStrNullFieldUtf16("MsgName", ""),
    ]


class NetrMessageNameDel_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


MSGSVC_OPNUMS = {
    0: DceRpcOp(NetrMessageNameAdd_Request, NetrMessageNameAdd_Response),
    1: DceRpcOp(NetrMessageNameEnum_Request, NetrMessageNameEnum_Response),
    2: DceRpcOp(NetrMessageNameGetInfo_Request, NetrMessageNameGetInfo_Response),
    3: DceRpcOp(NetrMessageNameDel_Request, NetrMessageNameDel_Response),
}
register_dcerpc_interface(
    name="msgsvc",
    uuid=uuid.UUID("17FDD703-1827-4E34-79D4-24A55C53BB37"),
    version="1.0",
    opnums=MSGSVC_OPNUMS,
)
