-- automatically generated by posy 7.0 #3 (wk87), do not edit!

SNMP DEFINITIONS ::=

%{
#include <stdio.h>
#include "SNMP-types.h"
%}

PREFIXES encode decode print

BEGIN


ENCODER encode

Message [[P struct type_SNMP_Message *]] ::=
        SEQUENCE
            %{
            %}
        {
            version
                INTEGER
                [[i parm -> version ]]
                {
                    version-1(0)
                },

            community
                OCTET STRING
                [[q parm -> community ]],

            data
                PDUs
                [[p parm -> data ]]
        }

PDUs [[P struct type_SNMP_PDUs *]] ::=
        CHOICE <<parm -> offset>> {
            get-request
                GetRequest-PDU
                [[p parm -> un.get__request ]],

            get-next-request
                GetNextRequest-PDU
                [[p parm -> un.get__next__request ]],

            get-response
                GetResponse-PDU
                [[p parm -> un.get__response ]],

            set-request
                SetRequest-PDU
                [[p parm -> un.set__request ]],

            trap
                Trap-PDU
                [[p parm -> un.trap ]]
        }

GetRequest-PDU [[P struct type_SNMP_GetRequest__PDU *]] ::=
    [0]
        IMPLICIT PDU
        [[p parm ]]

GetNextRequest-PDU [[P struct type_SNMP_GetNextRequest__PDU *]] ::=
    [1]
        IMPLICIT PDU
        [[p parm ]]

GetResponse-PDU [[P struct type_SNMP_GetResponse__PDU *]] ::=
    [2]
        IMPLICIT PDU
        [[p parm ]]

SetRequest-PDU [[P struct type_SNMP_SetRequest__PDU *]] ::=
    [3]
        IMPLICIT PDU
        [[p parm ]]

PDU [[P struct type_SNMP_PDU *]] ::=
        SEQUENCE
            %{
            %}
        {
            request-id
                INTEGER
                [[i parm -> request__id ]],

            error-status
                INTEGER
                [[i parm -> error__status ]]
                {
                    noError(0),
                    tooBig(1),
                    noSuchName(2),
                    badValue(3),
                    readOnly(4),
                    genErr(5)
                },

            error-index
                INTEGER
                [[i parm -> error__index ]],

            variable-bindings
                VarBindList
                [[p parm -> variable__bindings ]]
        }

Trap-PDU [[P struct type_SNMP_Trap__PDU *]] ::=
    [4]
        IMPLICIT SEQUENCE
            %{
            %}
        {
            enterprise
                OBJECT IDENTIFIER
                [[O parm -> enterprise ]],

            agent-addr
                NetworkAddress
                [[p parm -> agent__addr ]],

            generic-trap
                INTEGER
                [[i parm -> generic__trap ]]
                {
                    coldStart(0),
                    warmStart(1),
                    linkDown(2),
                    linkUp(3),
                    authenticationFailure(4),
                    egpNeighborLoss(5),
                    enterpriseSpecific(6)
                },

            specific-trap
                INTEGER
                [[i parm -> specific__trap ]],

            time-stamp
                TimeTicks
                [[p parm -> time__stamp ]],

            variable-bindings
                VarBindList
                [[p parm -> variable__bindings ]]
        }

VarBind [[P struct type_SNMP_VarBind *]] ::=
        SEQUENCE
            %{
            %}
        {
            name
                ObjectName
                [[p parm -> name ]],

            value
                ObjectSyntax
                [[p parm -> value ]]
        }

VarBindList [[P struct type_SNMP_VarBindList *]] ::=
        SEQUENCE OF
            <<; parm; parm = parm -> next>>
            VarBind
            [[p parm -> VarBind ]]

ObjectName [[P struct type_SNMP_ObjectName *]] ::=
        OBJECT IDENTIFIER
        [[O parm ]]

ObjectSyntax [[P struct type_SNMP_ObjectSyntax *]] ::=
        ANY
        [[a parm ]]

NetworkAddress [[P struct type_SNMP_NetworkAddress *]] ::=
        CHOICE <<1>> {
            internet
                IpAddress
                [[p parm ]]
        }

IpAddress [[P struct type_SNMP_IpAddress *]] ::=
    [APPLICATION 0]
        IMPLICIT OCTET STRING
        [[q parm ]]

TimeTicks [[P struct type_SNMP_TimeTicks *]] ::=
    [APPLICATION 3]
        IMPLICIT INTEGER
        [[i parm -> parm ]]

DECODER decode

Message [[P struct type_SNMP_Message **]] ::=
    %{
        if ((*(parm) = (struct type_SNMP_Message *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_Message *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    %}
        SEQUENCE
            %{
            %}
        {
            version
                INTEGER
                [[i (*parm) -> version ]]
                {
                    version-1(0)
                },

            community
                OCTET STRING
                [[q (*parm) -> community ]],

            data
                PDUs
                [[p &((*parm) -> data)]]
        }

PDUs [[P struct type_SNMP_PDUs **]] ::=
    %{
        if ((*(parm) = (struct type_SNMP_PDUs *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_PDUs *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    %}
        CHOICE
        {
            get-request
                GetRequest-PDU
                [[p &((*parm) -> un.get__request)]]
                %{ (*(parm)) -> offset = type_SNMP_PDUs_get__request; %},

            get-next-request
                GetNextRequest-PDU
                [[p &((*parm) -> un.get__next__request)]]
                %{ (*(parm)) -> offset = type_SNMP_PDUs_get__next__request; %},

            get-response
                GetResponse-PDU
                [[p &((*parm) -> un.get__response)]]
                %{ (*(parm)) -> offset = type_SNMP_PDUs_get__response; %},

            set-request
                SetRequest-PDU
                [[p &((*parm) -> un.set__request)]]
                %{ (*(parm)) -> offset = type_SNMP_PDUs_set__request; %},

            trap
                Trap-PDU
                [[p &((*parm) -> un.trap)]]
                %{ (*(parm)) -> offset = type_SNMP_PDUs_trap; %}
        }

GetRequest-PDU [[P struct type_SNMP_GetRequest__PDU **]] ::=
    [0]
        IMPLICIT PDU
        [[p &((*parm))]]

GetNextRequest-PDU [[P struct type_SNMP_GetNextRequest__PDU **]] ::=
    [1]
        IMPLICIT PDU
        [[p &((*parm))]]

GetResponse-PDU [[P struct type_SNMP_GetResponse__PDU **]] ::=
    [2]
        IMPLICIT PDU
        [[p &((*parm))]]

SetRequest-PDU [[P struct type_SNMP_SetRequest__PDU **]] ::=
    [3]
        IMPLICIT PDU
        [[p &((*parm))]]

PDU [[P struct type_SNMP_PDU **]] ::=
    %{
        if ((*(parm) = (struct type_SNMP_PDU *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_PDU *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    %}
        SEQUENCE
            %{
            %}
        {
            request-id
                INTEGER
                [[i (*parm) -> request__id ]],

            error-status
                INTEGER
                [[i (*parm) -> error__status ]]
                {
                    noError(0),
                    tooBig(1),
                    noSuchName(2),
                    badValue(3),
                    readOnly(4),
                    genErr(5)
                },

            error-index
                INTEGER
                [[i (*parm) -> error__index ]],

            variable-bindings
                VarBindList
                [[p &((*parm) -> variable__bindings)]]
        }

Trap-PDU [[P struct type_SNMP_Trap__PDU **]] ::=
    %{
        if ((*(parm) = (struct type_SNMP_Trap__PDU *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_Trap__PDU *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    %}
    [4]
        IMPLICIT SEQUENCE
            %{
            %}
        {
            enterprise
                OBJECT IDENTIFIER
                [[O (*parm) -> enterprise ]],

            agent-addr
                NetworkAddress
                [[p &((*parm) -> agent__addr)]],

            generic-trap
                INTEGER
                [[i (*parm) -> generic__trap ]]
                {
                    coldStart(0),
                    warmStart(1),
                    linkDown(2),
                    linkUp(3),
                    authenticationFailure(4),
                    egpNeighborLoss(5),
                    enterpriseSpecific(6)
                },

            specific-trap
                INTEGER
                [[i (*parm) -> specific__trap ]],

            time-stamp
                TimeTicks
                [[p &((*parm) -> time__stamp)]],

            variable-bindings
                VarBindList
                [[p &((*parm) -> variable__bindings)]]
        }

VarBind [[P struct type_SNMP_VarBind **]] ::=
    %{
        if ((*(parm) = (struct type_SNMP_VarBind *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_VarBind *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    %}
        SEQUENCE
            %{
            %}
        {
            name
                ObjectName
                [[p &((*parm) -> name)]],

            value
                ObjectSyntax
                [[p &((*parm) -> value)]]
        }

VarBindList [[P struct type_SNMP_VarBindList **]] ::=
        SEQUENCE OF
            %{
                if ((*(parm) = (struct type_SNMP_VarBindList *)
                        calloc (1, sizeof **(parm))) == ((struct type_SNMP_VarBindList *) 0)) {
                    advise (NULLCP, "%s", PEPY_ERR_NOMEM);
                    return NOTOK;
                }
            %}
            VarBind
            [[p &((*parm) -> VarBind)]]
            %{ parm = &((*parm) -> next); %}

ObjectName [[P struct type_SNMP_ObjectName **]] ::=
        OBJECT IDENTIFIER
        [[O (*parm) ]]

ObjectSyntax [[P struct type_SNMP_ObjectSyntax **]] ::=
        ANY
        [[a (*parm) ]]

NetworkAddress [[P struct type_SNMP_NetworkAddress **]] ::=
        CHOICE
        {
            internet
                IpAddress
                [[p &((*parm))]]
        }

IpAddress [[P struct type_SNMP_IpAddress **]] ::=
    [APPLICATION 0]
        IMPLICIT OCTET STRING
        [[q (*parm) ]]

TimeTicks [[P struct type_SNMP_TimeTicks **]] ::=
    %{
        if ((*(parm) = (struct type_SNMP_TimeTicks *)
                calloc (1, sizeof **(parm))) == ((struct type_SNMP_TimeTicks *) 0)) {
            advise (NULLCP, "%s", PEPY_ERR_NOMEM);
            return NOTOK;
        }
    %}
    [APPLICATION 3]
        IMPLICIT INTEGER
        [[i (*parm) -> parm ]]

END

%{

free_SNMP_Message (arg)
struct type_SNMP_Message *arg;
{
    struct type_SNMP_Message *parm = arg;

    if (parm == NULL)
	return;

    if (parm -> community)
        qb_free (parm -> community),
            parm -> community = NULL;
    if (parm -> data)
        free_SNMP_PDUs (parm -> data),
            parm -> data = NULL;

    free ((char *) arg);
}

free_SNMP_PDUs (arg)
struct type_SNMP_PDUs *arg;
{
    struct type_SNMP_PDUs *parm = arg;

    if (parm == NULL)
	return;

    switch (parm -> offset) {
        case type_SNMP_PDUs_get__request:
            if (parm -> un.get__request)
                free_SNMP_GetRequest__PDU (parm -> un.get__request),
                    parm -> un.get__request = NULL;
            break;

        case type_SNMP_PDUs_get__next__request:
            if (parm -> un.get__next__request)
                free_SNMP_GetNextRequest__PDU (parm -> un.get__next__request),
                    parm -> un.get__next__request = NULL;
            break;

        case type_SNMP_PDUs_get__response:
            if (parm -> un.get__response)
                free_SNMP_GetResponse__PDU (parm -> un.get__response),
                    parm -> un.get__response = NULL;
            break;

        case type_SNMP_PDUs_set__request:
            if (parm -> un.set__request)
                free_SNMP_SetRequest__PDU (parm -> un.set__request),
                    parm -> un.set__request = NULL;
            break;

        case type_SNMP_PDUs_trap:
            if (parm -> un.trap)
                free_SNMP_Trap__PDU (parm -> un.trap),
                    parm -> un.trap = NULL;
            break;
    }

    free ((char *) arg);
}

free_SNMP_PDU (arg)
struct type_SNMP_PDU *arg;
{
    struct type_SNMP_PDU *parm = arg;

    if (parm == NULL)
	return;

    if (parm -> variable__bindings)
        free_SNMP_VarBindList (parm -> variable__bindings),
            parm -> variable__bindings = NULL;

    free ((char *) arg);
}

free_SNMP_Trap__PDU (arg)
struct type_SNMP_Trap__PDU *arg;
{
    struct type_SNMP_Trap__PDU *parm = arg;

    if (parm == NULL)
	return;

    if (parm -> enterprise)
        oid_free (parm -> enterprise),
            parm -> enterprise = NULLOID;
    if (parm -> agent__addr)
        free_SNMP_NetworkAddress (parm -> agent__addr),
            parm -> agent__addr = NULL;
    if (parm -> time__stamp)
        free_SNMP_TimeTicks (parm -> time__stamp),
            parm -> time__stamp = NULL;
    if (parm -> variable__bindings)
        free_SNMP_VarBindList (parm -> variable__bindings),
            parm -> variable__bindings = NULL;

    free ((char *) arg);
}

free_SNMP_VarBind (arg)
struct type_SNMP_VarBind *arg;
{
    struct type_SNMP_VarBind *parm = arg;

    if (parm == NULL)
	return;

    if (parm -> name)
        free_SNMP_ObjectName (parm -> name),
            parm -> name = NULL;
    if (parm -> value)
        free_SNMP_ObjectSyntax (parm -> value),
            parm -> value = NULL;

    free ((char *) arg);
}

free_SNMP_VarBindList (arg)
struct type_SNMP_VarBindList *arg;
{
    struct type_SNMP_VarBindList *parm = arg;

    if (parm == NULL)
	return;

    for (parm = parm; parm;) {
        struct type_SNMP_VarBindList *f_parm = parm -> next;

        if (parm -> VarBind)
            free_SNMP_VarBind (parm -> VarBind),
                parm -> VarBind = NULL;

        if (parm)
            free ((char *) parm);
        parm = f_parm;
    }

}

free_SNMP_TimeTicks (arg)
struct type_SNMP_TimeTicks *arg;
{
    struct type_SNMP_TimeTicks *parm = arg;

    if (parm == NULL)
	return;


    free ((char *) arg);
}

%}
