- 5B4ADEDB0DDA25D37413FD81037EF2D94722CEE3B58B5A5314DA3816308540588319A280819E272845D154B6F2FDBDCECE3A73C15B2802F33BC6BFE484F0B4A5
+ 60F97FC937B6974E1AD4AA0D6728491D71127244D9FF43369612222359802A7816F57FE6060354582782A04CE62B6568BABAC0A0BF886FD6D8CBE3A17F540BCA
mpi/include/util.h
(1 . 22)(1 . 25)
994 /* util.h
995 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
996 * 2006 Free Software Foundation, Inc.
997 * Modified by No Such Labs. (C) 2015. See README.
998 *
999 * This file is part of GNUPG.
1000 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
1001 * SHA256(gnupg-1.4.10.tar.gz):
1002 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
1003 * (C) 1994-2005 Free Software Foundation, Inc.
1004 *
1005 * GNUPG is free software; you can redistribute it and/or modify
1006 * This program is free software: you can redistribute it and/or modify
1007 * it under the terms of the GNU General Public License as published by
1008 * the Free Software Foundation; either version 3 of the License, or
1009 * the Free Software Foundation, either version 3 of the License, or
1010 * (at your option) any later version.
1011 *
1012 * GNUPG is distributed in the hope that it will be useful,
1013 * This program is distributed in the hope that it will be useful,
1014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1016 * GNU General Public License for more details.
1017 *
1018 * You should have received a copy of the GNU General Public License
1019 * along with this program; if not, see <http://www.gnu.org/licenses/>.
1020 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1021 */
1022
1023 #ifndef G10_UTIL_H
1024 #define G10_UTIL_H
1025
(25 . 244)(28 . 25)
1027 #endif
1028
1029 #include "types.h"
1030 #include "errors.h"
1031 #include "types.h"
1032 #include "mpi.h"
1033 #include "compat.h"
1034
1035 typedef struct {
1036 int *argc; /* pointer to argc (value subject to change) */
1037 char ***argv; /* pointer to argv (value subject to change) */
1038 unsigned flags; /* Global flags (DO NOT CHANGE) */
1039 int err; /* print error about last option */
1040 /* 1 = warning, 2 = abort */
1041 int r_opt; /* return option */
1042 int r_type; /* type of return value (0 = no argument found)*/
1043 union {
1044 int ret_int;
1045 long ret_long;
1046 ulong ret_ulong;
1047 char *ret_str;
1048 } r; /* Return values */
1049 struct {
1050 int idx;
1051 int inarg;
1052 int stopped;
1053 const char *last;
1054 void *aliases;
1055 const void *cur_alias;
1056 } internal; /* DO NOT CHANGE */
1057 } ARGPARSE_ARGS;
1058
1059 typedef struct {
1060 int short_opt;
1061 const char *long_opt;
1062 unsigned flags;
1063 const char *description; /* optional option description */
1064 } ARGPARSE_OPTS;
1065
1066 /*-- logger.c --*/
1067 void log_set_logfile( const char *name, int fd );
1068 FILE *log_stream(void);
1069 void g10_log_print_prefix(const char *text);
1070 void log_set_name( const char *name );
1071 const char *log_get_name(void);
1072 void log_set_pid( int pid );
1073 int log_get_errorcount( int clear );
1074 void log_inc_errorcount(void);
1075 int log_set_strict(int val);
1076 void g10_log_hexdump( const char *text, const char *buf, size_t len );
1077
1078 #if defined (__riscos__) \
1079 || (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ))
1080 void g10_log_bug( const char *fmt, ... )
1081 __attribute__ ((noreturn, format (printf,1,2)));
1082 void g10_log_bug0( const char *, int, const char * ) __attribute__ ((noreturn));
1083 void g10_log_fatal( const char *fmt, ... )
1084 __attribute__ ((noreturn, format (printf,1,2)));
1085 void g10_log_error( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
1086 void g10_log_info( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
1087 void g10_log_warning( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
1088 void g10_log_debug( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
1089 #ifndef __riscos__
1090 #define BUG() g10_log_bug0( __FILE__ , __LINE__, __FUNCTION__ )
1091 #else
1092 #define BUG() g10_log_bug0( __FILE__ , __LINE__, __func__ )
1093 #endif
1094 #else
1095 void g10_log_bug( const char *fmt, ... );
1096 void g10_log_bug0( const char *, int );
1097 void g10_log_fatal( const char *fmt, ... );
1098 void g10_log_error( const char *fmt, ... );
1099 void g10_log_info( const char *fmt, ... );
1100 void g10_log_warning( const char *fmt, ... );
1101 void g10_log_debug( const char *fmt, ... );
1102 #define BUG() g10_log_bug0( __FILE__ , __LINE__ )
1103 #endif
1104 #define log_hexdump printf
1105 #define log_bug printf
1106 #define log_bug0 printf
1107 #define log_fatal printf
1108 #define log_error printf
1109 #define log_info printf
1110 #define log_warning printf
1111 #define log_debug printf
1112
1113 #define g10_log_print_prefix printf
1114
1115 #define log_hexdump g10_log_hexdump
1116 #define log_bug g10_log_bug
1117 #define log_bug0 g10_log_bug0
1118 #define log_fatal g10_log_fatal
1119 #define log_error g10_log_error
1120 #define log_info g10_log_info
1121 #define log_warning g10_log_warning
1122 #define log_debug g10_log_debug
1123
1124
1125 /*-- errors.c --*/
1126 const char * g10_errstr( int no );
1127
1128 /*-- argparse.c --*/
1129 int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
1130 int optfile_parse( FILE *fp, const char *filename, unsigned *lineno,
1131 ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
1132 void usage( int level );
1133 const char *default_strusage( int level );
1134
1135
1136 /*-- (main program) --*/
1137 const char *strusage( int level );
1138
1139
1140 /*-- dotlock.c --*/
1141 struct dotlock_handle;
1142 typedef struct dotlock_handle *DOTLOCK;
1143
1144 void disable_dotlock(void);
1145 DOTLOCK create_dotlock( const char *file_to_lock );
1146 void destroy_dotlock ( DOTLOCK h );
1147 int make_dotlock( DOTLOCK h, long timeout );
1148 int release_dotlock( DOTLOCK h );
1149 void remove_lockfiles (void);
1150
1151 /*-- fileutil.c --*/
1152 char * make_basename(const char *filepath, const char *inputpath);
1153 char * make_dirname(const char *filepath);
1154 char *make_filename( const char *first_part, ... );
1155 int compare_filenames( const char *a, const char *b );
1156 int same_file_p (const char *name1, const char *name2);
1157 const char *print_fname_stdin( const char *s );
1158 const char *print_fname_stdout( const char *s );
1159 int is_file_compressed(const char *s, int *r_status);
1160
1161 /*-- miscutil.c --*/
1162 u32 make_timestamp(void);
1163 u32 scan_isodatestr( const char *string );
1164 u32 isotime2seconds (const char *string);
1165 const char *strtimevalue( u32 stamp );
1166 const char *strtimestamp( u32 stamp ); /* GMT */
1167 const char *isotimestamp( u32 stamp ); /* GMT with hh:mm:ss */
1168 const char *asctimestamp( u32 stamp ); /* localized */
1169 void print_string( FILE *fp, const byte *p, size_t n, int delim );
1170 void print_string2( FILE *fp, const byte *p, size_t n, int delim, int delim2 );
1171 void print_utf8_string( FILE *fp, const byte *p, size_t n );
1172 void print_utf8_string2( FILE *fp, const byte *p, size_t n, int delim);
1173 char *make_printable_string( const byte *p, size_t n, int delim );
1174 int answer_is_yes_no_default( const char *s, int def_answer );
1175 int answer_is_yes( const char *s );
1176 int answer_is_yes_no_quit( const char *s );
1177 int answer_is_okay_cancel (const char *s, int def_answer);
1178 int match_multistr(const char *multistr,const char *match);
1179
1180 /*-- strgutil.c --*/
1181 void free_strlist( STRLIST sl );
1182 #define FREE_STRLIST(a) do { free_strlist((a)); (a) = NULL ; } while(0)
1183 STRLIST add_to_strlist( STRLIST *list, const char *string );
1184 STRLIST add_to_strlist2( STRLIST *list, const char *string, int is_utf8 );
1185 STRLIST append_to_strlist( STRLIST *list, const char *string );
1186 STRLIST append_to_strlist2( STRLIST *list, const char *string, int is_utf8 );
1187 STRLIST strlist_prev( STRLIST head, STRLIST node );
1188 STRLIST strlist_last( STRLIST node );
1189 char *pop_strlist( STRLIST *list );
1190 const char *memistr( const char *buf, size_t buflen, const char *sub );
1191 const char *ascii_memistr( const char *buf, size_t buflen, const char *sub );
1192 char *mem2str( char *, const void *, size_t);
1193 char *trim_spaces( char *string );
1194 unsigned int trim_trailing_chars( byte *line, unsigned int len,
1195 const char *trimchars);
1196 unsigned int trim_trailing_ws( byte *line, unsigned len );
1197 unsigned int check_trailing_chars( const byte *line, unsigned int len,
1198 const char *trimchars );
1199 unsigned int check_trailing_ws( const byte *line, unsigned int len );
1200 int string_count_chr( const char *string, int c );
1201 int set_native_charset( const char *newset );
1202 const char* get_native_charset(void);
1203 char *native_to_utf8( const char *string );
1204 char *utf8_to_native( const char *string, size_t length, int delim);
1205 char *string_to_utf8 (const char *string);
1206
1207 int ascii_isupper (int c);
1208 int ascii_islower (int c);
1209 int ascii_memcasecmp( const char *a, const char *b, size_t n);
1210
1211 #ifndef HAVE_STPCPY
1212 char *stpcpy(char *a,const char *b);
1213 #endif
1214 #ifndef HAVE_STRLWR
1215 char *strlwr(char *a);
1216 #endif
1217 #ifndef HAVE_STRCASECMP
1218 int strcasecmp( const char *, const char *b);
1219 #endif
1220 #ifndef HAVE_STRNCASECMP
1221 int strncasecmp (const char *, const char *b, size_t n);
1222 #endif
1223 #ifndef HAVE_STRTOUL
1224 #define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
1225 #endif
1226 #ifndef HAVE_MEMMOVE
1227 #define memmove(d, s, n) bcopy((s), (d), (n))
1228 #endif
1229
1230 /*-- membuf.c --*/
1231 /* The definition of the structure is private, we only need it here,
1232 so it can be allocated on the stack. */
1233 struct private_membuf_s {
1234 size_t len;
1235 size_t size;
1236 char *buf;
1237 int out_of_core;
1238 };
1239
1240 typedef struct private_membuf_s membuf_t;
1241
1242 void init_membuf (membuf_t *mb, int initiallen);
1243 void put_membuf (membuf_t *mb, const void *buf, size_t len);
1244 void *get_membuf (membuf_t *mb, size_t *len);
1245
1246
1247
1248 #if defined (_WIN32)
1249 /*-- w32reg.c --*/
1250 char *read_w32_registry_string( const char *root,
1251 const char *dir, const char *name );
1252 int write_w32_registry_string(const char *root, const char *dir,
1253 const char *name, const char *value);
1254
1255 #endif /*_WIN32*/
1256
1257 /*-- strgutil.c --*/
1258 char *xasprintf (const char *fmt, ...);
1259 char *xtryasprintf (const char *fmt, ...);
1260
1261
1262 /*-- pka.c --*/
1263 char *get_pka_info (const char *address, unsigned char *fpr);
1264
1265 /*-- cert.c --*/
1266 int get_cert(const char *name,size_t max_size,IOBUF *iobuf,
1267 unsigned char **fpr,size_t *fpr_len,char **url);
1268
1269 /*-- convert.c --*/
1270 int hex2bin (const char *string, void *buffer, size_t length);
1271 int hexcolon2bin (const char *string, void *buffer, size_t length);
1272 char *bin2hex (const void *buffer, size_t length, char *stringbuf);
1273 char *bin2hexcolon (const void *buffer, size_t length, char *stringbuf);
1274 const char *hex2str (const char *hexstring,
1275 char *buffer, size_t bufsize, size_t *buflen);
1276 char *hex2str_alloc (const char *hexstring, size_t *r_count);
1277
1278
1279 /**** other missing stuff ****/
1280 #ifndef HAVE_ATEXIT /* For SunOS */
(273 . 10)(57 . 6)
1282 #define raise(a) kill(getpid(), (a))
1283 #endif
1284
1285 /*-- Replacement functions from funcname.c --*/
1286
1287
1288
1289 /******** some macros ************/
1290 #ifndef STR
1291 #define STR(v) #v
(302 . 33)(82 . 5)
1293 *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
1294 #define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
1295
1296 /******* RISC OS stuff ***********/
1297 #ifdef __riscos__
1298 int riscos_load_module(const char *name, const char * const path[], int fatal);
1299 int riscos_get_filetype_from_string(const char *string, int len);
1300 int riscos_get_filetype(const char *filename);
1301 void riscos_set_filetype_by_number(const char *filename, int type);
1302 void riscos_set_filetype_by_mimetype(const char *filename, const char *mimetype);
1303 pid_t riscos_getpid(void);
1304 int riscos_kill(pid_t pid, int sig);
1305 int riscos_access(const char *path, int amode);
1306 int riscos_getchar(void);
1307 char *riscos_make_basename(const char *filepath, const char *inputpath);
1308 int riscos_check_regexp(const char *exp, const char *string, int debug);
1309 int riscos_fdopenfile(const char *filename, const int allow_write);
1310 void riscos_close_fds(void);
1311 int riscos_renamefile(const char *old, const char *new);
1312 char *riscos_gstrans(const char *old);
1313 void riscos_not_implemented(const char *feature);
1314 #ifdef DEBUG
1315 void riscos_dump_fdlist(void);
1316 void riscos_list_openfiles(void);
1317 #endif
1318 #ifndef __RISCOS__C__
1319 #define getpid riscos_getpid
1320 #define kill(a,b) riscos_kill((a),(b))
1321 #define access(a,b) riscos_access((a),(b))
1322 #endif /* !__RISCOS__C__ */
1323 #endif /* __riscos__ */
1324
1325 #endif /*G10_UTIL_H*/