Changed default hash algorithm preferences
[gnupg.git] / keyserver / ksutil.h
blob9f51359dfef3df28ca183b6d2b491bca1e443d8b
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 3 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, see <http://www.gnu.org/licenses/>.
19 * In addition, as a special exception, the Free Software Foundation
20 * gives permission to link the code of the keyserver helper tools:
21 * gpgkeys_ldap, gpgkeys_curl and gpgkeys_hkp with the OpenSSL
22 * project's "OpenSSL" library (or with modified versions of it that
23 * use the same license as the "OpenSSL" library), and distribute the
24 * linked executables. You must obey the GNU General Public License
25 * in all respects for all of the code used other than "OpenSSL". If
26 * you modify this file, you may extend this exception to your version
27 * of the file, but you are not obligated to do so. If you do not
28 * wish to do so, delete this exception statement from your version.
31 #ifndef _KSUTIL_H_
32 #define _KSUTIL_H_
34 #ifdef HAVE_LIBCURL
35 #include <curl/curl.h>
36 #else
37 #include "curl-shim.h"
38 #endif
40 /* MAX_LINE must be at least 1 larger than the largest item we expect
41 to receive, including the name tag ("COMMAND", "PORT", etc) and
42 space between. In practice, that means it should be
43 strlen("OPAQUE")+1+sizeof_opaque+1 */
44 #define MAX_LINE (6+1+1024+1)
46 #define MAX_COMMAND 7
47 #define MAX_OPTION 256
48 #define MAX_SCHEME 20
49 #define MAX_OPAQUE 1024
50 #define MAX_AUTH 128
51 #define MAX_HOST 80
52 #define MAX_PORT 10
53 #define URLMAX_PATH 1024
54 #define MAX_PROXY 128
55 #define MAX_URL (MAX_SCHEME+1+3+MAX_AUTH+1+1+MAX_HOST+1+1 \
56 +MAX_PORT+1+1+URLMAX_PATH+1+50)
58 #define STRINGIFY(x) #x
59 #define MKSTRING(x) STRINGIFY(x)
61 #define BEGIN "-----BEGIN PGP PUBLIC KEY BLOCK-----"
62 #define END "-----END PGP PUBLIC KEY BLOCK-----"
64 #ifdef __riscos__
65 #define HTTP_PROXY_ENV "GnuPG$HttpProxy"
66 #else
67 #define HTTP_PROXY_ENV "http_proxy"
68 #endif
70 struct keylist
72 char str[MAX_LINE];
73 struct keylist *next;
76 /* 2 minutes seems reasonable */
77 #define DEFAULT_KEYSERVER_TIMEOUT 120
79 unsigned int set_timeout(unsigned int seconds);
80 int register_timeout(void);
82 #ifdef HAVE_W32_SYSTEM
83 void w32_init_sockets (void);
84 #endif
87 enum ks_action {KS_UNKNOWN=0,KS_GET,KS_GETNAME,KS_SEND,KS_SEARCH};
89 enum ks_search_type {KS_SEARCH_SUBSTR,KS_SEARCH_EXACT,
90 KS_SEARCH_MAIL,KS_SEARCH_MAILSUB,
91 KS_SEARCH_KEYID_LONG,KS_SEARCH_KEYID_SHORT};
93 struct ks_options
95 enum ks_action action;
96 char *host;
97 char *port;
98 char *scheme;
99 char *auth;
100 char *path;
101 char *opaque;
102 struct
104 unsigned int include_disabled:1;
105 unsigned int include_revoked:1;
106 unsigned int include_subkeys:1;
107 unsigned int check_cert:1;
108 } flags;
109 unsigned int verbose;
110 unsigned int debug;
111 unsigned int timeout;
112 char *ca_cert_file;
115 struct ks_options *init_ks_options(void);
116 void free_ks_options(struct ks_options *opt);
117 int parse_ks_options(char *line,struct ks_options *opt);
118 const char *ks_action_to_string(enum ks_action action);
119 void print_nocr(FILE *stream,const char *str);
120 enum ks_search_type classify_ks_search(const char **search);
122 int curl_err_to_gpg_err(CURLcode error);
124 struct curl_writer_ctx
126 struct
128 unsigned int initialized:1;
129 unsigned int begun:1;
130 unsigned int done:1;
131 unsigned int armor:1;
132 } flags;
134 int armor_remaining;
135 unsigned char armor_ctx[3];
136 int markeridx,linelen;
137 const char *marker;
138 FILE *stream;
141 size_t curl_writer(const void *ptr,size_t size,size_t nmemb,void *cw_ctx);
142 void curl_writer_finalize(struct curl_writer_ctx *ctx);
144 int ks_hextobyte (const char *s);
145 int ks_toupper (int c);
146 int ks_strcasecmp (const char *a, const char *b);
149 #endif /* !_KSUTIL_H_ */