/* Write a status line with code NO followed by the string TEXT and directly followed by the remaining strings up to a NULL. */ void write_status_strings (int no, const char *text, ...) { va_list arg_ptr; const char *s; if (!statusfp || !status_currently_allowed (no) ) return; /* Not enabled or allowed. */ fputs ("[GNUPG:] ", statusfp); fputs (get_status_string (no), statusfp); if ( text ) { putc ( ' ', statusfp); va_start (arg_ptr, text); s = text; do { for (; *s; s++) { if (*s == '\n') fputs ("\\n", statusfp); else if (*s == '\r') fputs ("\\r", statusfp); else fputc (*(const byte *)s, statusfp); } } while ((s = va_arg (arg_ptr, const char*))); va_end (arg_ptr); } putc ('\n', statusfp); if (fflush (statusfp) && opt.exit_on_status_write_error) g10_exit (0); }
void write_status_text (int no, const char *text) { if (!statusfp || !status_currently_allowed (no) ) return; /* Not enabled or allowed. */ es_fputs ("[GNUPG:] ", statusfp); es_fputs (get_status_string (no), statusfp); if ( text ) { es_putc ( ' ', statusfp); for (; *text; text++) { if (*text == '\n') es_fputs ("\\n", statusfp); else if (*text == '\r') es_fputs ("\\r", statusfp); else es_fputc ( *(const byte *)text, statusfp); } } es_putc ('\n', statusfp); if (es_fflush (statusfp) && opt.exit_on_status_write_error) g10_exit (0); }
void write_status_error (const char *where, int errcode) { if (!statusfp || !status_currently_allowed (STATUS_ERROR)) return; /* Not enabled or allowed. */ fprintf (statusfp, "[GNUPG:] %s %s %u\n", get_status_string (STATUS_ERROR), where, gpg_err_code (errcode)); if (fflush (statusfp) && opt.exit_on_status_write_error) g10_exit (0); }
/* * Write a status line with a buffer using %XX escapes. If WRAP is > * 0 wrap the line after this length. If STRING is not NULL it will * be prepended to the buffer, no escaping is done for string. * A wrap of -1 forces spaces not to be encoded as %20. */ void write_status_text_and_buffer ( int no, const char *string, const char *buffer, size_t len, int wrap ) { const char *s, *text; int esc, first; int lower_limit = ' '; size_t n, count, dowrap; if( !statusfp || !status_currently_allowed (no) ) return; /* Not enabled or allowed. */ if (wrap == -1) { lower_limit--; wrap = 0; } text = get_status_string (no); count = dowrap = first = 1; do { if (dowrap) { fprintf (statusfp, "[GNUPG:] %s ", text ); count = dowrap = 0; if (first && string) { fputs (string, statusfp); count += strlen (string); /* Make sure that there is space after the string. */ if (*string && string[strlen (string)-1] != ' ') { putc (' ', statusfp); count++; } } first = 0; } for (esc=0, s=buffer, n=len; n && !esc; s++, n-- ) { if ( *s == '%' || *(const byte*)s <= lower_limit || *(const byte*)s == 127 ) esc = 1; if ( wrap && ++count > wrap ) { dowrap=1; break; } } if (esc) { s--; n++; } if (s != buffer) fwrite (buffer, s-buffer, 1, statusfp ); if ( esc ) { fprintf (statusfp, "%%%02X", *(const byte*)s ); s++; n--; } buffer = s; len = n; if ( dowrap && len ) putc ( '\n', statusfp ); } while ( len ); putc ('\n',statusfp); if ( fflush (statusfp) && opt.exit_on_status_write_error ) g10_exit (0); }