- added and tested id_payload_t
[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
34
35
36
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 {MAPPING_END, NULL}
64 };
65
66 /*
67 * see header
68 */
69 payload_t *payload_create(payload_type_t type)
70 {
71 switch (type)
72 {
73 case HEADER:
74 return (payload_t*)ike_header_create();
75 case SECURITY_ASSOCIATION:
76 return (payload_t*)sa_payload_create();
77 case PROPOSAL_SUBSTRUCTURE:
78 return (payload_t*)proposal_substructure_create();
79 case TRANSFORM_SUBSTRUCTURE:
80 return (payload_t*)transform_substructure_create();
81 case TRANSFORM_ATTRIBUTE:
82 return (payload_t*)transform_attribute_create();
83 case NONCE:
84 return (payload_t*)nonce_payload_create();
85 case ID_INITIATOR:
86 return (payload_t*)id_payload_create(TRUE);
87 case ID_RESPONDER:
88 return (payload_t*)id_payload_create(FALSE);
89 case KEY_EXCHANGE:
90 return (payload_t*)ke_payload_create();
91 case NOTIFY:
92 return (payload_t*)notify_payload_create();
93 default:
94 return NULL;
95 }
96 }
97