7e64993234a39f9688edcee59a56fddddb261a32
[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/cert_payload.h>
35 #include <encoding/payloads/encryption_payload.h>
36 #include <encoding/payloads/ts_payload.h>
37
38 /*
39 * build the mappings for payload_type_t
40 */
41 mapping_t payload_type_m[] = {
42 {NO_PAYLOAD, "NO_PAYLOAD"},
43 {SECURITY_ASSOCIATION, "SECURITY_ASSOCIATION"},
44 {KEY_EXCHANGE, "KEY_EXCHANGE"},
45 {ID_INITIATOR, "ID_INITIATOR"},
46 {ID_RESPONDER, "ID_RESPONDER"},
47 {CERTIFICATE, "CERTIFICATE"},
48 {CERTIFICATE_REQUEST, "CERTIFICATE_REQUEST"},
49 {AUTHENTICATION, "AUTHENTICATION"},
50 {NONCE, "NONCE"},
51 {NOTIFY, "NOTIFY"},
52 {DELETE, "DELETE"},
53 {VENDOR_ID, "VENDOR_ID"},
54 {TRAFFIC_SELECTOR_INITIATOR, "TRAFFIC_SELECTOR_INITIATOR"},
55 {TRAFFIC_SELECTOR_RESPONDER, "TRAFFIC_SELECTOR_RESPONDER"},
56 {ENCRYPTED, "ENCRYPTED"},
57 {CONFIGURATION, "CONFIGURATION"},
58 {EXTENSIBLE_AUTHENTICATION, "EXTENSIBLE_AUTHENTICATION"},
59 {HEADER, "HEADER"},
60 {PROPOSAL_SUBSTRUCTURE, "PROPOSAL_SUBSTRUCTURE"},
61 {TRANSFORM_SUBSTRUCTURE, "TRANSFORM_SUBSTRUCTURE"},
62 {TRANSFORM_ATTRIBUTE, "TRANSFORM_ATTRIBUTE"},
63 {TRAFFIC_SELECTOR_SUBSTRUCTURE, "TRAFFIC_SELECTOR_SUBSTRUCTURE"},
64 {MAPPING_END, NULL}
65 };
66
67 /*
68 * see header
69 */
70 payload_t *payload_create(payload_type_t type)
71 {
72 switch (type)
73 {
74 case HEADER:
75 return (payload_t*)ike_header_create();
76 case SECURITY_ASSOCIATION:
77 return (payload_t*)sa_payload_create();
78 case PROPOSAL_SUBSTRUCTURE:
79 return (payload_t*)proposal_substructure_create();
80 case TRANSFORM_SUBSTRUCTURE:
81 return (payload_t*)transform_substructure_create();
82 case TRANSFORM_ATTRIBUTE:
83 return (payload_t*)transform_attribute_create();
84 case NONCE:
85 return (payload_t*)nonce_payload_create();
86 case ID_INITIATOR:
87 return (payload_t*)id_payload_create(TRUE);
88 case ID_RESPONDER:
89 return (payload_t*)id_payload_create(FALSE);
90 case AUTHENTICATION:
91 return (payload_t*)auth_payload_create();
92 case CERTIFICATE:
93 return (payload_t*)cert_payload_create();
94 case TRAFFIC_SELECTOR_SUBSTRUCTURE:
95 return (payload_t*)traffic_selector_substructure_create();
96 case TRAFFIC_SELECTOR_INITIATOR:
97 return (payload_t*)ts_payload_create(TRUE);
98 case TRAFFIC_SELECTOR_RESPONDER:
99 return (payload_t*)ts_payload_create(FALSE);
100 case KEY_EXCHANGE:
101 return (payload_t*)ke_payload_create();
102 case NOTIFY:
103 return (payload_t*)notify_payload_create();
104 case ENCRYPTED:
105 return (payload_t*)encryption_payload_create();
106 default:
107 return NULL;
108 }
109 }
110