summaryrefslogtreecommitdiff
path: root/src/libcharon/encoding/payloads/fragment_payload.h
blob: a49cf32ddfbf87f70f12c132c9407ae84d429679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (C) 2012 Tobias Brunner
 * Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * 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 General Public License
 * for more details.
 */

/**
 * @defgroup fragment_payload fragment_payload
 * @{ @ingroup payloads
 */

#ifndef FRAGMENT_PAYLOAD_H_
#define FRAGMENT_PAYLOAD_H_

typedef struct fragment_payload_t fragment_payload_t;

#include <library.h>
#include <encoding/payloads/payload.h>

/**
 * Object representing an IKEv1 fragment payload.
 */
struct fragment_payload_t {

	/**
	 * The payload_t interface.
	 */
	payload_t payload_interface;

	/**
	 * Get the fragment ID. Identifies the fragments for a particular IKE
	 * message.
	 *
	 * @return				fragment ID
	 */
	u_int16_t (*get_id)(fragment_payload_t *this);

	/**
	 * Get the fragment number. Defines the order of the fragments.
	 *
	 * @return				fragment number
	 */
	u_int8_t (*get_number)(fragment_payload_t *this);

	/**
	 * Check if this is the last fragment.
	 *
	 * @return				TRUE if this is the last fragment
	 */
	bool (*is_last)(fragment_payload_t *this);

	/**
	 * Get the fragment data.
	 *
	 * @return				chunkt to internal fragment data
	 */
	chunk_t (*get_data)(fragment_payload_t *this);

	/**
	 * Destroys an fragment_payload_t object.
	 */
	void (*destroy)(fragment_payload_t *this);
};

/**
 * Creates an empty fragment_payload_t object.
 *
 * @return			fragment_payload_t object
 */
fragment_payload_t *fragment_payload_create();

/**
 * Creates a fragment payload from the given data.  All fragments currently
 * have the same fragment ID (1), which seems what other implementations are
 * doing.
 *
 * @param num		fragment number (first one should be 1)
 * @param last		TRUE to indicate that this is the last fragment
 * @param data		fragment data (gets cloned)
 * @return			fragment_payload_t object
 */
fragment_payload_t *fragment_payload_create_from_data(u_int8_t num, bool last,
													  chunk_t data);

#endif /** FRAGMENT_PAYLOAD_H_ @}*/