/*							-- DO NOT EDIT --
 * This file has been generated by smidump
 * version 0.3.1 for the scli package.
 *
 * Derived from SNMP-COMMUNITY-MIB:
 *   This MIB module defines objects to help support coexistence
 *   between SNMPv1, SNMPv2c, and SNMPv3.
 *
 * Revision 2000-03-06 00:00:
 *   This version published as RFC 2576.
 *
 * Revision 1999-05-13 00:00:
 *   The Initial Revision
 *
 * $Id: snmp-community-mib.c,v 1.18 2002/03/27 13:48:22 schoenw Exp $
 */

#include "snmp-community-mib.h"

GSnmpEnum const snmp_community_mib_enums_snmpCommunityStorageType[] = {
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTORAGETYPE_OTHER,       "other" },
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTORAGETYPE_VOLATILE,    "volatile" },
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTORAGETYPE_NONVOLATILE, "nonVolatile" },
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTORAGETYPE_PERMANENT,   "permanent" },
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTORAGETYPE_READONLY,    "readOnly" },
    { 0, NULL }
};

GSnmpEnum const snmp_community_mib_enums_snmpCommunityStatus[] = {
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTATUS_ACTIVE,        "active" },
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTATUS_NOTINSERVICE,  "notInService" },
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTATUS_NOTREADY,      "notReady" },
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTATUS_CREATEANDGO,   "createAndGo" },
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTATUS_CREATEANDWAIT, "createAndWait" },
    { SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTATUS_DESTROY,       "destroy" },
    { 0, NULL }
};


static guint16 snmpCommunitySecurityName_constraints[] = {1, 32, 0, 0};
static guint16 snmpCommunityContextEngineID_constraints[] = {5, 32, 0, 0};
static guint16 snmpCommunityContextName_constraints[] = {0, 32, 0, 0};
static guint16 snmpCommunityTransportTag_constraints[] = {0, 255, 0, 0};
static guint16 snmpTargetAddrTMask_constraints[] = {0, 255, 0, 0};
static guint32 snmpTargetAddrMMS_constraints[] = {0L, 0L, 484L, 2147483647L, 0, 0};


static guint32 const snmpCommunityEntry_oid[] = {1, 3, 6, 1, 6, 3, 18, 1, 1, 1};

static GSnmpAttribute snmpCommunityEntry_attr[] = {
    { 2, G_SNMP_OCTETSTRING,
      SNMP_COMMUNITY_MIB_SNMPCOMMUNITYNAME, "snmpCommunityName",
       NULL,
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, snmpCommunityName),
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, _snmpCommunityNameLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 3, G_SNMP_OCTETSTRING,
      SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSECURITYNAME, "snmpCommunitySecurityName",
       snmpCommunitySecurityName_constraints,
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, snmpCommunitySecurityName),
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, _snmpCommunitySecurityNameLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 4, G_SNMP_OCTETSTRING,
      SNMP_COMMUNITY_MIB_SNMPCOMMUNITYCONTEXTENGINEID, "snmpCommunityContextEngineID",
       snmpCommunityContextEngineID_constraints,
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, snmpCommunityContextEngineID),
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, _snmpCommunityContextEngineIDLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 5, G_SNMP_OCTETSTRING,
      SNMP_COMMUNITY_MIB_SNMPCOMMUNITYCONTEXTNAME, "snmpCommunityContextName",
       snmpCommunityContextName_constraints,
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, snmpCommunityContextName),
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, _snmpCommunityContextNameLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 6, G_SNMP_OCTETSTRING,
      SNMP_COMMUNITY_MIB_SNMPCOMMUNITYTRANSPORTTAG, "snmpCommunityTransportTag",
       snmpCommunityTransportTag_constraints,
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, snmpCommunityTransportTag),
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, _snmpCommunityTransportTagLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 7, G_SNMP_INTEGER32,
      SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTORAGETYPE, "snmpCommunityStorageType",
       NULL,
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, snmpCommunityStorageType),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 8, G_SNMP_INTEGER32,
      SNMP_COMMUNITY_MIB_SNMPCOMMUNITYSTATUS, "snmpCommunityStatus",
       NULL,
      G_STRUCT_OFFSET(snmp_community_mib_snmpCommunityEntry_t, snmpCommunityStatus),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 0, 0, 0, NULL }
};

static guint32 const snmpTargetAddrExtEntry_oid[] = {1, 3, 6, 1, 6, 3, 18, 1, 2, 1};

static GSnmpAttribute snmpTargetAddrExtEntry_attr[] = {
    { 1, G_SNMP_OCTETSTRING,
      SNMP_COMMUNITY_MIB_SNMPTARGETADDRTMASK, "snmpTargetAddrTMask",
       snmpTargetAddrTMask_constraints,
      G_STRUCT_OFFSET(snmp_community_mib_snmpTargetAddrExtEntry_t, snmpTargetAddrTMask),
      G_STRUCT_OFFSET(snmp_community_mib_snmpTargetAddrExtEntry_t, _snmpTargetAddrTMaskLength),
      GSNMP_ATTR_FLAG_WRITABLE },
    { 2, G_SNMP_INTEGER32,
      SNMP_COMMUNITY_MIB_SNMPTARGETADDRMMS, "snmpTargetAddrMMS",
       snmpTargetAddrMMS_constraints,
      G_STRUCT_OFFSET(snmp_community_mib_snmpTargetAddrExtEntry_t, snmpTargetAddrMMS),
      0,
      GSNMP_ATTR_FLAG_WRITABLE },
    { 0, 0, 0, NULL }
};


snmp_community_mib_snmpCommunityEntry_t *
snmp_community_mib_new_snmpCommunityEntry()
{
    snmp_community_mib_snmpCommunityEntry_t *snmpCommunityEntry;

    snmpCommunityEntry = (snmp_community_mib_snmpCommunityEntry_t *) g_malloc0(sizeof(snmp_community_mib_snmpCommunityEntry_t) + sizeof(gpointer));
    return snmpCommunityEntry;
}

static int
unpack_snmpCommunityEntry(GSnmpVarBind *vb, snmp_community_mib_snmpCommunityEntry_t *snmpCommunityEntry)
{
    guint8 idx = 11;
    guint16 i, len;

    if (vb->id_len < idx) return -1;
    len = vb->id_len - idx;
    if (len < 1 || len > 32) return -1;
    if (vb->id_len < idx + len) return -1;
    for (i = 0; i < len; i++) {
        snmpCommunityEntry->snmpCommunityIndex[i] = vb->id[idx++];
    }
    snmpCommunityEntry->_snmpCommunityIndexLength = len;
    if (vb->id_len > idx) return -1;
    return 0;
}

static int
pack_snmpCommunityEntry(guint32 *base, guchar *snmpCommunityIndex, guint16 _snmpCommunityIndexLength)
{
    guint8 idx = 11;
    guint16 i, len;

    len = _snmpCommunityIndexLength;
    if (len < 1 || len > 32) return -1;
    for (i = 0; i < len; i++) {
        base[idx++] = snmpCommunityIndex[i];
        if (idx >= 128) return -1;
    }
    return idx;
}

static snmp_community_mib_snmpCommunityEntry_t *
assign_snmpCommunityEntry(GSList *vbl)
{
    snmp_community_mib_snmpCommunityEntry_t *snmpCommunityEntry;
    char *p;

    snmpCommunityEntry = snmp_community_mib_new_snmpCommunityEntry();
    if (! snmpCommunityEntry) {
        return NULL;
    }

    p = (char *) snmpCommunityEntry + sizeof(snmp_community_mib_snmpCommunityEntry_t);
    * (GSList **) p = vbl;

    if (unpack_snmpCommunityEntry((GSnmpVarBind *) vbl->data, snmpCommunityEntry) < 0) {
        g_warning("%s: invalid instance identifier", "snmpCommunityEntry");
        g_free(snmpCommunityEntry);
        return NULL;
    }

    gsnmp_attr_assign(vbl, snmpCommunityEntry_oid, sizeof(snmpCommunityEntry_oid)/sizeof(guint32),
                      snmpCommunityEntry_attr, snmpCommunityEntry);

    return snmpCommunityEntry;
}

void
snmp_community_mib_get_snmpCommunityTable(GSnmpSession *s, snmp_community_mib_snmpCommunityEntry_t ***snmpCommunityEntry, gint mask)
{
    GSList *in = NULL, *out = NULL;
    GSList *row;
    int i;
    static guint32 base[] = {1, 3, 6, 1, 6, 3, 18, 1, 1, 1, 0};

    *snmpCommunityEntry = NULL;

    gsnmp_attr_get(s, &in, base, 11, 10, snmpCommunityEntry_attr, mask);

    out = gsnmp_gettable(s, in);
    /* g_snmp_vbl_free(in); */

    if (out) {
        *snmpCommunityEntry = (snmp_community_mib_snmpCommunityEntry_t **) g_malloc0((g_slist_length(out) + 1) * sizeof(snmp_community_mib_snmpCommunityEntry_t *));
        if (! *snmpCommunityEntry) {
            s->error_status = G_SNMP_ERR_INTERNAL;
            g_snmp_vbl_free(out);
            return;
        }
        for (row = out, i = 0; row; row = g_slist_next(row), i++) {
            (*snmpCommunityEntry)[i] = assign_snmpCommunityEntry(row->data);
        }
    }
}

void
snmp_community_mib_get_snmpCommunityEntry(GSnmpSession *s, snmp_community_mib_snmpCommunityEntry_t **snmpCommunityEntry, guchar *snmpCommunityIndex, guint16 _snmpCommunityIndexLength, gint mask)
{
    GSList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memset(base, 0, sizeof(base));
    memcpy(base, snmpCommunityEntry_oid, sizeof(snmpCommunityEntry_oid));
    len = pack_snmpCommunityEntry(base, snmpCommunityIndex, _snmpCommunityIndexLength);
    if (len < 0) {
        g_warning("%s: invalid index values", "snmpCommunityEntry");
        s->error_status = G_SNMP_ERR_INTERNAL;
        return;
    }

    *snmpCommunityEntry = NULL;

    gsnmp_attr_get(s, &in, base, len, 10, snmpCommunityEntry_attr, mask);

    out = g_snmp_session_sync_get(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        if (s->error_status != G_SNMP_ERR_NOERROR) {
            g_snmp_vbl_free(out);
            return;
        }
        *snmpCommunityEntry = assign_snmpCommunityEntry(out);
    }
}

void
snmp_community_mib_set_snmpCommunityEntry(GSnmpSession *s, snmp_community_mib_snmpCommunityEntry_t *snmpCommunityEntry, gint mask)
{
    GSList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memset(base, 0, sizeof(base));
    memcpy(base, snmpCommunityEntry_oid, sizeof(snmpCommunityEntry_oid));
    len = pack_snmpCommunityEntry(base, snmpCommunityEntry->snmpCommunityIndex, snmpCommunityEntry->_snmpCommunityIndexLength);
    if (len < 0) {
        g_warning("%s: invalid index values", "snmpCommunityEntry");
        s->error_status = G_SNMP_ERR_INTERNAL;
        return;
    }

    gsnmp_attr_set(s, &in, base, len, 10, snmpCommunityEntry_attr, mask, snmpCommunityEntry);

    out = g_snmp_session_sync_set(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        g_snmp_vbl_free(out);
    }
}

void
snmp_community_mib_free_snmpCommunityEntry(snmp_community_mib_snmpCommunityEntry_t *snmpCommunityEntry)
{
    GSList *vbl;
    char *p;

    if (snmpCommunityEntry) {
        p = (char *) snmpCommunityEntry + sizeof(snmp_community_mib_snmpCommunityEntry_t);
        vbl = * (GSList **) p;
        g_snmp_vbl_free(vbl);
        g_free(snmpCommunityEntry);
    }
}

void
snmp_community_mib_free_snmpCommunityTable(snmp_community_mib_snmpCommunityEntry_t **snmpCommunityEntry)
{
    int i;

    if (snmpCommunityEntry) {
        for (i = 0; snmpCommunityEntry[i]; i++) {
            snmp_community_mib_free_snmpCommunityEntry(snmpCommunityEntry[i]);
        }
        g_free(snmpCommunityEntry);
    }
}

snmp_community_mib_snmpTargetAddrExtEntry_t *
snmp_community_mib_new_snmpTargetAddrExtEntry()
{
    snmp_community_mib_snmpTargetAddrExtEntry_t *snmpTargetAddrExtEntry;

    snmpTargetAddrExtEntry = (snmp_community_mib_snmpTargetAddrExtEntry_t *) g_malloc0(sizeof(snmp_community_mib_snmpTargetAddrExtEntry_t) + sizeof(gpointer));
    return snmpTargetAddrExtEntry;
}

static int
unpack_snmpTargetAddrExtEntry(GSnmpVarBind *vb, snmp_community_mib_snmpTargetAddrExtEntry_t *snmpTargetAddrExtEntry)
{
    guint8 idx = 11;
    guint16 i, len;

    if (vb->id_len < idx) return -1;
    len = vb->id_len - idx;
    if (len < 1 || len > 32) return -1;
    if (vb->id_len < idx + len) return -1;
    for (i = 0; i < len; i++) {
        snmpTargetAddrExtEntry->snmpTargetAddrName[i] = vb->id[idx++];
    }
    snmpTargetAddrExtEntry->_snmpTargetAddrNameLength = len;
    if (vb->id_len > idx) return -1;
    return 0;
}

static int
pack_snmpTargetAddrExtEntry(guint32 *base, guchar *snmpTargetAddrName, guint16 _snmpTargetAddrNameLength)
{
    guint8 idx = 11;
    guint16 i, len;

    len = _snmpTargetAddrNameLength;
    if (len < 1 || len > 32) return -1;
    for (i = 0; i < len; i++) {
        base[idx++] = snmpTargetAddrName[i];
        if (idx >= 128) return -1;
    }
    return idx;
}

static snmp_community_mib_snmpTargetAddrExtEntry_t *
assign_snmpTargetAddrExtEntry(GSList *vbl)
{
    snmp_community_mib_snmpTargetAddrExtEntry_t *snmpTargetAddrExtEntry;
    char *p;

    snmpTargetAddrExtEntry = snmp_community_mib_new_snmpTargetAddrExtEntry();
    if (! snmpTargetAddrExtEntry) {
        return NULL;
    }

    p = (char *) snmpTargetAddrExtEntry + sizeof(snmp_community_mib_snmpTargetAddrExtEntry_t);
    * (GSList **) p = vbl;

    if (unpack_snmpTargetAddrExtEntry((GSnmpVarBind *) vbl->data, snmpTargetAddrExtEntry) < 0) {
        g_warning("%s: invalid instance identifier", "snmpTargetAddrExtEntry");
        g_free(snmpTargetAddrExtEntry);
        return NULL;
    }

    gsnmp_attr_assign(vbl, snmpTargetAddrExtEntry_oid, sizeof(snmpTargetAddrExtEntry_oid)/sizeof(guint32),
                      snmpTargetAddrExtEntry_attr, snmpTargetAddrExtEntry);

    return snmpTargetAddrExtEntry;
}

void
snmp_community_mib_get_snmpTargetAddrExtTable(GSnmpSession *s, snmp_community_mib_snmpTargetAddrExtEntry_t ***snmpTargetAddrExtEntry, gint mask)
{
    GSList *in = NULL, *out = NULL;
    GSList *row;
    int i;
    static guint32 base[] = {1, 3, 6, 1, 6, 3, 18, 1, 2, 1, 0};

    *snmpTargetAddrExtEntry = NULL;

    gsnmp_attr_get(s, &in, base, 11, 10, snmpTargetAddrExtEntry_attr, mask);

    out = gsnmp_gettable(s, in);
    /* g_snmp_vbl_free(in); */

    if (out) {
        *snmpTargetAddrExtEntry = (snmp_community_mib_snmpTargetAddrExtEntry_t **) g_malloc0((g_slist_length(out) + 1) * sizeof(snmp_community_mib_snmpTargetAddrExtEntry_t *));
        if (! *snmpTargetAddrExtEntry) {
            s->error_status = G_SNMP_ERR_INTERNAL;
            g_snmp_vbl_free(out);
            return;
        }
        for (row = out, i = 0; row; row = g_slist_next(row), i++) {
            (*snmpTargetAddrExtEntry)[i] = assign_snmpTargetAddrExtEntry(row->data);
        }
    }
}

void
snmp_community_mib_get_snmpTargetAddrExtEntry(GSnmpSession *s, snmp_community_mib_snmpTargetAddrExtEntry_t **snmpTargetAddrExtEntry, guchar *snmpTargetAddrName, guint16 _snmpTargetAddrNameLength, gint mask)
{
    GSList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memset(base, 0, sizeof(base));
    memcpy(base, snmpTargetAddrExtEntry_oid, sizeof(snmpTargetAddrExtEntry_oid));
    len = pack_snmpTargetAddrExtEntry(base, snmpTargetAddrName, _snmpTargetAddrNameLength);
    if (len < 0) {
        g_warning("%s: invalid index values", "snmpTargetAddrExtEntry");
        s->error_status = G_SNMP_ERR_INTERNAL;
        return;
    }

    *snmpTargetAddrExtEntry = NULL;

    gsnmp_attr_get(s, &in, base, len, 10, snmpTargetAddrExtEntry_attr, mask);

    out = g_snmp_session_sync_get(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        if (s->error_status != G_SNMP_ERR_NOERROR) {
            g_snmp_vbl_free(out);
            return;
        }
        *snmpTargetAddrExtEntry = assign_snmpTargetAddrExtEntry(out);
    }
}

void
snmp_community_mib_set_snmpTargetAddrExtEntry(GSnmpSession *s, snmp_community_mib_snmpTargetAddrExtEntry_t *snmpTargetAddrExtEntry, gint mask)
{
    GSList *in = NULL, *out = NULL;
    guint32 base[128];
    gint8 len;

    memset(base, 0, sizeof(base));
    memcpy(base, snmpTargetAddrExtEntry_oid, sizeof(snmpTargetAddrExtEntry_oid));
    len = pack_snmpTargetAddrExtEntry(base, snmpTargetAddrExtEntry->snmpTargetAddrName, snmpTargetAddrExtEntry->_snmpTargetAddrNameLength);
    if (len < 0) {
        g_warning("%s: invalid index values", "snmpTargetAddrExtEntry");
        s->error_status = G_SNMP_ERR_INTERNAL;
        return;
    }

    gsnmp_attr_set(s, &in, base, len, 10, snmpTargetAddrExtEntry_attr, mask, snmpTargetAddrExtEntry);

    out = g_snmp_session_sync_set(s, in);
    g_snmp_vbl_free(in);
    if (out) {
        g_snmp_vbl_free(out);
    }
}

void
snmp_community_mib_free_snmpTargetAddrExtEntry(snmp_community_mib_snmpTargetAddrExtEntry_t *snmpTargetAddrExtEntry)
{
    GSList *vbl;
    char *p;

    if (snmpTargetAddrExtEntry) {
        p = (char *) snmpTargetAddrExtEntry + sizeof(snmp_community_mib_snmpTargetAddrExtEntry_t);
        vbl = * (GSList **) p;
        g_snmp_vbl_free(vbl);
        g_free(snmpTargetAddrExtEntry);
    }
}

void
snmp_community_mib_free_snmpTargetAddrExtTable(snmp_community_mib_snmpTargetAddrExtEntry_t **snmpTargetAddrExtEntry)
{
    int i;

    if (snmpTargetAddrExtEntry) {
        for (i = 0; snmpTargetAddrExtEntry[i]; i++) {
            snmp_community_mib_free_snmpTargetAddrExtEntry(snmpTargetAddrExtEntry[i]);
        }
        g_free(snmpTargetAddrExtEntry);
    }
}


