-
Notifications
You must be signed in to change notification settings - Fork 4
/
GPGOptions.h
379 lines (329 loc) · 12.5 KB
/
GPGOptions.h
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
//
// GPGOptions.h
// GPGPreferences and MacGPGME
//
// Created by davelopper at users.sourceforge.net on Sun Feb 03 2002.
//
//
// Copyright (C) 2002-2006 Mac GPG Project.
//
// This code is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your option)
// any later version.
//
// This code 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 Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, visit <http://www.gnu.org/> or write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
// MA 02111-1307, USA.
//
// More info at <http://macgpg.sourceforge.net/>
//
#ifndef GPGOPTIONS_H
#define GPGOPTIONS_H
#include <Foundation/Foundation.h>
#include <MacGPGME/GPGDefines.h>
#ifdef __cplusplus
extern "C" {
#if 0 /* just to make Emacs auto-indent happy */
}
#endif
#endif
/*!
* @const GPGUserDefaultsSuiteName
* @abstract Name of the user defaults domain global for all MacGPGME-based
* applications (<code>net.sourceforge.macgpg</code>).
*/
GPG_EXPORT NSString * const GPGUserDefaultsSuiteName;
/*!
* @const GPGOpenPGPExecutablePathKey
* @abstract Name of the user defaults key containing the default path to the
* <code>gpg</code> executable (<code>GPGOpenPGPExecutablePath</code>).
*/
GPG_EXPORT NSString * const GPGOpenPGPExecutablePathKey;
/*!
* @const GPGDefaultsDidChangeNotification
* @abstract Posted after defaults in the @link ////macgpg/c/const/GPGUserDefaultsSuiteName GPGUserDefaultsSuiteName \@link defaults domain have been changed.
* @discussion Object is (currently) nil.
*
* This notification is also posted by the distributed notification
* center. object is also nil.
*/
GPG_EXPORT NSString * const GPGDefaultsDidChangeNotification;
/*!
* @class GPGOptions
* @abstract Represents GnuPG configuration options.
* @discussion GPGOptions class allows you to retrieve options used by GnuPG,
* as defined in <a href="http://macgpg.sf.net/" target="_blank">GPGPreferences</a>,
* from GnuPG configuration file, read by the executable.
*
* You can also set options and save them, though this should be
* the job of GPGPreferences only.
*
* Options are defined by a name, a state (active or not), and,
* optionally (sic), a value.
*
* Some options (e.g. <code>keyserver-options</code>) can have
* sub-options too.
*/
@interface GPGOptions : NSObject
{
NSString *path;
NSMutableArray *optionFileLines;
NSMutableArray *optionNames;
NSMutableArray *optionValues;
NSMutableArray *optionStates;
NSMutableArray *optionLineNumbers;
BOOL hasModifications;
}
/*!
* @method homeDirectoryChanged
* @abstract Returns whether user changed GnuPG's home directory, i.e.
* <code>@link //macgpg/occ/clm/GPGOptions/homeDirectory homeDirectory@/link</code>
* is equal or not to
* <code>@link //macgpg/occ/instm/GPGEngine/homeDirectory homeDirectory@/link</code>
* (GPGEngine).
*/
+ (BOOL) homeDirectoryChanged;
/*!
* @method setDefaultValue:forKey:
* @abstract Sets default in GPGUserDefaultsSuiteName defaults suite.
* @discussion Posts a @link //macgpg/c/const/GPGDefaultsDidChangeNotification GPGDefaultsDidChangeNotification@/link
* notification. If <i>value</i> is nil, default is removed.
* @param value The defaults value
* @param key The defaults key
*/
+ (void) setDefaultValue:(id)value forKey:(NSString *)key;
- (id) initWithPath:(NSString *)path;
/*!
* @methodgroup Setting options
*/
/*!
* @method setOptionValue:atIndex:
* @abstract (brief description)
* @discussion If <i>value</i> is nil, option is removed.
* @param value (description)
* @param index (description)
*/
- (void) setOptionValue:(NSString *)value atIndex:(unsigned)index;
/*!
* @method setEmptyOptionValueAtIndex:
* @abstract (brief description)
* @discussion (comprehensive description)
* @param index (description)
*/
- (void) setEmptyOptionValueAtIndex:(unsigned)index;
/*!
* @method setOptionName:atIndex:
* @abstract (brief description)
* @discussion (comprehensive description)
* @param name (description)
* @param index (description)
*/
- (void) setOptionName:(NSString *)name atIndex:(unsigned)index;
/*!
* @method setOptionState:atIndex:
* @abstract (brief description)
* @discussion (comprehensive description)
* @param flag (description)
* @param index (description)
*/
- (void) setOptionState:(BOOL)flag atIndex:(unsigned)index;
/*!
* @method addOptionNamed:
* @abstract Adds a new option named <i>name</i>, not active, with an empty
* value.
* @param name New option name
*/
- (void) addOptionNamed:(NSString *)name;
/*!
* @method addOptionNamed:value:state:
* @abstract Adds a new option, with an value and state.
* @discussion Does not disable existing options with same name. Use it only
* when option can appear multiple times.
* @param name New option name
* @param value New option value
* @param state New option state
*/
- (void) addOptionNamed:(NSString *)name value:(NSString *)value state:(BOOL)state;
/*!
* @method insertOptionNamed:atIndex:
* @abstract (brief description)
* @discussion (comprehensive description)
* @param name (description)
* @param index (description)
*/
- (void) insertOptionNamed:(NSString *)name atIndex:(unsigned)index;
/*!
* @method removeOptionAtIndex:
* @abstract (brief description)
* @discussion (comprehensive description)
* @param index (description)
*/
- (void) removeOptionAtIndex:(unsigned)index;
/*!
* @method moveOptionsAtIndexes:toIndex:
* @abstract Reorders options at <i>indexes</i> to new <i>index</i>. Returns
* the new index.
* @discussion <code>@link saveOptions saveOptions@/link</code> is
* automatically called. Returns the index of the first moved
* option.
* @param indexes Array of indexes as <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>
* objects
* @param index An index
*/
- (unsigned) moveOptionsAtIndexes:(NSArray *)indexes toIndex:(unsigned)index;
/*!
* @methodgroup Getting options
*/
/*!
* @method optionNames
* @abstract Returns all option names, active or not. The same option name
* can appear multiple times.
*/
- (NSArray *) optionNames;
/*!
* @method optionValues
* @abstract Returns all option values, active or not.
* @discussion There are as many option values as option names returned by
* <code>@link optionNames optionNames@/link</code>.
*/
- (NSArray *) optionValues;
/*!
* @method optionStates
* @abstract Returns all option states as an array of <code>@link //apple_ref/occ/cl/NSNumber NSNumber@/link</code>
* objects (boolean values).
* @discussion There are as many option states as option names returned by
* <code>@link optionNames optionNames@/link</code>.
*/
- (NSArray *) optionStates;
/*!
* @method optionValueForName:
* @abstract Returns the option value named <i>name</i>, used by GnuPG.
* @discussion In case of multiple occurences of the a named option, returns
* the used one. Note that the option might be inactive. Returns
* nil if option is not defined.
* @param name Option name
*/
- (NSString *) optionValueForName:(NSString *)name;
/*!
* @method setOptionValue:forName:
* @abstract (brief description)
* @discussion If <i>value</i> is nil, option is removed. You need to call
* <code>@link saveOptions saveOptions@/link</code>.
* @param value (description)
* @param name (description)
*/
- (void) setOptionValue:(NSString *)value forName:(NSString *)name;
/*!
* @method setEmptyOptionValueForName:
* @abstract (brief description)
* @discussion You need to call <code>@link saveOptions saveOptions@/link</code>.
* @param name (description)
*/
- (void) setEmptyOptionValueForName:(NSString *)name;
/*!
* @method optionStateForName:
* @abstract (brief description)
* @discussion (comprehensive description)
* @param name (description)
*/
- (BOOL) optionStateForName:(NSString *)name;
/*!
* @method setOptionState:forName:
* @abstract (brief description)
* @discussion If <i>state</i> is <code>YES</code> and option does not yet
* exist, it is created. You need to call <code>@link saveOptions saveOptions@/link</code>.
* @param state (description)
* @param name (description)
*/
- (void) setOptionState:(BOOL)state forName:(NSString *)name;
/*!
* @methodgroup Sub-options
*/
/*!
* @method subOptionState:forName:
* @abstract Returns sub-option's state, in named option.
* @discussion Used for <code>keyserver-options</code> option.
* @param subOptionName Sub-option name
* @param optionName Option name
*/
- (BOOL) subOptionState:(NSString *)subOptionName forName:(NSString *)optionName;
/*!
* @method setSubOption:state:forName:
* @abstract Sets sub-option's state, in named option, and enables option.
* @discussion Used for <code>keyserver-options</code> option. If <i>state</i>
* is <code>YES</code> and option does not yet exist, it is
* created. You need to call <code>@link saveOptions saveOptions@/link</code>.
* @param subOptionName Sub-option name
* @param state Sub-option new state
* @param optionName Option name
*/
- (void) setSubOption:(NSString *)subOptionName state:(BOOL)state forName:(NSString *)optionName;
/*!
* @method subOptionValue:state:forName:
* @abstract Returns sub-option's value and state, in named option.
* @discussion Used for <code>keyserver-options</code> option.
* @param subOptionName Sub-option name
* @param statePtr Used to return state; may be NULL
* @param optionName Option name
*/
- (NSString *) subOptionValue:(NSString *)subOptionName state:(BOOL *)statePtr forName:(NSString *)optionName;
/*!
* @method setSubOption:value:state:forName:
* @abstract Sets sub-option's value and state, in named option, and enables
* option.
* @discussion Used for <code>keyserver-options</code> option. If <i>state</i>
* is <code>YES</code> and option does not yet exist, it is
* created. You need to call <code>@link saveOptions saveOptions@/link</code>.
* @param subOptionName Sub-option name
* @param value Sub-option new value
* @param state Sub-option new state
* @param optionName Option name
*/
- (void) setSubOption:(NSString *)subOptionName value:(NSString *)value state:(BOOL)state forName:(NSString *)optionName;
/*!
* @methodgroup Loading and saving options
*/
/*!
* @method reloadOptions
* @abstract Re-reads GnuPG's configuration file.
* @discussion If user changed GnuPG's <i>home directory</i> without logging
* out and in, options might be not yet active, and changes won't
* be taken in account before logging out and in.
*/
- (void) reloadOptions;
/*!
* @method saveOptions
* @abstract Save options by writing file back.
* @discussion If user changed GnuPG's <i>home directory</i> without logging
* out and in, new options might be not yet valid.
*/
- (void) saveOptions;
/*!
* @methodgroup Getting inactive and active options
*/
/*!
* @method allOptionValuesForName:
* @abstract Returns all values for named option whatever their state is.
* @param name Option name
*/
- (NSArray *) allOptionValuesForName:(NSString *)name;
/*!
* @method activeOptionValuesForName:
* @abstract Returns all values for named option whose state is active.
* @discussion First value is the used value, in case no more than one value
* is considered by GnuPG.
* @param name Option name
*/
- (NSArray *) activeOptionValuesForName:(NSString *)name;
@end
#ifdef __cplusplus
}
#endif
#endif /* GPGOPTIONS_H */