snmpapi: Implement SnmpUtilOid{Append, Cmp, NCmp}. Fix SnmpUtilOid{Cpy, Free}.
This commit is contained in:
parent
bca85b3da3
commit
baaed37d6d
|
@ -252,24 +252,54 @@ INT WINAPI SnmpUtilOctetsCmp(AsnOctetString *octets1, AsnOctetString *octets2)
|
||||||
return SnmpUtilOctetsNCmp(octets1, octets2, octets1->length);
|
return SnmpUtilOctetsNCmp(octets1, octets2, octets1->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* SnmpUtilOidAppend (SNMPAPI.@)
|
||||||
|
*/
|
||||||
|
INT WINAPI SnmpUtilOidAppend(AsnObjectIdentifier *dst, AsnObjectIdentifier *src)
|
||||||
|
{
|
||||||
|
UINT *ids, i, size;
|
||||||
|
|
||||||
|
TRACE("(%p, %p)\n", dst, src);
|
||||||
|
|
||||||
|
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)))
|
||||||
|
{
|
||||||
|
if (!(ids = HeapAlloc(GetProcessHeap(), 0, size)))
|
||||||
|
{
|
||||||
|
SetLastError(SNMP_MEM_ALLOC_ERROR);
|
||||||
|
return SNMPAPI_ERROR;
|
||||||
|
}
|
||||||
|
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.@)
|
* SnmpUtilOidCpy (SNMPAPI.@)
|
||||||
*/
|
*/
|
||||||
INT WINAPI SnmpUtilOidCpy(AsnObjectIdentifier *dst, AsnObjectIdentifier *src)
|
INT WINAPI SnmpUtilOidCpy(AsnObjectIdentifier *dst, AsnObjectIdentifier *src)
|
||||||
{
|
{
|
||||||
unsigned int i, size;
|
|
||||||
|
|
||||||
TRACE("(%p, %p)\n", dst, src);
|
TRACE("(%p, %p)\n", dst, src);
|
||||||
|
|
||||||
size = sizeof(AsnObjectIdentifier);
|
if (!dst) return SNMPAPI_ERROR;
|
||||||
if ((dst = HeapAlloc(GetProcessHeap(), 0, size)))
|
if (!src)
|
||||||
{
|
{
|
||||||
size = src->idLength * sizeof(UINT);
|
dst->idLength = 0;
|
||||||
if (!(dst->ids = HeapAlloc(GetProcessHeap(), 0, size)))
|
dst->ids = NULL;
|
||||||
{
|
return SNMPAPI_NOERROR;
|
||||||
HeapFree(GetProcessHeap(), 0, dst);
|
}
|
||||||
return SNMPAPI_ERROR;
|
if ((dst->ids = HeapAlloc(GetProcessHeap(), 0, src->idLength * sizeof(UINT))))
|
||||||
}
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
dst->idLength = src->idLength;
|
dst->idLength = src->idLength;
|
||||||
for (i = 0; i < dst->idLength; i++) dst->ids[i] = src->ids[i];
|
for (i = 0; i < dst->idLength; i++) dst->ids[i] = src->ids[i];
|
||||||
return SNMPAPI_NOERROR;
|
return SNMPAPI_NOERROR;
|
||||||
|
@ -284,8 +314,43 @@ void WINAPI SnmpUtilOidFree(AsnObjectIdentifier *oid)
|
||||||
{
|
{
|
||||||
TRACE("(%p)\n", oid);
|
TRACE("(%p)\n", oid);
|
||||||
|
|
||||||
|
if (!oid) return;
|
||||||
|
|
||||||
|
oid->idLength = 0;
|
||||||
HeapFree(GetProcessHeap(), 0, oid->ids);
|
HeapFree(GetProcessHeap(), 0, oid->ids);
|
||||||
HeapFree(GetProcessHeap(), 0, oid);
|
oid->ids = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* SnmpUtilOidNCmp (SNMPAPI.@)
|
||||||
|
*/
|
||||||
|
INT WINAPI SnmpUtilOidNCmp(AsnObjectIdentifier *oid1, AsnObjectIdentifier *oid2, UINT count)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
TRACE("(%p, %p, %d)\n", oid1, oid2, count);
|
||||||
|
|
||||||
|
if (!oid1 || !oid2) return 0;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
if (oid1->ids[i] > oid2->ids[i]) return 1;
|
||||||
|
if (oid1->ids[i] < oid2->ids[i]) return -1;
|
||||||
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
|
@ -29,11 +29,11 @@
|
||||||
@ stdcall SnmpUtilOctetsCpy(ptr ptr)
|
@ stdcall SnmpUtilOctetsCpy(ptr ptr)
|
||||||
@ stdcall SnmpUtilOctetsFree(ptr)
|
@ stdcall SnmpUtilOctetsFree(ptr)
|
||||||
@ stdcall SnmpUtilOctetsNCmp(ptr ptr long)
|
@ stdcall SnmpUtilOctetsNCmp(ptr ptr long)
|
||||||
@ stub SnmpUtilOidAppend
|
@ stdcall SnmpUtilOidAppend(ptr ptr)
|
||||||
@ stub SnmpUtilOidCmp
|
@ stdcall SnmpUtilOidCmp(ptr ptr)
|
||||||
@ stdcall SnmpUtilOidCpy(ptr ptr)
|
@ stdcall SnmpUtilOidCpy(ptr ptr)
|
||||||
@ stdcall SnmpUtilOidFree(ptr)
|
@ stdcall SnmpUtilOidFree(ptr)
|
||||||
@ stub SnmpUtilOidNCmp
|
@ stdcall SnmpUtilOidNCmp(ptr ptr long)
|
||||||
@ stub SnmpUtilOidToA
|
@ stub SnmpUtilOidToA
|
||||||
@ stub SnmpUtilPrintAsnAny
|
@ stub SnmpUtilPrintAsnAny
|
||||||
@ stub SnmpUtilPrintOid
|
@ stub SnmpUtilPrintOid
|
||||||
|
|
Loading…
Reference in New Issue