Changeset 211
- Timestamp:
- 07/14/05 16:12:46
- Files:
-
- openpgpsdk/trunk/examples/packet-dump.c (modified) (2 diffs)
- openpgpsdk/trunk/include/ops_errors.h (added)
- openpgpsdk/trunk/include/packet-show.cast (modified) (1 diff)
- openpgpsdk/trunk/include/packet.h (modified) (4 diffs)
- openpgpsdk/trunk/include/util.h (modified) (1 diff)
- openpgpsdk/trunk/src/Makefile.template (modified) (1 diff)
- openpgpsdk/trunk/src/ops_errors.c (added)
- openpgpsdk/trunk/src/packet-parse.c (modified) (7 diffs)
- openpgpsdk/trunk/src/packet-show.c (modified) (3 diffs)
- openpgpsdk/trunk/src/util.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/examples/packet-dump.c
r209 r211 5 5 #include "util.h" 6 6 #include "lists.h" 7 #include "ops_errors.h" 7 8 8 9 #include <unistd.h> … … 238 239 break; 239 240 241 case OPS_PARSER_ERRCODE: 242 printf("parse error: %s (0x%x): %s\n", 243 ops_errcode(content->errcode.errcode, OPS_LANG_ENGLISH), 244 content->errcode.errcode, 245 ops_error(content->errcode.errcode, OPS_LANG_ENGLISH)); 246 break; 247 240 248 case OPS_PARSER_PACKET_END: 241 249 print_packet(&content->packet); openpgpsdk/trunk/include/packet-show.cast
r172 r211 2 2 // probably not this one! 3 3 4 char *show_packet_tag(ops_packet_tag_t packet_tag, packet_tag_map_t *packet_tag_map) -> char * str_from_map(int packet_tag, map_t *packet_tag_map)5 char *show_sig_type(ops_sig_type_t sig_type, sig_type_map_t *sig_type_map) -> char * str_from_map(int sig_type, map_t *sig_type_map)6 char *show_pka(ops_public_key_algorithm_t pka, public_key_algorithm_map_t *pka_map) -> char * str_from_map(int pka, map_t *pka_map)7 char *show_ss_type(ops_ss_type_t ss_type, ss_type_map_t *ss_type_map) -> char * str_from_map(int ss_type, map_t *ss_type_map)8 char *show_ss_rr_code(ops_ss_rr_code_t ss_rr_code, ss_rr_code_map_t *ss_rr_code_map) -> char * str_from_map(int ss_rr_code, map_t *ss_rr_code_map)9 char *show_hash_algorithm(unsigned char hash,+map_t *hash_algorithm_map) -> char * str_from_map(int hash,map_t *hash_algorithm_map)4 char *show_packet_tag(ops_packet_tag_t packet_tag, packet_tag_map_t *packet_tag_map) -> char *ops_str_from_map(int packet_tag, map_t *packet_tag_map) 5 char *show_sig_type(ops_sig_type_t sig_type, sig_type_map_t *sig_type_map) -> char *ops_str_from_map(int sig_type, map_t *sig_type_map) 6 char *show_pka(ops_public_key_algorithm_t pka, public_key_algorithm_map_t *pka_map) -> char *ops_str_from_map(int pka, map_t *pka_map) 7 char *show_ss_type(ops_ss_type_t ss_type, ss_type_map_t *ss_type_map) -> char *ops_str_from_map(int ss_type, map_t *ss_type_map) 8 char *show_ss_rr_code(ops_ss_rr_code_t ss_rr_code, ss_rr_code_map_t *ss_rr_code_map) -> char *ops_str_from_map(int ss_rr_code, map_t *ss_rr_code_map) 9 char *show_hash_algorithm(unsigned char hash,+map_t *hash_algorithm_map) -> char *ops_str_from_map(int hash,map_t *hash_algorithm_map) openpgpsdk/trunk/include/packet.h
r203 r211 9 9 #include <openssl/bn.h> 10 10 #include "types.h" 11 #include "ops_errors.h" 11 12 12 13 /** General-use structure for variable-length data … … 143 144 OPS_PTAG_SS_ALL =0x103, /*!< Internal Use: select all subtags */ 144 145 OPS_PARSER_PACKET_END =0x104, 146 OPS_PARSER_ERRCODE =0x105, /*! < Internal Use: Parser Error with errcode returned */ 145 147 146 148 /* signature subpackets (0x200-2ff) (type+0x200) */ … … 196 198 const char *error; /*!< error message. */ 197 199 } ops_parser_error_t; 200 201 /** Structure to hold one error code */ 202 typedef struct 203 { 204 ops_errcode_t errcode; 205 } ops_parser_errcode_t; 198 206 199 207 /** Structure to hold one packet tag. … … 660 668 { 661 669 ops_parser_error_t error; 670 ops_parser_errcode_t errcode; 662 671 ops_ptag_t ptag; 663 672 ops_public_key_t public_key; openpgpsdk/trunk/include/util.h
r191 r211 36 36 #define DECONST(type,p) (((type *(*)(const type *))ops_fcast(_deconst))(p)) 37 37 38 char *ops_str_from_map(int code, map_t *map); 39 38 40 #endif openpgpsdk/trunk/src/Makefile.template
r208 r211 11 11 LIBOBJS = packet-parse.o util.o openssl_crypto.o accumulate.o build.o \ 12 12 memory.o fingerprint.o hash.o keyring.o signature.o compress.o \ 13 packet-show.o create.o validate.o lists.o 13 packet-show.o create.o validate.o lists.o ops_errors.o 14 14 15 15 headers: openpgpsdk/trunk/src/packet-parse.c
r210 r211 9 9 #include "compress.h" 10 10 #include "lists.h" 11 #include "ops_errors.h" 11 12 12 13 #include <assert.h> … … 107 108 /*! macro to run CallBack function specifying a parser error has occurred */ 108 109 #define E CB(OPS_PARSER_ERROR,&content); return 0 109 /*! set error code in content and run CallBack to handle error, then return */ 110 /*! set error code in content and run CallBack to handle error */ 111 #define ERRCODE(err) do { C.errcode.errcode=err; CB(OPS_PARSER_ERRCODE,&content); } while(0) 112 /*! set error text in content and run CallBack to handle error, then return */ 110 113 #define ERR(err) do { C.error.error=err; E; } while(0) 111 /*! set error codein content and run CallBack to handle warning, do not return */114 /*! set error text in content and run CallBack to handle warning, do not return */ 112 115 #define WARN(warn) do { C.error.error=warn; CB(OPS_PARSER_ERROR,&content);; } while(0) 113 116 /*! \todo descr ERR1 macro */ … … 130 133 content->content.error.error=buf; 131 134 } 135 136 /** 137 * low-level function to read data from reader function 138 * 139 * Use this function, rather than calling the reader directly. 140 * 141 * If the accumulate flag is set in *opt, the function 142 * adds the read data to the accumulated data, and updates 143 * the accumulated length. This is useful if, for example, 144 * the application wants access to the raw data as well as the 145 * parsed data. 146 * 147 * \param *dest 148 * \param *plength 149 * \param flags 150 * \param *opt 151 * 152 * \return OPS_R_OK 153 * \return OPS_R_PARTIAL_READ 154 * \return OPS_R_EOF 155 * \return OPS_R_EARLY_EOF 156 * 157 * \sa #opt_reader_ret_t, ops_reader_fd() for details of return codes 158 */ 132 159 133 160 static ops_reader_ret_t base_read(unsigned char *dest,unsigned *plength, … … 165 192 * \param *reader Our reader 166 193 * \param length How many bytes to read 167 * \return OPS_PR_OK on success, reader's return value otherwise 168 * 194 * \return OPS_R_OK on success, reader's return value otherwise 195 * 196 * \sa #ops_reader_ret_t for possible return codes 169 197 */ 170 198 static ops_reader_ret_t read_scalar(unsigned *result,unsigned length, … … 214 242 215 243 if(!region->indeterminate && region->length_read+length > region->length) 216 ERR("Not enough data left"); 244 { 245 ERRCODE(OPS_E_P_NOT_ENOUGH_DATA); 246 return 0; 247 } 217 248 218 249 ret=base_read(dest,&length,region->indeterminate ? OPS_RETURN_LENGTH : 0, … … 220 251 221 252 if(ret != OPS_R_OK && ret != OPS_R_PARTIAL_READ) 222 ERR("Read failed"); 253 { 254 ERRCODE(OPS_E_R_READ_FAILED); 255 return 0; 256 } 223 257 224 258 region->last_read=length; … … 614 648 615 649 case OPS_PARSER_ERROR: 650 case OPS_PARSER_ERRCODE: 616 651 break; 617 652 openpgpsdk/trunk/src/packet-show.c
r178 r211 265 265 } 266 266 267 /**268 * Searches the given map for the given type.269 * Returns a human-readable descriptive string if found,270 * returns NULL if not found271 *272 * It is the responsibility of the calling function to handle the273 * error case sensibly (i.e. don't just print out the return string.274 *275 */276 static char *str_from_map_or_null(int type, map_t *map)277 {278 map_t *row;279 280 for ( row=map; row->string != NULL; row++ )281 if (row->type == type)282 return row->string;283 return NULL;284 }285 286 /**287 * Searches the given map for the given type.288 * Returns a readable string if found, "Unknown" if not.289 */290 291 char *str_from_map(int type, map_t *map)292 {293 char *str;294 str=str_from_map_or_null(type,map);295 if (str)296 return(str);297 else298 return("Unknown");299 }300 301 267 static char *str_from_bitfield_or_null(unsigned char octet, bit_map_t *map) 302 268 { … … 547 513 char *ops_show_ss_preferred_compression(unsigned char octet) 548 514 { 549 return( str_from_map(octet,compression_algorithm_map));515 return(ops_str_from_map(octet,compression_algorithm_map)); 550 516 } 551 517 … … 604 570 char *ops_show_ss_preferred_ska(unsigned char octet) 605 571 { 606 return( str_from_map(octet,symmetric_key_algorithm_map));572 return(ops_str_from_map(octet,symmetric_key_algorithm_map)); 607 573 } 608 574 openpgpsdk/trunk/src/util.c
r183 r211 9 9 #include <assert.h> 10 10 #include <unistd.h> 11 12 /** 13 * Searches the given map for the given type. 14 * Returns a human-readable descriptive string if found, 15 * returns NULL if not found 16 * 17 * It is the responsibility of the calling function to handle the 18 * error case sensibly (i.e. don't just print out the return string. 19 * 20 */ 21 static char *str_from_map_or_null(int type, map_t *map) 22 { 23 map_t *row; 24 25 for ( row=map; row->string != NULL; row++ ) 26 if (row->type == type) 27 return row->string; 28 return NULL; 29 } 30 31 /** 32 * \ingroup Utils 33 * 34 * Searches the given map for the given type. 35 * Returns a readable string if found, "Unknown" if not. 36 */ 37 38 char *ops_str_from_map(int type, map_t *map) 39 { 40 char *str; 41 str=str_from_map_or_null(type,map); 42 if (str) 43 return(str); 44 else 45 return("Unknown"); 46 } 11 47 12 48 void hexdump(const unsigned char *src,size_t length) … … 46 82 * descriptor in "arg_" into the buffer starting at "dest" using the 47 83 * rules contained in "flags" 48 * 84 * 49 85 * \param dest Pointer to previously allocated buffer 50 86 * \param plength Number of bytes to try to read … … 56 92 * \return OPS_R_EARLY_EOF if not enough bytes were read, and OPS_RETURN_LENGTH was not set in "flags" 57 93 * \return OPS_R_OK if expected length was read 94 * 95 * \sa enum opt_reader_ret_t 96 * 58 97 * \todo change arg_ to typesafe? 59 98 */
