Changeset 126
- Timestamp:
- 05/16/05 16:37:30
- Files:
-
- openpgpsdk/trunk/examples/packet-dump.c (modified) (13 diffs)
- openpgpsdk/trunk/include/packet-to-text.h (moved) (moved from openpgpsdk/trunk/include/packet-decode.h) (3 diffs)
- openpgpsdk/trunk/src/Makefile.template (modified) (1 diff)
- openpgpsdk/trunk/src/packet-to-text.c (moved) (moved from openpgpsdk/trunk/src/packet-decode.c) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/examples/packet-dump.c
r120 r126 3 3 #include "packet.h" 4 4 #include "packet-parse.h" 5 #include "packet- decode.h"5 #include "packet-to-text.h" 6 6 #include "util.h" 7 7 #include <unistd.h> … … 63 63 } 64 64 65 static void print_ decoded(char *label, decoded_t *decoded, int indentlevel)65 static void print_text(char *label, text_t *text, int indentlevel) 66 66 { 67 67 int i=0; … … 75 75 /* these were recognised */ 76 76 77 for(i=0 ; i< decoded->known.used ; i++)77 for(i=0 ; i<text->known.used ; i++) 78 78 { 79 79 indent(indentlevel+1); 80 printf("%s\n", decoded->known.strings[i]);80 printf("%s\n",text->known.strings[i]); 81 81 } 82 82 … … 85 85 */ 86 86 87 if( decoded->unknown.used)87 if(text->unknown.used) 88 88 { 89 89 printf("\n"); … … 91 91 printf("Not Recognised: "); 92 92 } 93 for( i=0; i < decoded->unknown.used; i++)93 for( i=0; i < text->unknown.used; i++) 94 94 { 95 95 indent(indentlevel+2); 96 printf("%s\n", decoded->unknown.strings[i]);96 printf("%s\n",text->unknown.strings[i]); 97 97 } 98 98 … … 154 154 { 155 155 const ops_parser_content_union_t *content=&content_->content; 156 decoded_t * decoded;156 text_t * text; 157 157 char *str; 158 158 … … 325 325 326 326 case OPS_PTAG_SS_PREFERRED_SKA: 327 decoded = decode_ss_preferred_ska(content->ss_preferred_ska);328 print_ decoded("Preferred Symmetric Algorithms",decoded,1);329 decoded_free(decoded);327 text = text_ss_preferred_ska(content->ss_preferred_ska); 328 print_text("Preferred Symmetric Algorithms",text,1); 329 text_free(text); 330 330 331 331 break; … … 338 338 339 339 case OPS_PTAG_SS_PREFERRED_HASH: 340 decoded = decode_ss_preferred_hash(content->ss_preferred_hash);341 print_ decoded("Preferred Hash Algorithms",decoded,1);342 decoded_free(decoded);340 text = text_ss_preferred_hash(content->ss_preferred_hash); 341 print_text("Preferred Hash Algorithms",text,1); 342 text_free(text); 343 343 break; 344 344 345 345 case OPS_PTAG_SS_PREFERRED_COMPRESSION: 346 decoded = decode_ss_preferred_compression(content->ss_preferred_compression);347 print_ decoded("Preferred Compression Algorithms",decoded,1);348 decoded_free(decoded);346 text = text_ss_preferred_compression(content->ss_preferred_compression); 347 print_text("Preferred Compression Algorithms",text,1); 348 text_free(text); 349 349 break; 350 350 … … 355 355 1); 356 356 357 decoded = decode_ss_key_flags(content->ss_key_flags);358 print_ decoded(NULL, decoded, 1);359 decoded_free(decoded);357 text = text_ss_key_flags(content->ss_key_flags); 358 print_text(NULL, text, 1); 359 text_free(text); 360 360 361 361 break; … … 367 367 1); 368 368 369 decoded = decode_ss_key_server_prefs(content->ss_key_server_prefs);370 print_ decoded(NULL, decoded, 1);371 decoded_free(decoded);369 text = text_ss_key_server_prefs(content->ss_key_server_prefs); 370 print_text(NULL, text, 1); 371 text_free(text); 372 372 373 373 break; … … 379 379 1); 380 380 381 decoded = decode_ss_features(content->ss_features);382 print_ decoded(NULL,decoded,1);383 decoded_free(decoded);381 text = text_ss_features(content->ss_features); 382 print_text(NULL,text,1); 383 text_free(text); 384 384 385 385 break; … … 391 391 &content->ss_notation_data.flags, 392 392 2); 393 decoded = decode_ss_notation_data_flags(content->ss_notation_data);394 print_ decoded(NULL,decoded,2);395 decoded_free(decoded);393 text = text_ss_notation_data_flags(content->ss_notation_data); 394 print_text(NULL,text,2); 395 text_free(text); 396 396 397 397 /* xxx - TODO: print out UTF - rachel */ … … 451 451 1, 452 452 1); 453 str = decode_ss_revocation_reason_code(content->ss_revocation_reason.code);453 str = text_ss_revocation_reason_code(content->ss_revocation_reason.code); 454 454 print_string(NULL,str,1); 455 455 /* xxx - todo : output text as UTF-8 string */ openpgpsdk/trunk/include/packet-to-text.h
r123 r126 1 /** \file packet-decode.h 2 * packet decode related headers. 1 /** \file packet-to_text.h 3 2 * 4 3 * $Id$ 5 4 */ 6 5 7 #ifndef OPS_PACKET_ DECODE_H8 #define OPS_PACKET_ DECODE_H6 #ifndef OPS_PACKET_TO_TEXT_H 7 #define OPS_PACKET_TO_TEXT_H 9 8 10 9 #ifndef OPS_PACKET_H … … 23 22 list_t known; 24 23 list_t unknown; 25 } decoded_t;24 } text_t; 26 25 27 26 … … 32 31 } bit_map_t; 33 32 34 void decoded_init(decoded_t * decoded);35 void decoded_free(decoded_t * decoded);33 void text_init(text_t * text); 34 void text_free(text_t * text); 36 35 37 decoded_t * decode_ss_preferred_compression(ops_ss_preferred_compression_t ss_preferred_compression);38 char * decode_single_ss_preferred_compression(unsigned char octet);36 text_t * text_ss_preferred_compression(ops_ss_preferred_compression_t ss_preferred_compression); 37 char * text_single_ss_preferred_compression(unsigned char octet); 39 38 40 decoded_t * decode_ss_preferred_hash(ops_ss_preferred_hash_t ss_preferred_hash);41 char * decode_single_ss_preferred_hash(unsigned char octet);39 text_t * text_ss_preferred_hash(ops_ss_preferred_hash_t ss_preferred_hash); 40 char * text_single_ss_preferred_hash(unsigned char octet); 42 41 43 decoded_t * decode_ss_preferred_ska(ops_ss_preferred_ska_t ss_preferred_ska);44 char * decode_single_ss_preferred_ska(unsigned char octet);42 text_t * text_ss_preferred_ska(ops_ss_preferred_ska_t ss_preferred_ska); 43 char * text_single_ss_preferred_ska(unsigned char octet); 45 44 46 char * decode_ss_revocation_reason_code(unsigned char octet);45 char *text_ss_revocation_reason_code(unsigned char octet); 47 46 48 decoded_t * decode_ss_features(ops_ss_features_t ss_features);49 char * decode_single_ss_feature(unsigned char octet, bit_map_t *map);47 text_t * text_ss_features(ops_ss_features_t ss_features); 48 char * text_single_ss_feature(unsigned char octet, bit_map_t *map); 50 49 51 decoded_t *decode_ss_key_flags(ops_ss_key_flags_t ss_key_flags);52 char * decode_single_ss_key_flag(unsigned char octet, bit_map_t *map);50 text_t *text_ss_key_flags(ops_ss_key_flags_t ss_key_flags); 51 char *text_single_ss_key_flag(unsigned char octet, bit_map_t *map); 53 52 54 decoded_t *decode_ss_key_server_prefs(ops_ss_key_server_prefs_t ss_key_server_prefs);55 char * decode_single_ss_key_server_prefs(unsigned char octet, bit_map_t *map);53 text_t *text_ss_key_server_prefs(ops_ss_key_server_prefs_t ss_key_server_prefs); 54 char *text_single_ss_key_server_prefs(unsigned char octet, bit_map_t *map); 56 55 57 decoded_t *decode_ss_notation_data_flags(ops_ss_notation_data_t ss_notation_data);56 text_t *text_ss_notation_data_flags(ops_ss_notation_data_t ss_notation_data); 58 57 59 58 /* vim:set textwidth=120: */ 60 59 /* vim:set ts=8: */ 61 60 62 #endif /* OPS_PACKET_ DECODE_H */61 #endif /* OPS_PACKET_TO_TEXT_H */ openpgpsdk/trunk/src/Makefile.template
r120 r126 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- decode.o create.o13 packet-to-text.o create.o 14 14 15 15 libops.a: $(LIBOBJS) openpgpsdk/trunk/src/packet-to-text.c
r123 r126 1 /** \file packet- decode.c1 /** \file packet-to_text.c 2 2 * 3 3 * Creates printable text strings from packet contents … … 6 6 */ 7 7 8 #include "packet- decode.h"8 #include "packet-to-text.h" 9 9 10 10 #include <stdlib.h> … … 199 199 200 200 201 unsigned int process_octet_str( decoded_t * decoded, char * str, unsigned char octet)202 { 203 if (str && !add_str(& decoded->known,str))201 unsigned int process_octet_str(text_t * text, char * str, unsigned char octet) 202 { 203 if (str && !add_str(&text->known,str)) 204 204 { 205 205 /* value recognised, but there was a problem adding it to the list */ … … 216 216 Ben? -- rachel */ 217 217 sprintf(str,"0x%x",octet); 218 if (!add_str(& decoded->unknown,str))218 if (!add_str(&text->unknown,str)) 219 219 return 0; 220 220 } … … 222 222 } 223 223 224 unsigned int process_bitmap_str( decoded_t * decoded, char * str, unsigned char bit)225 { 226 if (str && !add_str(& decoded->known,str))224 unsigned int process_bitmap_str(text_t * text, char * str, unsigned char bit) 225 { 226 if (str && !add_str(&text->known,str)) 227 227 { 228 228 /* value recognised, but there was a problem adding it to the list */ … … 239 239 Ben? -- rachel */ 240 240 sprintf(str,"Unknown bit(%d)",bit); 241 if (!add_str(& decoded->unknown,str))241 if (!add_str(&text->unknown,str)) 242 242 return 0; 243 243 } … … 249 249 */ 250 250 251 void decoded_init(decoded_t * decoded)252 { 253 list_init(& decoded->known);254 list_init(& decoded->unknown);255 } 256 257 void decoded_free(decoded_t * decoded)251 void text_init(text_t * text) 252 { 253 list_init(&text->known); 254 list_init(&text->unknown); 255 } 256 257 void text_free(text_t * text) 258 258 { 259 259 /* Strings in "known" array will be constants, so don't free them */ 260 list_free(& decoded->known);260 list_free(&text->known); 261 261 262 262 /* Strings in "unknown" array will be dynamically allocated, so do free them */ 263 list_free_strings(& decoded->unknown);264 list_free(& decoded->unknown);265 266 /* finally, free the decodedstructure itself */267 free( decoded);263 list_free_strings(&text->unknown); 264 list_free(&text->unknown); 265 266 /* finally, free the text structure itself */ 267 free(text); 268 268 } 269 269 … … 272 272 */ 273 273 274 char * decode_ss_revocation_reason_code(unsigned char octet)274 char * text_ss_revocation_reason_code(unsigned char octet) 275 275 { 276 276 return(search_octet_map(octet,revocation_reason_code_map)); 277 277 } 278 278 279 char * decode_single_ss_preferred_compression(unsigned char octet)279 char * text_single_ss_preferred_compression(unsigned char octet) 280 280 { 281 281 return(search_octet_map(octet,compression_algorithm_map)); 282 282 } 283 283 284 decoded_t * decode_ss_preferred_compression(ops_ss_preferred_compression_t array)284 text_t * text_ss_preferred_compression(ops_ss_preferred_compression_t array) 285 285 { 286 286 /* this can be generalised further to handle any similar list -- rachel */ 287 287 288 decoded_t * decoded=NULL;288 text_t * text=NULL; 289 289 char * str; 290 290 int i=0; 291 291 292 decoded=malloc(sizeof(decoded_t));293 if (! decoded)294 return NULL; 295 296 decoded_init(decoded);292 text=malloc(sizeof(text_t)); 293 if (!text) 294 return NULL; 295 296 text_init(text); 297 297 298 298 for ( i=0; i < array.len; i++) 299 299 { 300 str= decode_single_ss_preferred_compression(array.data[i]);301 if (!process_octet_str( decoded,str,array.data[i]))300 str=text_single_ss_preferred_compression(array.data[i]); 301 if (!process_octet_str(text,str,array.data[i])) 302 302 return NULL; 303 303 304 304 } 305 305 /* All values have been added to either the known or the unknown list */ 306 return decoded;307 } 308 309 char * decode_single_ss_preferred_hash(unsigned char octet)306 return text; 307 } 308 309 char * text_single_ss_preferred_hash(unsigned char octet) 310 310 { 311 311 return(search_octet_map(octet,hash_algorithm_map)); 312 312 } 313 313 314 decoded_t * decode_ss_preferred_hash(ops_ss_preferred_hash_t array)314 text_t * text_ss_preferred_hash(ops_ss_preferred_hash_t array) 315 315 { 316 316 /* this can be generalised further to handle any similar list -- rachel */ 317 317 318 decoded_t * decoded=NULL;318 text_t * text=NULL; 319 319 char * str; 320 320 int i=0; 321 321 322 decoded=malloc(sizeof(decoded_t));323 if (! decoded)324 return NULL; 325 326 decoded_init(decoded);322 text=malloc(sizeof(text_t)); 323 if (!text) 324 return NULL; 325 326 text_init(text); 327 327 328 328 for ( i=0; i < array.len; i++) 329 329 { 330 str= decode_single_ss_preferred_hash(array.data[i]);331 if (!process_octet_str( decoded,str,array.data[i]))330 str=text_single_ss_preferred_hash(array.data[i]); 331 if (!process_octet_str(text,str,array.data[i])) 332 332 return NULL; 333 333 334 334 } 335 335 /* All values have been added to either the known or the unknown list */ 336 return decoded;337 } 338 339 char * decode_single_ss_preferred_ska(unsigned char octet)336 return text; 337 } 338 339 char * text_single_ss_preferred_ska(unsigned char octet) 340 340 { 341 341 return(search_octet_map(octet,symmetric_key_algorithm_map)); … … 345 345 * Produce a structure containing human-readable textstrings 346 346 * representing the recognised and unrecognised contents 347 * of this byte array. decode_fn() will be called on each octet in turn.347 * of this byte array. text_fn() will be called on each octet in turn. 348 348 * 349 349 */ 350 350 351 static decoded_t *decode_bytearray(data_t *data,352 char *(* decode_fn)(unsigned char octet))353 { 354 355 decoded_t * decoded=NULL;351 static text_t *text_bytearray(data_t *data, 352 char *(*text_fn)(unsigned char octet)) 353 { 354 355 text_t * text=NULL; 356 356 char * str; 357 357 int i=0; 358 358 359 decoded=malloc(sizeof(decoded_t));360 if (! decoded)361 return NULL; 362 363 decoded_init(decoded);359 text=malloc(sizeof(text_t)); 360 if (!text) 361 return NULL; 362 363 text_init(text); 364 364 365 365 for ( i=0; i < data->len; i++) 366 366 { 367 str=(* decode_fn)(data->contents[i]);368 if (!process_octet_str( decoded,str,data->contents[i]))367 str=(*text_fn)(data->contents[i]); 368 if (!process_octet_str(text,str,data->contents[i])) 369 369 return NULL; 370 370 371 371 } 372 372 /* All values have been added to either the known or the unknown list */ 373 return decoded;374 } 375 376 decoded_t * decode_ss_preferred_ska(ops_ss_preferred_ska_t ss_preferred_ska)377 { 378 return( decode_bytearray(&ss_preferred_ska.data,379 & decode_single_ss_preferred_ska));380 } 381 382 char * decode_single_ss_feature(unsigned char octet, bit_map_t * map)373 return text; 374 } 375 376 text_t * text_ss_preferred_ska(ops_ss_preferred_ska_t ss_preferred_ska) 377 { 378 return(text_bytearray(&ss_preferred_ska.data, 379 &text_single_ss_preferred_ska)); 380 } 381 382 char * text_single_ss_feature(unsigned char octet, bit_map_t * map) 383 383 { 384 384 return(search_bit_map(octet,map)); 385 385 } 386 386 387 /** decoded_t * decode_ss_features(ops_ss_features_t * ss_features)387 /** text_t * text_ss_features(ops_ss_features_t * ss_features) 388 388 */ 389 389 390 decoded_t * decode_ss_features(ops_ss_features_t ss_features)391 { 392 decoded_t *decoded=NULL;390 text_t * text_ss_features(ops_ss_features_t ss_features) 391 { 392 text_t *text=NULL; 393 393 char *str; 394 394 int i=0, j=0; 395 395 unsigned char mask, bit; 396 396 397 decoded=malloc(sizeof(decoded_t));398 if (! decoded)399 return NULL; 400 401 decoded_init(decoded);397 text=malloc(sizeof(text_t)); 398 if (!text) 399 return NULL; 400 401 text_init(text); 402 402 403 403 for ( i=0; i < ss_features.len; i++) … … 408 408 if (bit) 409 409 { 410 str= decode_single_ss_feature ( bit, ss_feature_map[i] );411 if (!process_bitmap_str( decoded, str, bit))410 str=text_single_ss_feature ( bit, ss_feature_map[i] ); 411 if (!process_bitmap_str( text, str, bit)) 412 412 return NULL; 413 413 } 414 414 } 415 415 } 416 return decoded;417 } 418 419 /** char * decode_bit (unsigned char octet, bit_map_t *map)420 */ 421 422 char * decode_bit(unsigned char octet, bit_map_t * map)416 return text; 417 } 418 419 /** char *text_bit (unsigned char octet, bit_map_t *map) 420 */ 421 422 char * text_bit(unsigned char octet, bit_map_t * map) 423 423 { 424 424 return(search_bit_map(octet,map)); 425 425 } 426 426 427 /** decoded_t * decode_map (data_t *data, bit_map_t *map)427 /** text_t * text_map (data_t *data, bit_map_t *map) 428 428 */ 429 429 430 decoded_t * decode_map(data_t *data, bit_map_t **map)431 { 432 decoded_t *decoded=NULL;430 text_t * text_map(data_t *data, bit_map_t **map) 431 { 432 text_t *text=NULL; 433 433 char *str; 434 434 int i=0, j=0; 435 435 unsigned char mask, bit; 436 436 437 decoded=malloc(sizeof(decoded_t));438 if (! decoded)439 return NULL; 440 441 decoded_init(decoded);437 text=malloc(sizeof(text_t)); 438 if (!text) 439 return NULL; 440 441 text_init(text); 442 442 443 443 for ( i=0; i < data->len; i++) … … 448 448 if (bit) 449 449 { 450 str= decode_bit ( bit, map[i] );451 if (!process_bitmap_str( decoded, str, bit))450 str=text_bit ( bit, map[i] ); 451 if (!process_bitmap_str( text, str, bit)) 452 452 return NULL; 453 453 } 454 454 } 455 455 } 456 return decoded;457 } 458 459 decoded_t * decode_ss_notation_data_flags(ops_ss_notation_data_t ss_notation_data)460 { 461 return( decode_map(&ss_notation_data.flags,ss_notation_data_map));462 } 463 464 char * decode_single_ss_key_flag(unsigned char octet, bit_map_t * map)456 return text; 457 } 458 459 text_t * text_ss_notation_data_flags(ops_ss_notation_data_t ss_notation_data) 460 { 461 return(text_map(&ss_notation_data.flags,ss_notation_data_map)); 462 } 463 464 char * text_single_ss_key_flag(unsigned char octet, bit_map_t * map) 465 465 { 466 466 return(search_bit_map(octet,map)); 467 467 } 468 468 469 decoded_t * decode_ss_key_flags(ops_ss_key_flags_t ss_key_flags)470 { 471 decoded_t *decoded=NULL;469 text_t * text_ss_key_flags(ops_ss_key_flags_t ss_key_flags) 470 { 471 text_t *text=NULL; 472 472 char *str; 473 473 int i=0; 474 474 unsigned char mask, bit; 475 475 476 decoded=malloc(sizeof(decoded_t));477 if (! decoded)478 return NULL; 479 480 decoded_init(decoded);476 text=malloc(sizeof(text_t)); 477 if (!text) 478 return NULL; 479 480 text_init(text); 481 481 482 482 /* xxx - TBD: extend to handle multiple octets of bits - rachel */ … … 487 487 if (bit) 488 488 { 489 str= decode_single_ss_key_flag ( bit, &ss_key_flags_map[0] );490 if (!process_bitmap_str( decoded, str, bit))489 str=text_single_ss_key_flag ( bit, &ss_key_flags_map[0] ); 490 if (!process_bitmap_str( text, str, bit)) 491 491 return NULL; 492 492 } 493 493 } 494 494 /* xxx - must add error text if more than one octet. Only one currently specified -- rachel */ 495 return decoded;496 } 497 498 char * decode_single_ss_key_server_prefs(unsigned char octet, bit_map_t *map)495 return text; 496 } 497 498 char *text_single_ss_key_server_prefs(unsigned char octet, bit_map_t *map) 499 499 { 500 500 return(search_bit_map(octet,map)); 501 501 } 502 502 503 decoded_t *decode_ss_key_server_prefs(ops_ss_key_server_prefs_t ss_key_server_prefs)504 { 505 decoded_t *decoded=NULL;503 text_t *text_ss_key_server_prefs(ops_ss_key_server_prefs_t ss_key_server_prefs) 504 { 505 text_t *text=NULL; 506 506 char *str; 507 507 int i=0; 508 508 unsigned char mask, bit; 509 509 510 decoded=malloc(sizeof(decoded_t));511 if (! decoded)512 return NULL; 513 514 decoded_init(decoded);510 text=malloc(sizeof(text_t)); 511 if (!text) 512 return NULL; 513 514 text_init(text); 515 515 516 516 /* xxx - TBD: extend to handle multiple octets of bits - rachel */ … … 521 521 if (bit) 522 522 { 523 str= decode_single_ss_key_server_prefs ( bit, &ss_key_server_prefs_map[0] );524 if (!process_bitmap_str( decoded, str, bit))523 str=text_single_ss_key_server_prefs ( bit, &ss_key_server_prefs_map[0] ); 524 if (!process_bitmap_str( text, str, bit)) 525 525 return NULL; 526 526 } 527 527 } 528 528 /* xxx - must add error text if more than one octet. Only one currently specified -- rachel */ 529 return decoded;529 return text; 530 530 } 531 531
