### ms-mqmr.idl
"""
RPC definitions for the following interfaces:
- qmmgmt (v1.0): 41208ee0-e970-11d1-9b9e-00e02c064c39
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRByteField,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRInt3264EnumField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRRecursiveField,
    NDRShortField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRUnionField,
    register_dcerpc_interface,
)


class MgmtObjectType(IntEnum):
    MGMT_MACHINE = 1
    MGMT_QUEUE = 2
    MGMT_SESSION = 3


class QUEUE_FORMAT_TYPE(IntEnum):
    QUEUE_FORMAT_TYPE_UNKNOWN = 0
    QUEUE_FORMAT_TYPE_PUBLIC = 1
    QUEUE_FORMAT_TYPE_PRIVATE = 2
    QUEUE_FORMAT_TYPE_DIRECT = 3
    QUEUE_FORMAT_TYPE_MACHINE = 4
    QUEUE_FORMAT_TYPE_CONNECTOR = 5
    QUEUE_FORMAT_TYPE_DL = 6
    QUEUE_FORMAT_TYPE_MULTICAST = 7
    QUEUE_FORMAT_TYPE_SUBQUEUE = 8


class GUID(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Data1", 0),
        NDRShortField("Data2", 0),
        NDRShortField("Data3", 0),
        StrFixedLenField("Data4", "", length=8),
    ]


class OBJECTID(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("Lineage", GUID(), GUID),
        NDRIntField("Uniquifier", 0),
    ]


class DL_ID(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("m_DlGuid", GUID(), GUID),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("m_pwzDomain", ""), deferred=True
        ),
    ]


class MULTICAST_ID(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("m_address", 0), NDRIntField("m_port", 0)]


class QUEUE_FORMAT(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRByteField("m_qft", 0),
        NDRByteField("m_SuffixAndFlags", 0),
        NDRShortField("m_reserved", 0),
        NDRUnionField(
            [
                (
                    StrFixedLenField("value", "", length=0),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_UNKNOWN
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_UNKNOWN
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", GUID(), GUID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_PUBLIC
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_PUBLIC
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", OBJECTID(), OBJECTID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_PRIVATE
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_PRIVATE
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRConfVarStrNullFieldUtf16("value", ""), deferred=True
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_DIRECT
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_DIRECT
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", GUID(), GUID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_MACHINE
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_MACHINE
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", GUID(), GUID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_CONNECTOR
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_CONNECTOR
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", DL_ID(), DL_ID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_DL
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_DL
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", MULTICAST_ID(), MULTICAST_ID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_MULTICAST
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_MULTICAST
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRConfVarStrNullFieldUtf16("value", ""), deferred=True
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_SUBQUEUE
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_SUBQUEUE
                        ),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(1, 8),
            switch_fmt=("B", "B"),
        ),
    ]


class MGMT_OBJECT(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRInt3264EnumField("type", 0, MgmtObjectType),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField("value", QUEUE_FORMAT(), QUEUE_FORMAT),
                        deferred=True,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "type", None)
                            == MgmtObjectType.MGMT_QUEUE
                        ),
                        (lambda _, val: val.tag == MgmtObjectType.MGMT_QUEUE),
                    ),
                ),
                (
                    NDRIntField("value", 0),
                    (
                        (
                            lambda pkt: getattr(pkt, "type", None)
                            == MgmtObjectType.MGMT_MACHINE
                        ),
                        (lambda _, val: val.tag == MgmtObjectType.MGMT_MACHINE),
                    ),
                ),
                (
                    NDRIntField("value", 0),
                    (
                        (
                            lambda pkt: getattr(pkt, "type", None)
                            == MgmtObjectType.MGMT_SESSION
                        ),
                        (lambda _, val: val.tag == MgmtObjectType.MGMT_SESSION),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "I"),
        ),
    ]


class VARENUM(IntEnum):
    VT_EMPTY = 0
    VT_NULL = 1
    VT_I2 = 2
    VT_I4 = 3
    VT_BOOL = 11
    VT_VARIANT = 12
    VT_I1 = 16
    VT_UI1 = 17
    VT_UI2 = 18
    VT_UI4 = 19
    VT_I8 = 20
    VT_UI8 = 21
    VT_LPWSTR = 31
    VT_BLOB = 65
    VT_CLSID = 72
    VT_VECTOR = 4096


class LARGE_INTEGER(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRSignedLongField("QuadPart", 0)]


class ULARGE_INTEGER(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRLongField("QuadPart", 0)]


class BLOB(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cbSize", None, size_of="pBlobData"),
        NDRFullPointerField(
            NDRConfStrLenField("pBlobData", "", size_is=lambda pkt: pkt.cbSize),
            deferred=True,
        ),
    ]


class CAUB(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfStrLenField("pElems", "", size_is=lambda pkt: pkt.cElems),
            deferred=True,
        ),
    ]


class CAUI(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16("pElems", "", size_is=lambda pkt: pkt.cElems),
            deferred=True,
        ),
    ]


class CAL(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "pElems",
                [],
                NDRSignedIntField("pElems", 0),
                size_is=lambda pkt: pkt.cElems,
            ),
            deferred=True,
        ),
    ]


class CAUL(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "pElems", [], NDRIntField("pElems", 0), size_is=lambda pkt: pkt.cElems
            ),
            deferred=True,
        ),
    ]


class CAUH(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pElems", [], ULARGE_INTEGER, size_is=lambda pkt: pkt.cElems
            ),
            deferred=True,
        ),
    ]


class CACLSID(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfPacketListField("pElems", [], GUID, size_is=lambda pkt: pkt.cElems),
            deferred=True,
        ),
    ]


class CALPWSTR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "pElems",
                [],
                NDRFullPointerField(
                    NDRConfVarStrNullFieldUtf16("pElems", ""), deferred=True
                ),
                size_is=lambda pkt: pkt.cElems,
            ),
            deferred=True,
        ),
    ]


class tag_inner_PROPVARIANT(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRShortField("vt", 0),
        NDRByteField("wReserved1", 0),
        NDRByteField("wReserved2", 0),
        NDRIntField("wReserved3", 0),
        NDRRecursiveField("_varUnion"),
    ]


class R_QMMgmtGetInfo_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pObjectFormat", MGMT_OBJECT(), MGMT_OBJECT),
        NDRIntField("cp", None, size_of="apVar"),
        NDRConfFieldListField(
            "aProp", [], NDRIntField("", 0), size_is=lambda pkt: pkt.cp
        ),
        NDRConfPacketListField(
            "apVar", [], tag_inner_PROPVARIANT, size_is=lambda pkt: pkt.cp
        ),
    ]


class R_QMMgmtGetInfo_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "apVar", [], tag_inner_PROPVARIANT, size_is=lambda pkt: pkt.cp
        ),
        NDRIntField("status", 0),
    ]


class R_QMMgmtAction_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pObjectFormat", MGMT_OBJECT(), MGMT_OBJECT),
        NDRShortField("lpwszAction", 0),
    ]


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


QMMGMT_OPNUMS = {
    0: DceRpcOp(R_QMMgmtGetInfo_Request, R_QMMgmtGetInfo_Response),
    1: DceRpcOp(R_QMMgmtAction_Request, R_QMMgmtAction_Response),
}
register_dcerpc_interface(
    name="qmmgmt",
    uuid=uuid.UUID("41208ee0-e970-11d1-9b9e-00e02c064c39"),
    version="1.0",
    opnums=QMMGMT_OPNUMS,
)
