From 398354b6f0c5e8311496481c2b80c1eb4bec4424 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 20 Oct 2009 00:24:44 +0000 Subject: update C API for error retrieval git-svn-id: svn+q:///qpdf/trunk@830 71b93d88-0707-0410-a8cf-f5a4172ac649 --- include/qpdf/QPDF.hh | 4 ++-- include/qpdf/QPDFExc.hh | 6 +++--- include/qpdf/qpdf-c.h | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 35 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh index 178d71c7..3f66a5f9 100644 --- a/include/qpdf/QPDF.hh +++ b/include/qpdf/QPDF.hh @@ -70,7 +70,7 @@ class DLL_EXPORT QPDF // throws an exception. Note that if setSuppressWarnings was not // called or was called with a false value, any warnings retrieved // here will have already been issued to stderr. - std::vector getWarnings(); + std::vector getWarnings(); std::string getFilename() const; std::string getPDFVersion() const; @@ -761,7 +761,7 @@ class DLL_EXPORT QPDF std::map obj_cache; QPDFObjectHandle trailer; std::vector all_pages; - std::vector warnings; + std::vector warnings; // Linearization data int first_xref_item_offset; // actual value from file diff --git a/include/qpdf/QPDFExc.hh b/include/qpdf/QPDFExc.hh index 6b9a11e4..7d6d8968 100644 --- a/include/qpdf/QPDFExc.hh +++ b/include/qpdf/QPDFExc.hh @@ -11,7 +11,7 @@ #include #include #include -#include +#include class DLL_EXPORT QPDFExc: public std::runtime_error { @@ -36,8 +36,8 @@ class DLL_EXPORT QPDFExc: public std::runtime_error qpdf_error_code_e getErrorCode() const; std::string const& getFilename() const; std::string const& getObject() const; - off_t getOffset() const; - std::string const& getMessage() const; + off_t getFilePosition() const; + std::string const& getMessageDetail() const; private: static std::string createWhat(std::string const& filename, diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h index 90b3e5f9..ef4c4c6b 100644 --- a/include/qpdf/qpdf-c.h +++ b/include/qpdf/qpdf-c.h @@ -63,12 +63,14 @@ #include #include +#include #ifdef __cplusplus extern "C" { #endif typedef struct _qpdf_data* qpdf_data; + typedef struct _qpdf_error* qpdf_error; /* Many functions return an integer error code. Codes are defined * below. See comments at the top of the file for details. Note @@ -97,21 +99,42 @@ extern "C" { /* ERROR REPORTING */ - /* Returns 1 if there are any errors or warnings, and zero - * otherwise. + /* Returns the error condition, if any. The return value is a + * pointer to data that will become invalid the next time an error + * occurs or after this function is called gain. */ DLL_EXPORT - QPDF_BOOL qpdf_more_errors(qpdf_data qpdf); + qpdf_error qpdf_get_error(qpdf_data qpdf); + + /* Returns 1 if there are any unretrieved warnings, and zero + * otherwise. + */ DLL_EXPORT QPDF_BOOL qpdf_more_warnings(qpdf_data qpdf); - /* If there are any errors/warnings, returns a pointer to the next - * error or warning. Otherwise returns a null pointer. + /* If there are any warnings, returns a pointer to the next + * warning. Otherwise returns a null pointer. */ DLL_EXPORT - char const* qpdf_next_error(qpdf_data qpdf); + qpdf_error qpdf_next_warning(qpdf_data qpdf); + + /* Extract fields of the error. */ + + /* Use this function to get a full error message suitable for + * showing to the user. */ + DLL_EXPORT + char const* qpdf_get_error_full_text(qpdf_data q, qpdf_error e); + + /* Use these functions to extract individual fields from the + * error; see QPDFExc.hh for details. */ + DLL_EXPORT + enum qpdf_error_code_e qpdf_get_error_code(qpdf_data q, qpdf_error e); + DLL_EXPORT + char const* qpdf_get_error_filename(qpdf_data q, qpdf_error e); + DLL_EXPORT + off_t qpdf_get_error_file_position(qpdf_data q, qpdf_error e); DLL_EXPORT - char const* qpdf_next_warning(qpdf_data qpdf); + char const* qpdf_get_error_message_detail(qpdf_data q, qpdf_error e); /* By default, warnings are written to stderr. Passing true to * this function will prevent warnings from being written to -- cgit v1.2.3-70-g09d2