DiameterUtils.h 2.9 KB
Newer Older
C
calin cerchez 已提交
1
//
C
calin cerchez 已提交
2 3
// Copyright (C) 2012 Calin Cerchez
//
C
calin cerchez 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// This program 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 3 of the License, or
// (at your option) any later version.
// 
// This program 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 program.  If not, see http://www.gnu.org/licenses/.
// 

#ifndef DIAMETERUTILS_H_
#define DIAMETERUTILS_H_

#include <string>
#include "DiameterMessage_m.h"

#define IPV4_ADDRESS_TYPE	1
#define IPV4_ADDRESS_SIZE	4

C
calincerchez 已提交
27 28 29
/*
 * Diameter utility class. It is used for creating and processing Diameter header and AVPs.
 */
C
calin cerchez 已提交
30 31 32 33 34
class DiameterUtils {
public:
	DiameterUtils();
	virtual ~DiameterUtils();

C
calincerchez 已提交
35 36 37 38 39
	/*
	 * Methods for Diameter header and AVP creation.
	 */
    DiameterHeader createHeader(unsigned commandCode, bool reqFlag, bool prxyFlag, bool errFlag, bool retrFlag, unsigned applId, unsigned hopByHopId, unsigned endToEndId);
	AVP *createBaseAVP(unsigned avpCode, bool vendFlag, bool manFlag, bool privFlag, unsigned vendorId);
C
calin cerchez 已提交
40 41 42 43 44 45 46
	AVP *createOctetStringAVP(unsigned avpCode, bool vendFlag, bool manFlag, bool privFlag, unsigned vendorId, unsigned len, const char *str);
	AVP *createUTF8StringAVP(unsigned avpCode, bool vendFlag, bool manFlag, bool privFlag, unsigned vendorId, std::string str);
	AVP *createAddressAVP(unsigned avpCode, bool vendFlag, bool manFlag, bool privFlag, unsigned vendorId, IPvXAddress addr);
	AVP *createUnsigned32AVP(unsigned avpCode, bool vendFlag, bool manFlag, bool privFlag, unsigned vendorId, unsigned val);
	AVP *createInteger32AVP(unsigned avpCode, bool vendFlag, bool manFlag, bool privFlag, unsigned vendorId, int val);
	AVP *createGroupedAVP(unsigned avpCode, bool vendFlag, bool manFlag, bool privFlag, unsigned vendorId, std::vector<AVP*> avps);

C
calincerchez 已提交
47 48 49
	/*
	 * Methods for Diameter header and AVP processing.
	 */
C
calin cerchez 已提交
50 51 52 53 54 55 56
	unsigned processUnsigned32AVP(AVP *unsigned32AVP);
	int processInteger32AVP(AVP *integer32AVP);
	char *processOctetStringAVP(AVP *octetStringAVP);
	std::string processUTF8String(AVP *utf8StringAVP);
	IPvXAddress processAddressAVP(AVP *addressAVP);
	std::vector<AVP*> processGroupedAVP(AVP *groupedAVP);

C
calincerchez 已提交
57 58 59
	/*
	 * Methods for finding AVP or arrays of AVPs in grouped AVPs.
	 */
C
calin cerchez 已提交
60 61 62
	AVP *findAVP(unsigned avpCode, std::vector<AVP*>avps);
	std::vector<AVP*> findAVPs(unsigned avpCode, std::vector<AVP*>avps);

C
calincerchez 已提交
63 64 65
	/*
	 * Method for printing the name of a AVP code.
	 */
C
calin cerchez 已提交
66
	const char *avpName(unsigned avpCode);
C
calincerchez 已提交
67 68 69 70

	/*
	 * Method for cleaning grouped AVPs.
	 */
C
calin cerchez 已提交
71 72 73 74
	void deleteGroupedAVP(std::vector<AVP*>avps);
};

#endif /* DIAMETERUTILS_H_ */