1/*
2 * Copyright 2003-2004, Haiku Inc.
3 * Distributed under the terms of the MIT License.
4 */
5
6#ifndef _K_PPP_CONFIGURE_PACKET__H
7#define _K_PPP_CONFIGURE_PACKET__H
8
9#include <TemplateList.h>
10#include <net_buffer.h>
11
12//!	An abstract configure item.
13typedef struct ppp_configure_item {
14	uint8 type;
15		//!< Item's type.
16	uint8 length;
17		//!< Item length (including appended data, if any).
18	uint8 data[0];
19		//!< Additional data may be appended to this structure.
20} ppp_configure_item;
21
22
23class KPPPConfigurePacket {
24	private:
25		// copies are not allowed!
26		KPPPConfigurePacket(const KPPPConfigurePacket& copy);
27		KPPPConfigurePacket& operator= (const KPPPConfigurePacket& copy);
28
29	public:
30		KPPPConfigurePacket(uint8 code);
31		KPPPConfigurePacket(net_buffer *packet);
32		~KPPPConfigurePacket();
33
34		bool SetCode(uint8 code);
35		//!	Returns this packet's code value.
36		uint8 Code() const
37			{ return fCode; }
38
39		//!	Sets the packet's (unique) ID. Use KPPPLCP::NextID() to get a unique ID.
40		void SetID(uint8 id)
41			{ fID = id; }
42		//!	Returns this packet's ID.
43		uint8 ID() const
44			{ return fID; }
45
46		bool AddItem(const ppp_configure_item *item, int32 index = -1);
47		bool RemoveItem(ppp_configure_item *item);
48		//!	Returns number of items in this packet.
49		int32 CountItems() const
50			{ return fItems.CountItems(); }
51		ppp_configure_item *ItemAt(int32 index) const;
52		ppp_configure_item *ItemWithType(uint8 type) const;
53
54		net_buffer *ToNetBuffer(uint32 MRU);
55			// the user is responsible for freeing the net_buffer
56
57	private:
58		uint8 fCode, fID;
59		TemplateList<ppp_configure_item*> fItems;
60};
61
62
63#endif
64