2002-04-29 20:43:35 +02:00
|
|
|
/*
|
2007-01-22 11:05:49 +01:00
|
|
|
* Implementation of SNMPAPI.DLL
|
2002-04-29 20:43:35 +02:00
|
|
|
*
|
|
|
|
* Copyright 2002 Patrik Stridvall
|
2007-01-14 19:20:38 +01:00
|
|
|
* Copyright 2007 Hans Leidekker
|
2002-04-29 20:43:35 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-04-29 20:43:35 +02:00
|
|
|
*/
|
|
|
|
|
2007-01-22 15:30:01 +01:00
|
|
|
#include <stdio.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
2003-06-30 22:53:48 +02:00
|
|
|
#include "winbase.h"
|
2007-01-14 19:19:52 +01:00
|
|
|
#include "snmp.h"
|
|
|
|
|
2002-04-29 20:43:35 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(snmpapi);
|
|
|
|
|
2007-11-06 22:29:25 +01:00
|
|
|
static INT asn_any_copy(AsnAny *dst, const AsnAny *src)
|
2007-01-22 11:05:49 +01:00
|
|
|
{
|
|
|
|
memset(dst, 0, sizeof(AsnAny));
|
|
|
|
switch (src->asnType)
|
|
|
|
{
|
|
|
|
case ASN_INTEGER32: dst->asnValue.number = src->asnValue.number; break;
|
|
|
|
case ASN_UNSIGNED32: dst->asnValue.unsigned32 = src->asnValue.unsigned32; break;
|
|
|
|
case ASN_COUNTER64: dst->asnValue.counter64 = src->asnValue.counter64; break;
|
|
|
|
case ASN_COUNTER32: dst->asnValue.counter = src->asnValue.counter; break;
|
|
|
|
case ASN_GAUGE32: dst->asnValue.gauge = src->asnValue.gauge; break;
|
|
|
|
case ASN_TIMETICKS: dst->asnValue.ticks = src->asnValue.ticks; break;
|
|
|
|
|
|
|
|
case ASN_OCTETSTRING:
|
|
|
|
case ASN_BITS:
|
|
|
|
case ASN_SEQUENCE:
|
|
|
|
case ASN_IPADDRESS:
|
|
|
|
case ASN_OPAQUE:
|
|
|
|
{
|
|
|
|
BYTE *stream;
|
|
|
|
UINT length = src->asnValue.string.length;
|
|
|
|
|
|
|
|
if (!(stream = HeapAlloc(GetProcessHeap(), 0, length))) return SNMPAPI_ERROR;
|
2007-02-18 19:38:01 +01:00
|
|
|
memcpy(stream, src->asnValue.string.stream, length);
|
2007-01-22 11:05:49 +01:00
|
|
|
|
|
|
|
dst->asnValue.string.stream = stream;
|
|
|
|
dst->asnValue.string.length = length;
|
|
|
|
dst->asnValue.string.dynamic = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ASN_OBJECTIDENTIFIER:
|
|
|
|
{
|
|
|
|
UINT *ids, i, size = src->asnValue.object.idLength * sizeof(UINT);
|
|
|
|
|
|
|
|
if (!(ids = HeapAlloc(GetProcessHeap(), 0, size))) return SNMPAPI_ERROR;
|
|
|
|
|
|
|
|
dst->asnValue.object.ids = ids;
|
|
|
|
dst->asnValue.object.idLength = src->asnValue.object.idLength;
|
|
|
|
|
|
|
|
for (i = 0; i < dst->asnValue.object.idLength; i++)
|
|
|
|
dst->asnValue.object.ids[i] = src->asnValue.object.ids[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
WARN("unknown ASN type: %d\n", src->asnType);
|
|
|
|
return SNMPAPI_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst->asnType = src->asnType;
|
|
|
|
return SNMPAPI_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void asn_any_free(AsnAny *any)
|
|
|
|
{
|
|
|
|
switch (any->asnType)
|
|
|
|
{
|
|
|
|
case ASN_OCTETSTRING:
|
|
|
|
case ASN_BITS:
|
|
|
|
case ASN_SEQUENCE:
|
|
|
|
case ASN_IPADDRESS:
|
|
|
|
case ASN_OPAQUE:
|
|
|
|
{
|
|
|
|
if (any->asnValue.string.dynamic)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, any->asnValue.string.stream);
|
|
|
|
any->asnValue.string.stream = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ASN_OBJECTIDENTIFIER:
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, any->asnValue.object.ids);
|
|
|
|
any->asnValue.object.ids = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
any->asnType = ASN_NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-07 21:02:07 +01:00
|
|
|
static ULONGLONG startTime;
|
|
|
|
|
2002-04-29 20:43:35 +02:00
|
|
|
/***********************************************************************
|
2002-11-05 00:53:41 +01:00
|
|
|
* DllMain for SNMPAPI
|
2002-04-29 20:43:35 +02:00
|
|
|
*/
|
2002-11-05 00:53:41 +01:00
|
|
|
BOOL WINAPI DllMain(
|
2002-04-29 20:43:35 +02:00
|
|
|
HINSTANCE hInstDLL,
|
|
|
|
DWORD fdwReason,
|
|
|
|
LPVOID lpvReserved)
|
|
|
|
{
|
2006-09-29 01:19:00 +02:00
|
|
|
TRACE("(%p,%d,%p)\n", hInstDLL, fdwReason, lpvReserved);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-04-29 20:43:35 +02:00
|
|
|
switch(fdwReason) {
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2003-06-30 22:53:48 +02:00
|
|
|
DisableThreadLibraryCalls(hInstDLL);
|
2009-12-07 21:02:07 +01:00
|
|
|
startTime = GetTickCount64();
|
2002-04-29 20:43:35 +02:00
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-04-29 20:43:35 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2007-01-14 19:19:52 +01:00
|
|
|
|
2009-12-07 21:02:07 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SnmpSvcGetUptime (SNMPAPI.@)
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* This returns the number of centiseconds since the DLL was loaded,
|
|
|
|
* rather than the number of centiseconds since the SNMP service was
|
|
|
|
* started, since there isn't yet any SNMP service in Wine.
|
|
|
|
*/
|
|
|
|
DWORD WINAPI SnmpSvcGetUptime(void)
|
|
|
|
{
|
|
|
|
ULONGLONG now = GetTickCount64();
|
|
|
|
|
|
|
|
return (now - startTime) / 10;
|
|
|
|
}
|
|
|
|
|
2007-01-22 15:30:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilDbgPrint (SNMPAPI.@)
|
2007-01-24 15:39:26 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The Microsoft headers claim this function uses the stdcall calling
|
|
|
|
* convention. But stdcall functions cannot take a variable number of
|
|
|
|
* arguments so this does not make sense. The stdcall specification is
|
|
|
|
* probably ignored by Microsoft's compiler in this case. So declare it
|
|
|
|
* correctly in Wine so it works with all compilers.
|
2007-01-22 15:30:01 +01:00
|
|
|
*/
|
2007-01-25 15:10:23 +01:00
|
|
|
VOID WINAPIV SnmpUtilDbgPrint(INT loglevel, LPSTR format, ...)
|
2007-01-22 15:30:01 +01:00
|
|
|
{
|
|
|
|
FIXME("(%d, %s)\n", loglevel, debugstr_a(format));
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:08:40 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilMemAlloc (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-14 19:20:24 +01:00
|
|
|
LPVOID WINAPI SnmpUtilMemAlloc(UINT nbytes)
|
|
|
|
{
|
|
|
|
TRACE("(%d)\n", nbytes);
|
|
|
|
return HeapAlloc(GetProcessHeap(), 0, nbytes);
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:08:40 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilMemReAlloc (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-14 19:20:24 +01:00
|
|
|
LPVOID WINAPI SnmpUtilMemReAlloc(LPVOID mem, UINT nbytes)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d)\n", mem, nbytes);
|
|
|
|
return HeapReAlloc(GetProcessHeap(), 0, mem, nbytes);
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:08:40 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilMemFree (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-25 15:10:23 +01:00
|
|
|
VOID WINAPI SnmpUtilMemFree(LPVOID mem)
|
2007-01-14 19:20:24 +01:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n", mem);
|
|
|
|
HeapFree(GetProcessHeap(), 0, mem);
|
|
|
|
}
|
|
|
|
|
2007-01-22 11:05:49 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilAsnAnyCpy (SNMPAPI.@)
|
|
|
|
*/
|
|
|
|
INT WINAPI SnmpUtilAsnAnyCpy(AsnAny *dst, AsnAny *src)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %p)\n", dst, src);
|
|
|
|
return asn_any_copy(dst, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilAsnAnyFree (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-25 15:10:23 +01:00
|
|
|
VOID WINAPI SnmpUtilAsnAnyFree(AsnAny *any)
|
2007-01-22 11:05:49 +01:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n", any);
|
|
|
|
asn_any_free(any);
|
|
|
|
}
|
|
|
|
|
2007-01-22 11:06:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilOctetsCpy (SNMPAPI.@)
|
|
|
|
*/
|
|
|
|
INT WINAPI SnmpUtilOctetsCpy(AsnOctetString *dst, AsnOctetString *src)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %p)\n", dst, src);
|
|
|
|
|
|
|
|
if (!dst) return SNMPAPI_ERROR;
|
|
|
|
if (!src)
|
|
|
|
{
|
|
|
|
dst->dynamic = FALSE;
|
|
|
|
dst->length = 0;
|
|
|
|
dst->stream = NULL;
|
|
|
|
return SNMPAPI_NOERROR;
|
|
|
|
}
|
|
|
|
if ((dst->stream = HeapAlloc(GetProcessHeap(), 0, src->length)))
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
dst->dynamic = TRUE;
|
|
|
|
dst->length = src->length;
|
|
|
|
for (i = 0; i < dst->length; i++) dst->stream[i] = src->stream[i];
|
|
|
|
return SNMPAPI_NOERROR;
|
|
|
|
}
|
|
|
|
return SNMPAPI_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilOctetsFree (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-25 15:10:23 +01:00
|
|
|
VOID WINAPI SnmpUtilOctetsFree(AsnOctetString *octets)
|
2007-01-22 11:06:13 +01:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n", octets);
|
|
|
|
|
|
|
|
if (octets)
|
|
|
|
{
|
|
|
|
octets->length = 0;
|
|
|
|
if (octets->dynamic) HeapFree(GetProcessHeap(), 0, octets->stream);
|
|
|
|
octets->stream = NULL;
|
|
|
|
octets->dynamic = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilOctetsNCmp (SNMPAPI.@)
|
|
|
|
*/
|
|
|
|
INT WINAPI SnmpUtilOctetsNCmp(AsnOctetString *octets1, AsnOctetString *octets2, UINT count)
|
|
|
|
{
|
|
|
|
INT ret;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %d)\n", octets1, octets2, count);
|
|
|
|
|
|
|
|
if (!octets1 || !octets2) return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
if ((ret = octets1->stream[i] - octets2->stream[i])) return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilOctetsCmp (SNMPAPI.@)
|
|
|
|
*/
|
|
|
|
INT WINAPI SnmpUtilOctetsCmp(AsnOctetString *octets1, AsnOctetString *octets2)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %p)\n", octets1, octets2);
|
|
|
|
|
|
|
|
if (octets1->length < octets2->length) return -1;
|
|
|
|
if (octets1->length > octets2->length) return 1;
|
|
|
|
|
|
|
|
return SnmpUtilOctetsNCmp(octets1, octets2, octets1->length);
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:08:40 +01:00
|
|
|
/***********************************************************************
|
2007-01-22 11:06:38 +01:00
|
|
|
* SnmpUtilOidAppend (SNMPAPI.@)
|
2007-01-15 19:08:40 +01:00
|
|
|
*/
|
2007-01-22 11:06:38 +01:00
|
|
|
INT WINAPI SnmpUtilOidAppend(AsnObjectIdentifier *dst, AsnObjectIdentifier *src)
|
2007-01-14 19:19:52 +01:00
|
|
|
{
|
2007-01-22 11:06:38 +01:00
|
|
|
UINT *ids, i, size;
|
2007-01-14 19:19:52 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", dst, src);
|
|
|
|
|
2007-01-22 11:06:38 +01:00
|
|
|
if (!dst) return SNMPAPI_ERROR;
|
|
|
|
if (!src) return SNMPAPI_NOERROR;
|
|
|
|
|
|
|
|
size = (src->idLength + dst->idLength) * sizeof(UINT);
|
|
|
|
if (!(ids = HeapReAlloc(GetProcessHeap(), 0, dst->ids, size)))
|
2007-01-14 19:19:52 +01:00
|
|
|
{
|
2007-01-22 11:06:38 +01:00
|
|
|
if (!(ids = HeapAlloc(GetProcessHeap(), 0, size)))
|
2007-01-14 19:19:52 +01:00
|
|
|
{
|
2007-01-22 11:06:38 +01:00
|
|
|
SetLastError(SNMP_MEM_ALLOC_ERROR);
|
2007-01-14 19:19:52 +01:00
|
|
|
return SNMPAPI_ERROR;
|
|
|
|
}
|
2007-01-22 11:06:38 +01:00
|
|
|
else memcpy(ids, dst->ids, dst->idLength * sizeof(UINT));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < src->idLength; i++) ids[i + dst->idLength] = src->ids[i];
|
|
|
|
dst->idLength = dst->idLength + src->idLength;
|
|
|
|
dst->ids = ids;
|
|
|
|
|
|
|
|
return SNMPAPI_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilOidCpy (SNMPAPI.@)
|
|
|
|
*/
|
|
|
|
INT WINAPI SnmpUtilOidCpy(AsnObjectIdentifier *dst, AsnObjectIdentifier *src)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %p)\n", dst, src);
|
|
|
|
|
|
|
|
if (!dst) return SNMPAPI_ERROR;
|
|
|
|
if (!src)
|
|
|
|
{
|
|
|
|
dst->idLength = 0;
|
|
|
|
dst->ids = NULL;
|
|
|
|
return SNMPAPI_NOERROR;
|
|
|
|
}
|
|
|
|
if ((dst->ids = HeapAlloc(GetProcessHeap(), 0, src->idLength * sizeof(UINT))))
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2007-01-14 19:19:52 +01:00
|
|
|
dst->idLength = src->idLength;
|
|
|
|
for (i = 0; i < dst->idLength; i++) dst->ids[i] = src->ids[i];
|
|
|
|
return SNMPAPI_NOERROR;
|
|
|
|
}
|
|
|
|
return SNMPAPI_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:08:40 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilOidFree (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-25 15:10:23 +01:00
|
|
|
VOID WINAPI SnmpUtilOidFree(AsnObjectIdentifier *oid)
|
2007-01-14 19:19:52 +01:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n", oid);
|
|
|
|
|
2007-01-22 11:06:38 +01:00
|
|
|
if (!oid) return;
|
|
|
|
|
|
|
|
oid->idLength = 0;
|
2007-01-14 19:19:52 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, oid->ids);
|
2007-01-22 11:06:38 +01:00
|
|
|
oid->ids = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilOidNCmp (SNMPAPI.@)
|
|
|
|
*/
|
|
|
|
INT WINAPI SnmpUtilOidNCmp(AsnObjectIdentifier *oid1, AsnObjectIdentifier *oid2, UINT count)
|
|
|
|
{
|
2008-05-17 01:09:11 +02:00
|
|
|
unsigned int i, len;
|
2007-01-22 11:06:38 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %d)\n", oid1, oid2, count);
|
|
|
|
|
|
|
|
if (!oid1 || !oid2) return 0;
|
|
|
|
|
2008-05-17 01:09:11 +02:00
|
|
|
len = min(count, oid1->idLength);
|
|
|
|
len = min(len, oid2->idLength);
|
|
|
|
for (i = 0; i < len; i++)
|
2007-01-22 11:06:38 +01:00
|
|
|
{
|
|
|
|
if (oid1->ids[i] > oid2->ids[i]) return 1;
|
|
|
|
if (oid1->ids[i] < oid2->ids[i]) return -1;
|
|
|
|
}
|
2008-05-17 01:09:34 +02:00
|
|
|
if (i == count) return 0;
|
2008-05-17 01:09:11 +02:00
|
|
|
if (oid1->idLength < oid2->idLength) return -1;
|
|
|
|
if (oid1->idLength > oid2->idLength) return 1;
|
2007-01-22 11:06:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilOidCmp (SNMPAPI.@)
|
|
|
|
*/
|
|
|
|
INT WINAPI SnmpUtilOidCmp(AsnObjectIdentifier *oid1, AsnObjectIdentifier *oid2)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %p)\n", oid1, oid2);
|
|
|
|
|
|
|
|
if (oid1->idLength < oid2->idLength) return -1;
|
|
|
|
if (oid1->idLength > oid2->idLength) return 1;
|
|
|
|
|
|
|
|
return SnmpUtilOidNCmp(oid1, oid2, oid1->idLength);
|
2007-01-14 19:19:52 +01:00
|
|
|
}
|
|
|
|
|
2007-01-15 19:08:40 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilVarBindCpy (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-14 19:20:38 +01:00
|
|
|
INT WINAPI SnmpUtilVarBindCpy(SnmpVarBind *dst, SnmpVarBind *src)
|
|
|
|
{
|
|
|
|
unsigned int i, size;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", dst, src);
|
|
|
|
|
2007-01-22 11:05:49 +01:00
|
|
|
if (!dst) return SNMPAPI_ERROR;
|
|
|
|
if (!src)
|
2007-01-14 19:20:38 +01:00
|
|
|
{
|
2007-01-22 11:05:49 +01:00
|
|
|
dst->value.asnType = ASN_NULL;
|
|
|
|
return SNMPAPI_NOERROR;
|
2007-01-14 19:20:38 +01:00
|
|
|
}
|
|
|
|
|
2007-01-22 11:05:49 +01:00
|
|
|
size = src->name.idLength * sizeof(UINT);
|
|
|
|
if (!(dst->name.ids = HeapAlloc(GetProcessHeap(), 0, size))) return SNMPAPI_ERROR;
|
2007-01-14 19:20:38 +01:00
|
|
|
|
2007-01-22 11:05:49 +01:00
|
|
|
for (i = 0; i < src->name.idLength; i++) dst->name.ids[i] = src->name.ids[i];
|
|
|
|
dst->name.idLength = src->name.idLength;
|
2007-01-14 19:20:38 +01:00
|
|
|
|
2007-01-22 11:05:49 +01:00
|
|
|
if (!asn_any_copy(&dst->value, &src->value))
|
2007-01-14 19:20:38 +01:00
|
|
|
{
|
2007-01-22 11:05:49 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, dst->name.ids);
|
|
|
|
return SNMPAPI_ERROR;
|
2007-01-14 19:20:38 +01:00
|
|
|
}
|
|
|
|
return SNMPAPI_NOERROR;
|
|
|
|
}
|
|
|
|
|
2007-01-15 19:08:40 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilVarBindFree (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-25 15:10:23 +01:00
|
|
|
VOID WINAPI SnmpUtilVarBindFree(SnmpVarBind *vb)
|
2007-01-14 19:19:52 +01:00
|
|
|
{
|
|
|
|
TRACE("(%p)\n", vb);
|
|
|
|
|
2007-01-22 11:05:49 +01:00
|
|
|
if (!vb) return;
|
2007-01-14 19:19:52 +01:00
|
|
|
|
2007-01-22 11:05:49 +01:00
|
|
|
asn_any_free(&vb->value);
|
2007-01-14 19:19:52 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, vb->name.ids);
|
2007-01-22 11:05:49 +01:00
|
|
|
vb->name.idLength = 0;
|
|
|
|
vb->name.ids = NULL;
|
2007-01-14 19:19:52 +01:00
|
|
|
}
|
2007-01-15 19:08:40 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilVarBindListCpy (SNMPAPI.@)
|
|
|
|
*/
|
|
|
|
INT WINAPI SnmpUtilVarBindListCpy(SnmpVarBindList *dst, SnmpVarBindList *src)
|
|
|
|
{
|
|
|
|
unsigned int i, size;
|
|
|
|
SnmpVarBind *src_entry, *dst_entry;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", dst, src);
|
|
|
|
|
2007-01-22 15:31:50 +01:00
|
|
|
if (!src)
|
|
|
|
{
|
|
|
|
dst->list = NULL;
|
|
|
|
dst->len = 0;
|
|
|
|
return SNMPAPI_NOERROR;
|
|
|
|
}
|
2007-10-26 23:18:38 +02:00
|
|
|
size = src->len * sizeof(SnmpVarBind);
|
2007-01-15 19:08:40 +01:00
|
|
|
if (!(dst->list = HeapAlloc(GetProcessHeap(), 0, size)))
|
|
|
|
return SNMPAPI_ERROR;
|
2007-10-26 23:18:38 +02:00
|
|
|
|
2007-01-15 19:08:40 +01:00
|
|
|
src_entry = src->list;
|
|
|
|
dst_entry = dst->list;
|
|
|
|
for (i = 0; i < src->len; i++)
|
|
|
|
{
|
|
|
|
if (SnmpUtilVarBindCpy(dst_entry, src_entry))
|
|
|
|
{
|
|
|
|
src_entry++;
|
|
|
|
dst_entry++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (--i; i > 0; i--) SnmpUtilVarBindFree(--dst_entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, dst->list);
|
|
|
|
return SNMPAPI_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst->len = src->len;
|
|
|
|
return SNMPAPI_NOERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilVarBindListFree (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-25 15:10:23 +01:00
|
|
|
VOID WINAPI SnmpUtilVarBindListFree(SnmpVarBindList *vb)
|
2007-01-15 19:08:40 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
SnmpVarBind *entry;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", vb);
|
|
|
|
|
|
|
|
entry = vb->list;
|
|
|
|
for (i = 0; i < vb->len; i++) SnmpUtilVarBindFree(entry++);
|
|
|
|
HeapFree(GetProcessHeap(), 0, vb->list);
|
2007-01-22 15:31:50 +01:00
|
|
|
vb->list = NULL;
|
|
|
|
vb->len = 0;
|
2007-01-15 19:08:40 +01:00
|
|
|
}
|
2007-01-22 15:30:01 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilIdsToA (SNMPAPI.@)
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI SnmpUtilIdsToA(UINT *ids, UINT length)
|
|
|
|
{
|
|
|
|
static char one[10], oid[514], null_oid[] = "<null oid>";
|
|
|
|
unsigned int i, len, left = sizeof(oid) - 1;
|
|
|
|
|
|
|
|
TRACE("(%p, %d)\n", ids, length);
|
|
|
|
|
|
|
|
if (!ids || !length) return null_oid;
|
|
|
|
|
|
|
|
*oid = 0;
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
sprintf(one, "%d", ids[i]);
|
|
|
|
len = strlen(one);
|
|
|
|
if (left >= len)
|
|
|
|
{
|
|
|
|
strcat(oid, one);
|
|
|
|
left -= len;
|
|
|
|
}
|
|
|
|
else return oid;
|
|
|
|
|
|
|
|
if (i < length - 1)
|
|
|
|
{
|
|
|
|
if (left > 0)
|
|
|
|
{
|
|
|
|
strcat(oid, ".");
|
|
|
|
left--;
|
|
|
|
}
|
|
|
|
else return oid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return oid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilOidToA (SNMPAPI.@)
|
|
|
|
*/
|
|
|
|
LPSTR WINAPI SnmpUtilOidToA(AsnObjectIdentifier *oid)
|
|
|
|
{
|
|
|
|
static char null_oid[] = "<null oid>";
|
|
|
|
|
|
|
|
TRACE("(%p)\n", oid);
|
|
|
|
|
|
|
|
if (oid)
|
|
|
|
return SnmpUtilIdsToA(oid->ids, oid->idLength);
|
|
|
|
else
|
|
|
|
return null_oid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilPrintOid (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-25 15:10:23 +01:00
|
|
|
VOID WINAPI SnmpUtilPrintOid(AsnObjectIdentifier *oid)
|
2007-01-22 15:30:01 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", oid);
|
|
|
|
|
|
|
|
if (!oid) return;
|
|
|
|
|
|
|
|
for (i = 0; i < oid->idLength; i++)
|
|
|
|
{
|
|
|
|
TRACE("%u", oid->ids[i]);
|
|
|
|
if (i < oid->idLength - 1) TRACE(".");
|
|
|
|
}
|
2007-01-24 15:39:01 +01:00
|
|
|
TRACE("\n");
|
2007-01-22 15:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SnmpUtilPrintAsnAny (SNMPAPI.@)
|
|
|
|
*/
|
2007-01-25 15:10:23 +01:00
|
|
|
VOID WINAPI SnmpUtilPrintAsnAny(AsnAny *any)
|
2007-01-22 15:30:01 +01:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", any);
|
|
|
|
|
|
|
|
switch (any->asnType)
|
|
|
|
{
|
|
|
|
case ASN_NULL: TRACE("Null value\n"); return;
|
|
|
|
case ASN_INTEGER32: TRACE("Integer32 %d\n", any->asnValue.number); return;
|
|
|
|
case ASN_UNSIGNED32: TRACE("Unsigned32 %u\n", any->asnValue.unsigned32); return;
|
|
|
|
case ASN_COUNTER32: TRACE("Counter32 %u\n", any->asnValue.counter); return;
|
|
|
|
case ASN_GAUGE32: TRACE("Gauge32 %u\n", any->asnValue.gauge); return;
|
|
|
|
case ASN_TIMETICKS: TRACE("Timeticks %u\n", any->asnValue.ticks); return;
|
|
|
|
case ASN_COUNTER64:
|
|
|
|
{
|
2007-03-06 15:34:19 +01:00
|
|
|
TRACE("Counter64 %x%08x\n", (DWORD)(any->asnValue.counter64.QuadPart>>32),(DWORD)any->asnValue.counter64.QuadPart);
|
2007-01-22 15:30:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case ASN_OCTETSTRING:
|
|
|
|
{
|
|
|
|
TRACE("String ");
|
|
|
|
for (i = 0; i < any->asnValue.string.length; i++)
|
|
|
|
TRACE("%c", any->asnValue.string.stream[i]);
|
|
|
|
TRACE("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case ASN_IPADDRESS:
|
|
|
|
{
|
|
|
|
TRACE("IpAddress ");
|
|
|
|
if (any->asnValue.string.length < 4)
|
|
|
|
{
|
|
|
|
TRACE("Invalid\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
TRACE("%u", any->asnValue.string.stream[i]);
|
|
|
|
if (i < 3) TRACE(".");
|
|
|
|
}
|
|
|
|
TRACE("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case ASN_BITS:
|
|
|
|
{
|
|
|
|
TRACE("Bits ");
|
|
|
|
for (i = 0; i < any->asnValue.string.length; i++)
|
|
|
|
{
|
|
|
|
TRACE("0x%02x", any->asnValue.string.stream[i]);
|
|
|
|
if (i < any->asnValue.object.idLength - 1) TRACE(" ");
|
|
|
|
}
|
|
|
|
TRACE("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case ASN_OPAQUE:
|
|
|
|
{
|
|
|
|
TRACE("Opaque ");
|
|
|
|
for (i = 0; i < any->asnValue.string.length; i++)
|
|
|
|
{
|
|
|
|
TRACE("0x%02x", any->asnValue.string.stream[i]);
|
|
|
|
if (i < any->asnValue.object.idLength - 1) TRACE(" ");
|
|
|
|
}
|
|
|
|
TRACE("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case ASN_OBJECTIDENTIFIER:
|
|
|
|
{
|
|
|
|
TRACE("ObjectID ");
|
|
|
|
for (i = 0; i < any->asnValue.object.idLength; i++)
|
|
|
|
{
|
|
|
|
TRACE("%u", any->asnValue.object.ids[i]);
|
|
|
|
if (i < any->asnValue.object.idLength - 1) TRACE(".");
|
|
|
|
}
|
|
|
|
TRACE("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
TRACE("Invalid type %d\n", any->asnType);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|