Home | History | Annotate | Line # | Download | only in global
      1 /*	$NetBSD: quote_flags.c,v 1.2 2020/03/18 19:05:16 christos Exp $	*/
      2 
      3 /*++
      4 /* NAME
      5 /*	quote_flags 3
      6 /* SUMMARY
      7 /*	quote rfc 821/822 local part
      8 /* SYNOPSIS
      9 /*	#include <quote_flags.h>
     10 /*
     11 /*	int	quote_flags_from_string(const char *string)
     12 /*
     13 /*	const char *quote_flags_to_string(VSTRING *res_buf, int mask)
     14 /* DESCRIPTION
     15 /*	quote_flags_from_string() converts symbolic flag names into
     16 /*	the corresponding internal bitmask. This logs a warning and
     17 /*	returns zero if an unknown symbolic name is specified.
     18 /*
     19 /*	quote_flags_to_string() converts from internal bitmask to
     20 /*	the corresponding symbolic names. This logs a warning and
     21 /*	returns a null pointer if an unknown bitmask is specified.
     22 /*
     23 /*	Arguments:
     24 /* .IP string
     25 /*	Symbolic representation of a quote_flags bitmask, for
     26 /*	example: \fB8bitclean | bare_localpart\fR. The conversion
     27 /*	is case-insensitive.
     28 /* .IP res_buf
     29 /*	Storage for the quote_flags_to_string() result, which has
     30 /*	the same form as the string argument. If a null pointer is
     31 /*	specified, quote_flags_to_string() uses storage that is
     32 /*	overwritten with each call.
     33 /* .IP mask
     34 /*	Binary representation of quote_flags.
     35 /* DIAGNOSTICS
     36 /*	Fatal error: out of memory; or unknown bitmask name or value.
     37 /* LICENSE
     38 /* .ad
     39 /* .fi
     40 /*	The Secure Mailer license must be distributed with this software.
     41 /* AUTHOR(S)
     42 /*	Wietse Venema
     43 /*	Google, Inc.
     44 /*	111 8th Avenue
     45 /*	New York, NY 10011, USA
     46 /*--*/
     47 
     48  /*
     49   * System library.
     50   */
     51 #include <sys_defs.h>
     52 
     53  /*
     54   * Utility library.
     55   */
     56 #include <name_mask.h>
     57 
     58  /*
     59   * Global library.
     60   */
     61 #include <quote_flags.h>
     62 
     63 static const NAME_MASK quote_flags_table[] = {
     64     "8bitclean", QUOTE_FLAG_8BITCLEAN,
     65     "expose_at", QUOTE_FLAG_EXPOSE_AT,
     66     "append", QUOTE_FLAG_APPEND,
     67     "bare_localpart", QUOTE_FLAG_BARE_LOCALPART,
     68     0,
     69 };
     70 
     71 /* quote_flags_from_string - symbolic quote flags to internal form */
     72 
     73 int     quote_flags_from_string(const char *quote_flags_string)
     74 {
     75     return (name_mask_delim_opt("quote_flags_from_string", quote_flags_table,
     76 				quote_flags_string, "|",
     77 				NAME_MASK_WARN | NAME_MASK_ANY_CASE));
     78 }
     79 
     80 /* quote_flags_to_string - internal form to symbolic quote flags */
     81 
     82 const char *quote_flags_to_string(VSTRING *res_buf, int quote_flags_mask)
     83 {
     84     static VSTRING *my_buf;
     85 
     86     if (res_buf == 0 && (res_buf = my_buf) == 0)
     87 	res_buf = my_buf = vstring_alloc(20);
     88     return (str_name_mask_opt(res_buf, "quote_flags_to_string",
     89 			      quote_flags_table, quote_flags_mask,
     90 			      NAME_MASK_WARN | NAME_MASK_PIPE));
     91 }
     92