bc68cb11f3dd786dc7feb8dbceb41330838fa5f6
[strongswan.git] / Source / charon / encoding / payloads / payload.c
1 /**
2 * @file payload.c
3 *
4 * @brief Generic payload interface
5 *
6 *
7 */
8
9 /*
10 * Copyright (C) 2005 Jan Hutter, Martin Willi
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24
25 #include "payload.h"
26
27 #include <encoding/payloads/ike_header.h>
28 #include <encoding/payloads/sa_payload.h>
29 #include <encoding/payloads/nonce_payload.h>
30 #include <encoding/payloads/id_payload.h>
31 #include <encoding/payloads/ke_payload.h>
32 #include <encoding/payloads/notify_payload.h>
33 #include <encoding/payloads/auth_payload.h>
34 #include <encoding/payloads/ts_payload.h>
35
36 /*
37 * build the mappings for payload_type_t
38 */
39 mapping_t payload_type_m[] = {
40 {NO_PAYLOAD, "NO_PAYLOAD"},
41 {SECURITY_ASSOCIATION, "SECURITY_ASSOCIATION"},
42 {KEY_EXCHANGE, "KEY_EXCHANGE"},
43 {ID_INITIATOR, "ID_INITIATOR"},
44 {ID_RESPONDER, "ID_RESPONDER"},
45 {CERTIFICATE, "CERTIFICATE"},
46 {CERTIFICATE_REQUEST, "CERTIFICATE_REQUEST"},
47 {AUTHENTICATION, "AUTHENTICATION"},
48 {NONCE, "NONCE"},
49 {NOTIFY, "NOTIFY"},
50 {DELETE, "DELETE"},
51 {VENDOR_ID, "VENDOR_ID"},
52 {TRAFFIC_SELECTOR_INITIATOR, "TRAFFIC_SELECTOR_INITIATOR"},
53 {TRAFFIC_SELECTOR_RESPONDER, "TRAFFIC_SELECTOR_RESPONDER"},
54 {ENCRYPTED, "ENCRYPTED"},
55 {CONFIGURATION, "CONFIGURATION"},
56 {EXTENSIBLE_AUTHENTICATION, "EXTENSIBLE_AUTHENTICATION"},
57 {HEADER, "HEADER"},
58 {PROPOSAL_SUBSTRUCTURE, "PROPOSAL_SUBSTRUCTURE"},
59 {TRANSFORM_SUBSTRUCTURE, "TRANSFORM_SUBSTRUCTURE"},
60 {TRANSFORM_ATTRIBUTE, "TRANSFORM_ATTRIBUTE"},
61 {TRAFFIC_SELECTOR_SUBSTRUCTURE, "TRAFFIC_SELECTOR_SUBSTRUCTURE"},
62 {MAPPING_END, NULL}
63 };
64
65 /*
66 * see header
67 */
68 payload_t *payload_create(payload_type_t type)
69 {
70 switch (type)
71 {
72 case HEADER:
73 return (payload_t*)ike_header_create();
74 case SECURITY_ASSOCIATION:
75 return (payload_t*)sa_payload_create();
76 case PROPOSAL_SUBSTRUCTURE:
77 return (payload_t*)proposal_substructure_create();
78 case TRANSFORM_SUBSTRUCTURE:
79 return (payload_t*)transform_substructure_create();
80 case TRANSFORM_ATTRIBUTE:
81 return (payload_t*)transform_attribute_create();
82 case NONCE:
83 return (payload_t*)nonce_payload_create();
84 case ID_INITIATOR:
85 return (payload_t*)id_payload_create(TRUE);
86 case ID_RESPONDER:
87 return (payload_t*)id_payload_create(FALSE);
88 case AUTHENTICATION:
89 return (payload_t*)auth_payload_create();
90 case TRAFFIC_SELECTOR_SUBSTRUCTURE:
91 return (payload_t*)traffic_selector_substructure_create();
92 case TRAFFIC_SELECTOR_INITIATOR:
93 return (payload_t*)ts_payload_create(TRUE);
94 case TRAFFIC_SELECTOR_RESPONDER:
95 return (payload_t*)ts_payload_create(FALSE);
96 case KEY_EXCHANGE:
97 return (payload_t*)ke_payload_create();
98 case NOTIFY:
99 return (payload_t*)notify_payload_create();
100 default:
101 return NULL;
102 }
103 }
104