summaryrefslogtreecommitdiff
path: root/client/platform.h
blob: 30b890fcd517d3848c77b0f072a770509c803da9 (plain)
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
/*

  Copyright (c) 2009-2011 Samuel Lidén Borell <samuel@kodafritt.se>
 
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.

*/

#ifndef PLATFORM_H
#define PLATFORM_H

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "backend.h"

/* Initialization */
void platform_init(int *argc, char ***argv);

/* Pipe I/O */
typedef void (PlatformPipeFunction) (void);
void platform_setupPipe(PlatformPipeFunction *pipeFunction);

/* File IO */
typedef enum { Platform_OpenRead, Platform_OpenCreate } PlatformOpenMode;
FILE *platform_openLocked(const char *filename, PlatformOpenMode mode);
bool platform_closeLocked(FILE *file);
bool platform_deleteLocked(FILE *file, const char *filename);
bool platform_readFile(const char *filename, char **data, int *length);

typedef struct PlatformDirIter PlatformDirIter;
PlatformDirIter *platform_openDir(const char *pathname);
bool platform_iterateDir(PlatformDirIter *iter);
char *platform_currentName(PlatformDirIter *iter);
char *platform_currentPath(PlatformDirIter *iter);
void platform_closeDir(PlatformDirIter *iter);

void platform_keyDirs(char*** path, size_t* len);
PlatformDirIter *platform_openKeysDir(char *path);
char *platform_filterFilename(const char *filename);
char *platform_getFilenameForKey(const char *nameAttr);
char *platform_getDumpFilename(const char *prefix, const char *suffix);

/* Configuration */
char *platform_getConfigPath(const char *appname);

typedef struct PlatformConfig PlatformConfig;
PlatformConfig *platform_openConfig(const char *appname,
                                    const char *configname);
bool platform_saveConfig(PlatformConfig *config);
void platform_freeConfig(PlatformConfig *config);

#define PLATFORM_CFGPARAMS PlatformConfig *config, \
                           const char *section, const char *name
bool platform_getConfigInteger(const PLATFORM_CFGPARAMS, long *value);
bool platform_getConfigBool(const PLATFORM_CFGPARAMS, bool *value);
bool platform_getConfigString(const PLATFORM_CFGPARAMS, char **value);

void platform_setConfigInteger(PLATFORM_CFGPARAMS, long value);
void platform_setConfigBool(PLATFORM_CFGPARAMS, bool value);
void platform_setConfigString(PLATFORM_CFGPARAMS, const char *value);

/* User interface */

// This value has to match the value in the window system
// (for example, None on X11)
#define PLATFORM_NO_WINDOW 0

void platform_mainloop(void);
void platform_leaveMainloop(void);

/* Signature dialog */
void platform_startSign(const char *url, const char *hostname, const char *ip,
                        unsigned long parentWindowId);
void platform_endSign(void);
void platform_setNotifier(BackendNotifier *notifier);
void platform_setMessage(const char *message);
void platform_focusPassword();
void platform_addKeyDirectories(void);
void platform_addToken(Token *token);
void platform_removeToken(Token *token);
bool platform_sign(Token **token, char *password, int password_maxlen);

/* Password selection (and key generation) dialog */
void platform_startChoosePassword(const char *name, unsigned long parentWindowId);
void platform_setPasswordPolicy(int minLength, int minNonDigits, int minDigits);
void platform_endChoosePassword(void);
bool platform_choosePassword(char *password, long password_maxlen);

/* Errors */
void platform_showError(TokenError error);

#endif