Commit baaed37d authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

snmpapi: Implement SnmpUtilOid{Append, Cmp, NCmp}. Fix SnmpUtilOid{Cpy, Free}.

parent bca85b3d
...@@ -253,23 +253,53 @@ INT WINAPI SnmpUtilOctetsCmp(AsnOctetString *octets1, AsnOctetString *octets2) ...@@ -253,23 +253,53 @@ INT WINAPI SnmpUtilOctetsCmp(AsnOctetString *octets1, AsnOctetString *octets2)
} }
/*********************************************************************** /***********************************************************************
* SnmpUtilOidCpy (SNMPAPI.@) * SnmpUtilOidAppend (SNMPAPI.@)
*/ */
INT WINAPI SnmpUtilOidCpy(AsnObjectIdentifier *dst, AsnObjectIdentifier *src) INT WINAPI SnmpUtilOidAppend(AsnObjectIdentifier *dst, AsnObjectIdentifier *src)
{ {
unsigned int i, size; UINT *ids, 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) return SNMPAPI_NOERROR;
size = (src->idLength + dst->idLength) * sizeof(UINT);
if (!(ids = HeapReAlloc(GetProcessHeap(), 0, dst->ids, size)))
{ {
size = src->idLength * sizeof(UINT); if (!(ids = HeapAlloc(GetProcessHeap(), 0, size)))
if (!(dst->ids = HeapAlloc(GetProcessHeap(), 0, size)))
{ {
HeapFree(GetProcessHeap(), 0, dst); SetLastError(SNMP_MEM_ALLOC_ERROR);
return SNMPAPI_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.@)
*/
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;
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) ...@@ -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 @@ ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment