]> git.ipfire.org Git - thirdparty/strongswan.git/blob - src/frontends/android/app/src/main/java/org/strongswan/android/logic/imc/attributes/SettingsAttribute.java
android: Migrate to the Gradle build system
[thirdparty/strongswan.git] / src / frontends / android / app / src / main / java / org / strongswan / android / logic / imc / attributes / SettingsAttribute.java
1 /*
2 * Copyright (C) 2013 Tobias Brunner
3 * Copyright (C) 2012 Christoph Buehler
4 * Copyright (C) 2012 Patrick Loetscher
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 package org.strongswan.android.logic.imc.attributes;
19
20 import java.util.LinkedList;
21
22 import org.strongswan.android.utils.BufferedByteWriter;
23
24 import android.util.Pair;
25
26 /**
27 * ITA Settings attribute
28 *
29 * 1 2 3
30 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Settings Count |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Name Length | Name (Variable Length) ~
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * ~ Name (Variable Length) ~
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * | Value Length | Value (Variable Length) ~
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * ~ Value (Variable Length) ~
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 * | Name Length | Name (Variable Length) ~
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * ~ Name (Variable Length) ~
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | Value Length | Value (Variable Length) ~
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
48 * ~ Value (Variable Length) ~
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 * ...........................
51 */
52 public class SettingsAttribute implements Attribute
53 {
54 private final LinkedList<Pair<String, String>> mSettings = new LinkedList<Pair<String, String>>();
55
56 /**
57 * Add a setting to this attribute.
58 * @param name name of the setting
59 * @param value value of the setting
60 */
61 public void addSetting(String name, String value)
62 {
63 mSettings.add(new Pair<String, String>(name, value));
64 }
65
66 @Override
67 public byte[] getEncoding()
68 {
69 BufferedByteWriter writer = new BufferedByteWriter();
70 writer.put32(mSettings.size());
71 for (Pair<String, String> pair : mSettings)
72 {
73 writer.putLen16(pair.first.getBytes());
74 writer.putLen16(pair.second.getBytes());
75 }
76 return writer.toByteArray();
77 }
78 }