3 * Abstract interface to codecs
5 * (c) 2009 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
35 /*----- Header files ------------------------------------------------------*/
41 /*----- Data structures ---------------------------------------------------*/
43 typedef struct codec {
44 const struct codec_ops *ops;
47 typedef struct codec_class {
49 codec *(*encoder)(unsigned /*flags*/,
50 const char */*indent*/, unsigned /*maxline*/);
51 codec *(*decoder)(unsigned /*flags*/);
53 #define CDCF_LOWERC 1u /* Prefer lower case */
54 #define CDCF_IGNCASE 2u /* Ignore case on input */
55 #define CDCF_NOEQPAD 4u /* No `=' padding */
56 #define CDCF_IGNEQPAD 8u /* Ignore `=' pad errors on input */
57 #define CDCF_IGNEQMID 16u /* Ignore pad chars on input */
58 #define CDCF_IGNZPAD 32u /* Ignore zero padding on input */
59 #define CDCF_IGNNEWL 64u /* Ignore newlines on input */
60 #define CDCF_IGNINVCH 128u /* Ignore invalid chars on input */
61 #define CDCF_IGNSPC 256u /* Ignore whitespace on input */
63 #define CDCF_IGNJUNK /* Ignore all bad things */ \
64 (CDCF_IGNEQMID | CDCF_IGNZPAD | \
65 CDCF_IGNCASE | CDCF_IGNNEWL | CDCF_IGNSPC | CDCF_IGNINVCH)
69 #define CODEC_ERRORS(_) \
71 _(INVCH, "Invalid character") \
72 _(INVEQPAD, "Invalid padding character") \
73 _(INVZPAD, "Nonzero padding bits")
75 #define DECLERR(name, text) CDCERR_##name,
81 typedef struct codec_ops {
83 int (*code)(codec */*c*/, const void */*p*/, size_t /*sz*/, dstr */*d*/);
84 void (*destroy)(codec */*c*/);
87 /*----- Functions provided ------------------------------------------------*/
89 /* --- @codec_strerror@ --- *
91 * Arguments: @int err@ = error code from codec
93 * Returns: Pointer to error text.
95 * Use: Converts error codes to human-readable strings.
98 const char *codec_strerror(int /*err*/);
100 /*----- Null codec --------------------------------------------------------*/
102 extern const codec_class null_codec_class;
104 /*----- That's all, folks -------------------------------------------------*/