diff options
author | Werner Koch <[email protected]> | 2007-11-19 16:03:50 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2007-11-19 16:03:50 +0000 |
commit | 55ba204bfa848c2e591a29fedc9f103103493a57 (patch) | |
tree | e37263e4d3a25e2aa300faf4c5240191b54ea1a7 /jnlib | |
parent | Updated (diff) | |
download | gnupg-55ba204bfa848c2e591a29fedc9f103103493a57.tar.gz gnupg-55ba204bfa848c2e591a29fedc9f103103493a57.zip |
Started to implement the audit log feature.
Pass PINENTRY_USER_DATA and XAUTHORITY to Pinentry.
Improved support for the quality bar.
Minor internal restructuring.
Translation fixes.
Diffstat (limited to 'jnlib')
-rw-r--r-- | jnlib/ChangeLog | 6 | ||||
-rw-r--r-- | jnlib/stringhelp.c | 31 | ||||
-rw-r--r-- | jnlib/stringhelp.h | 5 |
3 files changed, 37 insertions, 5 deletions
diff --git a/jnlib/ChangeLog b/jnlib/ChangeLog index 452a99b3f..0dc15daae 100644 --- a/jnlib/ChangeLog +++ b/jnlib/ChangeLog @@ -1,3 +1,9 @@ +2007-11-19 Werner Koch <[email protected]> + + * stringhelp.c (percent_escape): Factor code out to + (do_percent_escape): .. new. + (try_percent_escape): New. + 2007-10-01 Werner Koch <[email protected]> * w32-afunix.c: Only keep the client related code. diff --git a/jnlib/stringhelp.c b/jnlib/stringhelp.c index 2f5204341..028750528 100644 --- a/jnlib/stringhelp.c +++ b/jnlib/stringhelp.c @@ -856,9 +856,9 @@ memrchr (const void *buffer, int c, size_t n) /* Percent-escape the string STR by replacing colons with '%3a'. If - EXTRA is not NULL all characters in it are also escaped. */ -char * -percent_escape (const char *str, const char *extra) + EXTRA is not NULL all characters in EXTRA are also escaped. */ +static char * +do_percent_escape (const char *str, const char *extra, int die) { int i, j; char *ptr; @@ -869,7 +869,14 @@ percent_escape (const char *str, const char *extra) for (i=j=0; str[i]; i++) if (str[i] == ':' || str[i] == '%' || (extra && strchr (extra, str[i]))) j++; - ptr = jnlib_xmalloc (i + 2 * j + 1); + if (die) + ptr = jnlib_xmalloc (i + 2 * j + 1); + else + { + ptr = jnlib_malloc (i + 2 * j + 1); + if (!ptr) + return NULL; + } i = 0; while (*str) { @@ -899,3 +906,19 @@ percent_escape (const char *str, const char *extra) return ptr; } + +/* Percent-escape the string STR by replacing colons with '%3a'. If + EXTRA is not NULL all characters in EXTRA are also escaped. */ +char * +percent_escape (const char *str, const char *extra) +{ + return do_percent_escape (str, extra, 1); +} + +/* Same as percent_escape but return NULL instead of exiting on memory + error. */ +char * +try_percent_escape (const char *str, const char *extra) +{ + return do_percent_escape (str, extra, 0); +} diff --git a/jnlib/stringhelp.h b/jnlib/stringhelp.h index 6dee2e417..cb7051933 100644 --- a/jnlib/stringhelp.h +++ b/jnlib/stringhelp.h @@ -116,8 +116,11 @@ isascii (int c) #define STR2(v) STR(v) /* Percent-escape the string STR by replacing colons with '%3a'. If - EXTRA is not NULL, also replace all characters given in EXTRA. */ + EXTRA is not NULL, also replace all characters given in EXTRA. The + "try_" variant fails with NULL if not enough memory can be + allocated. */ char *percent_escape (const char *str, const char *extra); +char *try_percent_escape (const char *str, const char *extra); #endif /*LIBJNLIB_STRINGHELP_H*/ |