diff options
author | Werner Koch <[email protected]> | 2000-07-14 17:34:53 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2000-07-14 17:34:53 +0000 |
commit | 92cd25550836198cf1e3a6aac239eef98364359d (patch) | |
tree | 4fad355126fae79c93535e0e7c6afd91e384552a /util | |
parent | See ChangeLog: Thu May 25 18:39:11 CEST 2000 Werner Koch (diff) | |
download | gnupg-92cd25550836198cf1e3a6aac239eef98364359d.tar.gz gnupg-92cd25550836198cf1e3a6aac239eef98364359d.zip |
See ChangeLog: Fri Jul 14 19:38:23 CEST 2000 Werner Koch
Diffstat (limited to 'util')
-rw-r--r-- | util/ChangeLog | 25 | ||||
-rw-r--r-- | util/Makefile.am | 2 | ||||
-rw-r--r-- | util/http.c | 42 | ||||
-rw-r--r-- | util/iobuf.c | 42 | ||||
-rw-r--r-- | util/logger.c | 8 | ||||
-rw-r--r-- | util/miscutil.c | 4 | ||||
-rw-r--r-- | util/simple-gettext.c | 22 | ||||
-rw-r--r-- | util/strgutil.c | 2 | ||||
-rw-r--r-- | util/ttyio.c | 30 |
9 files changed, 141 insertions, 36 deletions
diff --git a/util/ChangeLog b/util/ChangeLog index b42bc37e5..d1eba0291 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,28 @@ +Fri Jul 14 19:38:23 CEST 2000 Werner Koch <wk@> + + * iobuf.c (iobuf_cancel): Broadcast the new Cancel message to all + filters. Fix for MSDOS. + + * miscutil.c (asctimestamp): Fix for possible buffer overflow by + a large system returned date format string. + + * logger.c (log_inc_errorcount): New. + + * w32reg.c: New. + + * simple-gettext.c: Use the Registry to locate the mo file. + + * http.c (send_request): Add support for proxys; suggested by + Walter Hofmann. + (http_open_document): Pass flags to http_open. + + * ttyio.c (do_get): Replaced #if __MINGW32__ by #ifdef because + gcc 2.95.1 assigns a floating point value (0.2) to this macro, + which in turn can't be used in an expression. + * ttyio.c: Simulate termios with termios. By Dave Dykstra. + * ttyio.c (tty_print_utf8_string): Oops. + * ttyio.c (tty_print_utf8_string2): New to allow a max output size. + Thu Jan 27 18:00:44 CET 2000 Werner Koch <[email protected]> * Changed all "g10_"/"GPG_" prefixes to "gpg_"/"GPG_". diff --git a/util/Makefile.am b/util/Makefile.am index 7668de61e..6247f1f2e 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -8,7 +8,7 @@ noinst_LTLIBRARIES = libutil.la libutil_la_LDFLAGS = libutil_la_SOURCES = logger.c fileutil.c miscutil.c strgutil.c \ ttyio.c errors.c iobuf.c \ - http.c simple-gettext.c + http.c simple-gettext.c w32reg.c http-test: http.c diff --git a/util/http.c b/util/http.c index 173c17116..81bf91ded 100644 --- a/util/http.c +++ b/util/http.c @@ -1,5 +1,5 @@ /* http.c - HTTP protocol handler - * Copyright (C) 1999 Free Software Foundation, Inc. + * Copyright (C) 1999, 2000 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -26,7 +26,7 @@ #include <ctype.h> #include <errno.h> -#ifndef HAVE_DOSISH_SYSTEM +#ifndef HAVE_DOSISH_SYSTEM /* fixme: add support W32 sockets */ #include <unistd.h> #include <sys/types.h> @@ -76,7 +76,7 @@ http_open( HTTP_HD hd, HTTP_REQ_TYPE reqtype, const char *url, { int rc; - if( flags || !(reqtype == HTTP_REQ_GET || reqtype == HTTP_REQ_POST) ) + if( !(reqtype == HTTP_REQ_GET || reqtype == HTTP_REQ_POST) ) return GPGERR_INV_ARG; /* initialize the handle */ @@ -84,6 +84,7 @@ http_open( HTTP_HD hd, HTTP_REQ_TYPE reqtype, const char *url, hd->sock = -1; hd->initialized = 1; hd->req_type = reqtype; + hd->flags = flags; rc = parse_uri( &hd->uri, url ); if( !rc ) { @@ -150,10 +151,7 @@ http_open_document( HTTP_HD hd, const char *document, unsigned int flags ) { int rc; - if( flags ) - return GPGERR_INV_ARG; - - rc = http_open( hd, HTTP_REQ_GET, document, 0 ); + rc = http_open( hd, HTTP_REQ_GET, document, flags ); if( rc ) return rc; @@ -429,21 +427,47 @@ send_request( HTTP_HD hd ) byte *request, *p; ushort port; int rc; + const char *http_proxy = NULL; server = *hd->uri->host? hd->uri->host : "localhost"; port = hd->uri->port? hd->uri->port : 80; - hd->sock = connect_server( server, port ); + if( (hd->flags & HTTP_FLAG_TRY_PROXY) + && (http_proxy = getenv( "http_proxy" )) ) { + PARSED_URI uri; + + rc = parse_uri( &uri, http_proxy ); + if (rc) { + log_error("invalid $http_proxy: %s\n", gpg_errstr(rc)); + release_parsed_uri( uri ); + return GPGERR_NETWORK; + } + hd->sock = connect_server( *uri->host? uri->host : "localhost", + uri->port? uri->port : 80 ); + release_parsed_uri( uri ); + } + else + hd->sock = connect_server( server, port ); + if( hd->sock == -1 ) return GPGERR_NETWORK; p = build_rel_path( hd->uri ); request = gcry_xmalloc( strlen(p) + 20 ); - sprintf( request, "%s %s%s HTTP/1.0\r\n", + if( http_proxy ) { + sprintf( request, "%s http://%s:%hu%s%s HTTP/1.0\r\n", + hd->req_type == HTTP_REQ_GET ? "GET" : + hd->req_type == HTTP_REQ_HEAD? "HEAD": + hd->req_type == HTTP_REQ_POST? "POST": "OOPS", + server, port, *p == '/'? "":"/", p ); + } + else { + sprintf( request, "%s %s%s HTTP/1.0\r\n", hd->req_type == HTTP_REQ_GET ? "GET" : hd->req_type == HTTP_REQ_HEAD? "HEAD": hd->req_type == HTTP_REQ_POST? "POST": "OOPS", *p == '/'? "":"/", p ); + } gcry_free(p); rc = write_server( hd->sock, request, strlen(request) ); diff --git a/util/iobuf.c b/util/iobuf.c index ec5cfefbd..d4900f416 100644 --- a/util/iobuf.c +++ b/util/iobuf.c @@ -1,5 +1,5 @@ /* iobuf.c - file handling - * Copyright (C) 1998, 1999 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -81,6 +81,8 @@ static int underflow(IOBUF a); * IOBUFCTRL_FLUSH: called by iobuf_flush() to write out the collected stuff. * *RET_LAN is the number of bytes in BUF. * + * IOBUFCTRL_CANCEL: send to all filters on behalf of iobuf_cancel. The + * filter may take appropriate action on this message. */ static int file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) @@ -494,19 +496,47 @@ iobuf_close( IOBUF a ) return rc; } + int iobuf_cancel( IOBUF a ) { const char *s; + IOBUF a2; + int rc; + #ifdef HAVE_DOSISH_SYSTEM + char *remove_name = NULL; + #endif if( a && a->use == 2 ) { s = iobuf_get_real_fname(a); - if( s && *s ) - remove(s); /* remove the file. Fixme: this will fail for MSDOZE*/ - } /* because the file is still open */ - return iobuf_close(a); -} + if( s && *s ) { + #ifdef HAVE_DOSISH_SYSTEM + remove_name = m_strdup ( s ); + #else + remove(s); + #endif + } + } + + /* send a cancel message to all filters */ + for( a2 = a; a2 ; a2 = a2->chain ) { + size_t dummy; + if( a2->filter ) + a2->filter( a2->filter_ov, IOBUFCTRL_CANCEL, a2->chain, + NULL, &dummy ); + } + rc = iobuf_close(a); + #ifdef HAVE_DOSISH_SYSTEM + if ( remove_name ) { + /* Argg, MSDOS does not allow to remove open files. So + * we have to do it here */ + remove ( remove_name ); + m_free ( remove_name ); + } + #endif + return rc; +} /**************** * create a temporary iobuf, which can be used to collect stuff diff --git a/util/logger.c b/util/logger.c index 83cba8c22..bb0b89e8b 100644 --- a/util/logger.c +++ b/util/logger.c @@ -1,5 +1,5 @@ /* logger.c - log functions - * Copyright (C) 1998 Free Software Foundation, Inc. + * Copyright (C) 1998, 2000 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -102,6 +102,12 @@ log_get_errorcount( int clear) return n; } +void +log_inc_errorcount() +{ + errorcount++; +} + void gpg_log_print_prefix(const char *text) diff --git a/util/miscutil.c b/util/miscutil.c index 2cf0db0e2..c1b8fa076 100644 --- a/util/miscutil.c +++ b/util/miscutil.c @@ -1,5 +1,5 @@ /* miscutil.c - miscellaneous utilities - * Copyright (C) 1998, 1999 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -148,7 +148,7 @@ asctimestamp( u32 stamp ) tp = localtime( &atime ); #ifdef HAVE_STRFTIME #if defined(HAVE_NL_LANGINFO) - mem2str( fmt, nl_langinfo(D_T_FMT), DIM(fmt) ); + mem2str( fmt, nl_langinfo(D_T_FMT), DIM(fmt)-3 ); if( strstr( fmt, "%Z" ) == NULL ) strcat( fmt, " %Z"); strftime( buffer, DIM(buffer)-1, fmt, tp ); diff --git a/util/simple-gettext.c b/util/simple-gettext.c index a128aff3c..80dbbfe0e 100644 --- a/util/simple-gettext.c +++ b/util/simple-gettext.c @@ -217,13 +217,6 @@ load_domain( const char *filename ) free( domain ); return NULL; } - /* Currently we have only a Latin-1 to IBM850 translation, so - * we simply mark everything mapped if we don't have this codepage. */ - { - const char *s = get_native_charset(); - if( !s || strcmp(s, "ibm850") - memset( domain->mapped, 1, domain->nstrings ); - } return domain; } @@ -251,16 +244,19 @@ set_gettext_file( const char *filename ) /* absolute path - use it as is */ domain = load_domain( filename ); } - else { /* relative path - append ".mo" and get DIR from env */ + else { /* relative path - append ".mo" and get DIR from the Registry */ char *buf = NULL; - const char *s; + char *dir; - s = getenv("MINGW32_NLS_DIR"); - if( s && (buf=malloc(strlen(s)+strlen(filename)+1+3+1)) ) { - strcpy(stpcpy(stpcpy(stpcpy( buf, s),"/"), filename),".mo"); + dir = read_w32_registry_string( NULL, + "Control Panel\\Mingw32\\NLS", + "MODir" ); + if( dir && (buf=malloc(strlen(dir)+strlen(filename)+1+3+1)) ) { + strcpy(stpcpy(stpcpy(stpcpy( buf, dir),"/"), filename),".mo"); domain = load_domain( buf ); free(buf); } + free(dir); } if( !domain ) return -1; @@ -286,7 +282,7 @@ get_string( struct loaded_domain *domain, u32 idx ) byte *pp; domain->mapped[idx] = 1; - /* currently we only support Latin-1 to CP 850 */ + /* we assume Latin1 -> CP 850 for now */ for( pp=p; *pp; pp++ ) { if( (*pp & 0x80) ) { switch( *pp ) { diff --git a/util/strgutil.c b/util/strgutil.c index ea3ddc29c..a8abf7ba8 100644 --- a/util/strgutil.c +++ b/util/strgutil.c @@ -1,5 +1,5 @@ /* strgutil.c - string utilities - * Copyright (C) 1998 Free Software Foundation, Inc. + * Copyright (C) 1998, 2000 Free Software Foundation, Inc. * * This file is part of GnuPG. * diff --git a/util/ttyio.c b/util/ttyio.c index 527d64832..6aaff000c 100644 --- a/util/ttyio.c +++ b/util/ttyio.c @@ -1,5 +1,5 @@ /* ttyio.c - tty i/O functions - * Copyright (C) 1998 Free Software Foundation, Inc. + * Copyright (C) 1998, 2000 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -26,6 +26,16 @@ #include <unistd.h> #ifdef HAVE_TCGETATTR #include <termios.h> +#else + #ifdef HAVE_TERMIO_H + /* simulate termios with termio */ + #include <termio.h> + #define termios termio + #define tcsetattr ioctl + #define TCSAFLUSH TCSETAF + #define tcgetattr(A,B) ioctl(A,TCGETA,B) + #define HAVE_TCGETATTR + #endif #endif #ifdef __MINGW32__ /* use the odd Win32 functions */ #include <windows.h> @@ -237,7 +247,7 @@ tty_print_string( byte *p, size_t n ) } void -tty_print_utf8_string( byte *p, size_t n ) +tty_print_utf8_string2( byte *p, size_t n, size_t max_n ) { size_t i; char *buf; @@ -252,14 +262,28 @@ tty_print_utf8_string( byte *p, size_t n ) } if( i < n ) { buf = utf8_to_native( p, n ); + if( strlen( buf ) > max_n ) { + buf[max_n] = 0; + } + /*(utf8 conversion already does the control character quoting)*/ tty_printf("%s", buf ); gcry_free( buf ); } - else + else { + if( n > max_n ) { + n = max_n; + } tty_print_string( p, n ); + } } +void +tty_print_utf8_string( byte *p, size_t n ) +{ + tty_print_utf8_string2( p, n, n ); +} + |