* gpgkeys_ldap.c (printquoted), curl-shim.c (curl_escape): Fix bad
[gnupg.git] / keyserver / ksutil.h
blob16c1ebf88c897d2bd08ba5fc3f045eb7d0668ab2
1 /* ksutil.h
2 * Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
4 * This file is part of GNUPG.
6 * GNUPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNUPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 * USA.
22 #ifndef _KSUTIL_H_
23 #define _KSUTIL_H_
25 #ifdef HAVE_LIBCURL
26 #include <curl/curl.h>
27 #else
28 #include "curl-shim.h"
29 #endif
31 /* MAX_LINE must be at least 1 larger than the largest item we expect
32 to receive, including the name tag ("COMMAND", "PORT", etc) and
33 space between. In practice, that means it should be
34 strlen("OPAQUE")+1+sizeof_opaque+1 */
35 #define MAX_LINE (6+1+1024+1)
37 #define MAX_COMMAND 7
38 #define MAX_OPTION 256
39 #define MAX_SCHEME 20
40 #define MAX_OPAQUE 1024
41 #define MAX_AUTH 128
42 #define MAX_HOST 80
43 #define MAX_PORT 10
44 #define URLMAX_PATH 1024
45 #define MAX_PROXY 128
46 #define MAX_URL (MAX_SCHEME+1+3+MAX_AUTH+1+1+MAX_HOST+1+1 \
47 +MAX_PORT+1+1+URLMAX_PATH+1+50)
49 #define STRINGIFY(x) #x
50 #define MKSTRING(x) STRINGIFY(x)
52 #define BEGIN "-----BEGIN PGP PUBLIC KEY BLOCK-----"
53 #define END "-----END PGP PUBLIC KEY BLOCK-----"
55 #ifdef __riscos__
56 #define HTTP_PROXY_ENV "GnuPG$HttpProxy"
57 #else
58 #define HTTP_PROXY_ENV "http_proxy"
59 #endif
61 struct keylist
63 char str[MAX_LINE];
64 struct keylist *next;
67 /* 2 minutes seems reasonable */
68 #define DEFAULT_KEYSERVER_TIMEOUT 120
70 unsigned int set_timeout(unsigned int seconds);
71 int register_timeout(void);
73 enum ks_action {KS_UNKNOWN=0,KS_GET,KS_GETNAME,KS_SEND,KS_SEARCH};
75 enum ks_search_type {KS_SEARCH_SUBSTR,KS_SEARCH_EXACT,
76 KS_SEARCH_MAIL,KS_SEARCH_MAILSUB,
77 KS_SEARCH_KEYID_LONG,KS_SEARCH_KEYID_SHORT};
79 struct ks_options
81 enum ks_action action;
82 char *host;
83 char *port;
84 char *scheme;
85 char *auth;
86 char *path;
87 char *opaque;
88 struct
90 unsigned int include_disabled:1;
91 unsigned int include_revoked:1;
92 unsigned int include_subkeys:1;
93 unsigned int check_cert:1;
94 } flags;
95 unsigned int verbose;
96 unsigned int debug;
97 unsigned int timeout;
98 char *ca_cert_file;
101 struct ks_options *init_ks_options(void);
102 void free_ks_options(struct ks_options *opt);
103 int parse_ks_options(char *line,struct ks_options *opt);
104 const char *ks_action_to_string(enum ks_action action);
105 void print_nocr(FILE *stream,const char *str);
106 enum ks_search_type classify_ks_search(const char **search);
108 int curl_err_to_gpg_err(CURLcode error);
110 struct curl_writer_ctx
112 struct
114 unsigned int initialized:1;
115 unsigned int begun:1;
116 unsigned int done:1;
117 unsigned int armor:1;
118 } flags;
120 int armor_remaining;
121 unsigned char armor_ctx[3];
122 int markeridx,linelen;
123 const char *marker;
124 FILE *stream;
127 size_t curl_writer(const void *ptr,size_t size,size_t nmemb,void *cw_ctx);
128 void curl_writer_finalize(struct curl_writer_ctx *ctx);
130 #endif /* !_KSUTIL_H_ */