From: David Levine Date: Wed, 27 Feb 2013 01:23:58 +0000 (-0600) Subject: Added a handful of functions to the parser to allow access to X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/fb5a049491f2f756c8931384103f4ee017e25b49?ds=inline;hp=--cc Added a handful of functions to the parser to allow access to init functions and string representations of enum valus for content types and encodings. --- fb5a049491f2f756c8931384103f4ee017e25b49 diff --git a/h/mhparse.h b/h/mhparse.h index b11f706d..d7bdb344 100644 --- a/h/mhparse.h +++ b/h/mhparse.h @@ -280,5 +280,10 @@ int params_external (CT, int); int open7Bit (CT, char **); void close_encoding (CT); void free_content (CT); +char *ct_type_str (int); +char *ct_subtype_str (int, int); +const struct str2init *get_ct_init (int); +const char *ce_str (int); +const struct str2init *get_ce_method (const char *); extern int checksw; /* Add Content-MD5 field */ diff --git a/uip/mhparse.c b/uip/mhparse.c index 69d2f2c8..87714fdb 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -3004,3 +3004,132 @@ get_leftover_mp_content (CT ct, int before /* or after */) { return OK; } + + +char * +ct_type_str (int type) { + switch (type) { + case CT_APPLICATION: + return "application"; + case CT_AUDIO: + return "audio"; + case CT_IMAGE: + return "image"; + case CT_MESSAGE: + return "message"; + case CT_MULTIPART: + return "multipart"; + case CT_TEXT: + return "text"; + case CT_VIDEO: + return "video"; + case CT_EXTENSION: + return "extension"; + default: + return "unknown_type"; + } +} + + +char * +ct_subtype_str (int type, int subtype) { + switch (type) { + case CT_APPLICATION: + switch (subtype) { + case APPLICATION_OCTETS: + return "octets"; + case APPLICATION_POSTSCRIPT: + return "postscript"; + default: + return "unknown_app_subtype"; + } + case CT_MESSAGE: + switch (subtype) { + case MESSAGE_RFC822: + return "rfc822"; + case MESSAGE_PARTIAL: + return "partial"; + case MESSAGE_EXTERNAL: + return "external"; + default: + return "unknown_msg_subtype"; + } + case CT_MULTIPART: + switch (subtype) { + case MULTI_MIXED: + return "mixed"; + case MULTI_ALTERNATE: + return "alternative"; + case MULTI_DIGEST: + return "digest"; + case MULTI_PARALLEL: + return "parallel"; + default: + return "unknown_multipart_subtype"; + } + case CT_TEXT: + switch (subtype) { + case TEXT_PLAIN: + return "plain"; + case TEXT_RICHTEXT: + return "richtext"; + case TEXT_ENRICHED: + return "enriched"; + default: + return "unknown_text_subtype"; + } + default: + return "unknown_type"; + } +} + + +/* Find the content type and InitFunc for the CT. */ +const struct str2init * +get_ct_init (int type) { + const struct str2init *sp; + + for (sp = str2cts; sp->si_key; ++sp) { + if (type == sp->si_val) { + return sp; + } + } + + return NULL; +} + +const char * +ce_str (int encoding) { + switch (encoding) { + case CE_BASE64: + return "base64"; + case CE_QUOTED: + return "quoted"; + case CE_8BIT: + return "8bit"; + case CE_7BIT: + return "7bit"; + case CE_BINARY: + return "binary"; + case CE_EXTENSION: + return "extension"; + case CE_EXTERNAL: + return "external"; + default: + return "unknown"; + } +} + +/* Find the content type and InitFunc for the content encoding method. */ +const struct str2init * +get_ce_method (const char *method) { + struct str2init *sp; + + for (sp = str2ces; sp->si_key; ++sp) { + if (! strcasecmp (method, sp->si_key)) { + return sp; + } + } + + return NULL; +}