⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rvmegacoauth.c

📁 h.248协议源码
💻 C
字号:
/******************************************************************************
Filename:    rvmegacoauth.c
Description: megaco authentication header class
*******************************************************************************
                Copyright (c) 2000 RADVision Inc.
*******************************************************************************
NOTICE:
This document contains information that is proprietary to RADVision Inc.
No part of this publication may be reproduced in any form whatsoever without
written prior approval by RADVision Inc.

RADVision Inc. reserves the right to revise this publication and make changes
without obligation to notify any person of such revisions or changes.
******************************************************************************/

#include "rvmegacoauth.h"
#include "rvdefalloc.h"


/*
{function:
	{name: rvMegacoAuthenticationHeaderConstruct}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Constructs an authentication header object.}
	}
	{proto: RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderConstruct(RvMegacoAuthenticationHeader *x, unsigned int index, unsigned int seqNum, const char *data);}
	{params:
		{param: {n:x} {d:The authentication header object.}}
		{param: {n:index} {d:The security parameters index.}}
		{param: {n:seqNum} {d:The sequence number.}}
		{param: {n:data} {d:The authentication data.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
	{notes:
		{note: see RFC2402}
	}
}
*/
RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderConstruct(RvMegacoAuthenticationHeader *x, unsigned int index, unsigned int seqNum, const char *data)
{
	return rvMegacoAuthenticationHeaderConstructA(x, index, seqNum, data, &rvDefaultAlloc);
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderConstructA}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Constructs an authentication header object.}
	}
	{proto: RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderConstructA(RvMegacoAuthenticationHeader *x, unsigned int index, unsigned int seqNum, const char *data, RvAlloc *alloc);}
	{params:
		{param: {n:x} {d:The authentication header object.}}
		{param: {n:index} {d:The security parameters index.}}
		{param: {n:seqNum} {d:The sequence number.}}
		{param: {n:data} {d:The authentication data.}}
		{param: {n:alloc} {d:The allocator to use.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
	{notes:
		{note: see RFC2402}
	}
}
*/
RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderConstructA(RvMegacoAuthenticationHeader *x, unsigned int index, unsigned int seqNum, const char *data, RvAlloc *alloc)
{
	x->securityIndex = index;
	x->sequenceNum = seqNum;
	rvStringConstruct(&x->authData, data, alloc);
	return x;
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderConstructString}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Constructs an authentication header object.}
	}
	{proto: RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderConstructString(RvMegacoAuthenticationHeader *x, unsigned int index, unsigned int seqNum, const RvString *data, RvAlloc *alloc);}
	{params:
		{param: {n:x} {d:The authentication header object.}}
		{param: {n:index} {d:The security parameters index.}}
		{param: {n:seqNum} {d:The sequence number.}}
		{param: {n:data} {d:The authentication data.}}
		{param: {n:alloc} {d:The allocator to use.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
	{notes:
		{note: see RFC2402}
		{note: special version for parser.}
	}
}
*/
RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderConstructString(RvMegacoAuthenticationHeader *x, unsigned int index, unsigned int seqNum, const RvString *data, RvAlloc *alloc)
{
	x->securityIndex = index;
	x->sequenceNum = seqNum;
	rvStringConstructCopy(&x->authData, data, alloc);
	return x;
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderConstructCopy}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Constructs a copy of an authentication header object.}
	}
	{proto: RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderConstructCopy(RvMegacoAuthenticationHeader *d, const RvMegacoAuthenticationHeader *s, RvAlloc *alloc);}
	{params:
		{param: {n:d} {d:The destination authentication header object.}}
		{param: {n:s} {d:The authentication header object to copy.}}
		{param: {n:alloc} {d:The allocator to use.}}
	}
	{returns: A pointer to the constructed object, or NULL if construction failed.}
}
*/
RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderConstructCopy(RvMegacoAuthenticationHeader *d, const RvMegacoAuthenticationHeader *s, RvAlloc *alloc)
{
	d->securityIndex = s->securityIndex;
	d->sequenceNum = s->sequenceNum;
	rvStringConstructCopy(&d->authData, &s->authData, alloc);
	return d;
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderDestruct}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Destroys an authentication header object.}
	}
	{proto: void rvMegacoAuthenticationHeaderDestruct(RvMegacoAuthenticationHeader *x);}
	{params:
		{param: {n:x} {d:The authentication header object.}}
	}
}
*/
void rvMegacoAuthenticationHeaderDestruct(RvMegacoAuthenticationHeader *x)
{
	rvStringDestruct(&x->authData);
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderCopy}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Copies the value of one authentication header object to another.}
	}
	{proto: RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderCopy(RvMegacoAuthenticationHeader *d, const RvMegacoAuthenticationHeader *s);}
	{params:
		{param: {n:d} {d:The destination authentication header object.}}
		{param: {n:s} {d:The authentication header object to copy.}}
	}
	{returns: A pointer to the destination object, or NULL if the copy failed.}
}
*/
RvMegacoAuthenticationHeader *rvMegacoAuthenticationHeaderCopy(RvMegacoAuthenticationHeader *d, const RvMegacoAuthenticationHeader *s)
{
	d->securityIndex = s->securityIndex;
	d->sequenceNum = s->sequenceNum;
	rvStringCopy(&d->authData, &s->authData);
	return d;
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderEqual}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Compares two authentication header objects for equality.}
	}
	{proto: RvBool rvMegacoAuthenticationHeaderEqual(const RvMegacoAuthenticationHeader *a, const RvMegacoAuthenticationHeader *b);}
	{params:
		{param: {n:a} {d:The first authentication header object.}}
		{param: {n:b} {d:The second authentication header object.}}
	}
	{returns: rvTrue if the objects are equal, rvFalse if not.}
}
*/
RvBool rvMegacoAuthenticationHeaderEqual(const RvMegacoAuthenticationHeader *a, const RvMegacoAuthenticationHeader *b)
{
	return a->securityIndex == b->securityIndex && 
		a->sequenceNum == b->sequenceNum &&
		rvStringEqual(&a->authData, &b->authData);
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderGetSecurityIndex}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Gets the security parameters index of the authentication header object.}
	}
	{proto: unsigned int rvMegacoAuthenticationHeaderGetSecurityIndex(const RvMegacoAuthenticationHeader *x);}
	{params:
		{param: {n:x} {d:The authentication header object.}}
	}
	{returns: The security parameters index.}
}
*/
unsigned int rvMegacoAuthenticationHeaderGetSecurityIndex(const RvMegacoAuthenticationHeader *x)
{
	return x->securityIndex;
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderGetSequenceNumber}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Gets the sequence number of the authentication header object.}
	}
	{proto: unsigned int rvMegacoAuthenticationHeaderGetSequenceNumber(const RvMegacoAuthenticationHeader *x);}
	{params:
		{param: {n:x} {d:The authentication header object.}}
	}
	{returns: The sequence number.}
}
*/
unsigned int rvMegacoAuthenticationHeaderGetSequenceNumber(const RvMegacoAuthenticationHeader *x)
{
	return x->sequenceNum;
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderGetData}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Gets the authentication data of the authentication header object.}
	}
	{proto: const char *rvMegacoAuthenticationHeaderGetData(const RvMegacoAuthenticationHeader *x);}
	{params:
		{param: {n:x} {d:The authentication header object.}}
	}
	{returns: The data.}
}
*/
const char *rvMegacoAuthenticationHeaderGetData(const RvMegacoAuthenticationHeader *x)
{
	return rvStringGetData(&x->authData);
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderGetDataLength}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Gets the length of the authentication data of the authentication header object.}
	}
	{proto: size_t rvMegacoAuthenticationHeaderGetDataLength(const RvMegacoAuthenticationHeader *x);}
	{params:
		{param: {n:x} {d:The authentication header object.}}
	}
	{returns: The length.}
}
*/
size_t rvMegacoAuthenticationHeaderGetDataLength(const RvMegacoAuthenticationHeader *x)
{
	return rvStringGetSize(&x->authData);
}


/*
{function:
	{name: rvMegacoAuthenticationHeaderEncode}
	{class: RvMegacoAuthenticationHeader}
	{include: rvmegacoauth.h}
	{description:
		{p: Encodes an authentication header.}
	}
	{proto: void rvMegacoAuthenticationHeaderEncode(const RvMegacoAuthenticationHeader *x, RvStrStream *os, RvBool encodeCompact);}
	{params:
		{param: {n:x} {d:The authentication header object.}}
		{param: {n:os} {d:The string stream to encode to.}}
		{param: {n:encodeCompact} {d:Set to rvTrue to encode as compact as possible.
		 Set to rvFalse to encode in a more readable format.}}
	}
}
*/
void rvMegacoAuthenticationHeaderEncode(const RvMegacoAuthenticationHeader *x, RvStrStream *os, RvBool encodeCompact)
{
	rvStrStreamWriteStr(os, encodeCompact ? "AU" : "Authentication");
	rvStrStreamWriteStr(os, "=0x");
	rvStrStreamWriteHexIntW(os, rvMegacoAuthenticationHeaderGetSecurityIndex(x), 8, '0');
	rvStrStreamWriteStr(os, ":0x");
	rvStrStreamWriteHexIntW(os, rvMegacoAuthenticationHeaderGetSequenceNumber(x), 8, '0');
	rvStrStreamWriteStr(os, ":0x");
	rvStrStreamWriteStr(os, rvMegacoAuthenticationHeaderGetData(x));
	rvStrStreamPut(os, '\n');
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -