#include <fcntl.h>
#include <h/signals.h>
#include <h/md5.h>
-#include <errno.h>
-#include <signal.h>
#include <h/mts.h>
#include <h/tws.h>
#include <h/mime.h>
* static prototypes
*/
static CT get_content (FILE *, char *, int);
-static int get_comment (CT, char **, int);
+static int get_comment (const char *, CI, char **, int);
static int InitGeneric (CT);
static int InitText (CT);
hp = ct->c_first_hf; /* start at first header field */
while (hp) {
/* Get MIME-Version field */
- if (!mh_strcasecmp (hp->name, VRSN_FIELD)) {
+ if (!strcasecmp (hp->name, VRSN_FIELD)) {
int ucmp;
char c, *cp, *dp;
if (debugsw)
fprintf (stderr, "%s: %s\n", VRSN_FIELD, cp);
- if (*cp == '(' && get_comment (ct, &cp, 0) == NOTOK)
+ if (*cp == '(' &&
+ get_comment (ct->c_file, &ct->c_ctinfo, &cp, 0) == NOTOK)
goto out;
for (dp = cp; istoken (*dp); dp++)
continue;
c = *dp;
*dp = '\0';
- ucmp = !mh_strcasecmp (cp, VRSN_VALUE);
+ ucmp = !strcasecmp (cp, VRSN_VALUE);
*dp = c;
if (!ucmp) {
admonish (NULL, "message %s has unknown value for %s: field (%s)",
ct->c_file, VRSN_FIELD, cp);
}
}
- else if (!mh_strcasecmp (hp->name, TYPE_FIELD)) {
+ else if (!strcasecmp (hp->name, TYPE_FIELD)) {
/* Get Content-Type field */
struct str2init *s2i;
CI ci = &ct->c_ctinfo;
* flag for this content type.
*/
for (s2i = str2cts; s2i->si_key; s2i++)
- if (!mh_strcasecmp (ci->ci_type, s2i->si_key))
+ if (!strcasecmp (ci->ci_type, s2i->si_key))
break;
if (!s2i->si_key && !uprf (ci->ci_type, "X-"))
s2i++;
ct->c_type = s2i->si_val;
ct->c_ctinitfnx = s2i->si_init;
}
- else if (!mh_strcasecmp (hp->name, ENCODING_FIELD)) {
+ else if (!strcasecmp (hp->name, ENCODING_FIELD)) {
/* Get Content-Transfer-Encoding field */
char c, *cp, *dp;
struct str2init *s2i;
* for this transfer encoding.
*/
for (s2i = str2ces; s2i->si_key; s2i++)
- if (!mh_strcasecmp (cp, s2i->si_key))
+ if (!strcasecmp (cp, s2i->si_key))
break;
if (!s2i->si_key && !uprf (cp, "X-"))
s2i++;
if (s2i->si_init && (*s2i->si_init) (ct) == NOTOK)
goto out;
}
- else if (!mh_strcasecmp (hp->name, MD5_FIELD)) {
+ else if (!strcasecmp (hp->name, MD5_FIELD)) {
/* Get Content-MD5 field */
char *cp, *dp, *ep;
if (debugsw)
fprintf (stderr, "%s: %s\n", MD5_FIELD, cp);
- if (*cp == '(' && get_comment (ct, &cp, 0) == NOTOK) {
+ if (*cp == '(' &&
+ get_comment (ct->c_file, &ct->c_ctinfo, &cp, 0) == NOTOK) {
free (ep);
goto out;
}
free (ep);
ct->c_digested++;
}
- else if (!mh_strcasecmp (hp->name, ID_FIELD)) {
+ else if (!strcasecmp (hp->name, ID_FIELD)) {
/* Get Content-ID field */
ct->c_id = add (hp->value, ct->c_id);
}
- else if (!mh_strcasecmp (hp->name, DESCR_FIELD)) {
+ else if (!strcasecmp (hp->name, DESCR_FIELD)) {
/* Get Content-Description field */
ct->c_descr = add (hp->value, ct->c_descr);
}
- else if (!mh_strcasecmp (hp->name, DISPO_FIELD)) {
+ else if (!strcasecmp (hp->name, DISPO_FIELD)) {
/* Get Content-Disposition field */
ct->c_dispo = add (hp->value, ct->c_dispo);
}
get_ctinfo (char *cp, CT ct, int magic)
{
int i;
- char *dp, **ap, **ep;
+ char *dp;
char c;
CI ci;
+ int status;
ci = &ct->c_ctinfo;
i = strlen (invo_name) + 2;
if (debugsw)
fprintf (stderr, "%s: %s\n", TYPE_FIELD, cp);
- if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
+ if (*cp == '(' && get_comment (ct->c_file, &ct->c_ctinfo, &cp, 1) == NOTOK)
return NOTOK;
for (dp = cp; istoken (*dp); dp++)
while (isspace ((unsigned char) *cp))
cp++;
- if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
+ if (*cp == '(' && get_comment (ct->c_file, &ct->c_ctinfo, &cp, 1) == NOTOK)
return NOTOK;
if (*cp != '/') {
while (isspace ((unsigned char) *cp))
cp++;
- if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
+ if (*cp == '(' && get_comment (ct->c_file, &ct->c_ctinfo, &cp, 1) == NOTOK)
return NOTOK;
for (dp = cp; istoken (*dp); dp++)
while (isspace ((unsigned char) *cp))
cp++;
- if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
+ if (*cp == '(' && get_comment (ct->c_file, &ct->c_ctinfo, &cp, 1) == NOTOK)
return NOTOK;
- /*
- * Parse attribute/value pairs given with Content-Type
- */
- ep = (ap = ci->ci_attrs) + NPARMS;
- while (*cp == ';') {
- char *vp, *up;
-
- if (ap >= ep) {
- advise (NULL,
- "too many parameters in message %s's %s: field (%d max)",
- ct->c_file, TYPE_FIELD, NPARMS);
- return NOTOK;
- }
-
- cp++;
- while (isspace ((unsigned char) *cp))
- cp++;
-
- if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
- return NOTOK;
-
- if (*cp == 0) {
- advise (NULL,
- "extraneous trailing ';' in message %s's %s: parameter list",
- ct->c_file, TYPE_FIELD);
- return OK;
- }
-
- /* down case the attribute name */
- for (dp = cp; istoken ((unsigned char) *dp); dp++)
- if (isalpha((unsigned char) *dp) && isupper ((unsigned char) *dp))
- *dp = tolower ((unsigned char) *dp);
-
- for (up = dp; isspace ((unsigned char) *dp);)
- dp++;
- if (dp == cp || *dp != '=') {
- advise (NULL,
- "invalid parameter in message %s's %s: field\n%*.*sparameter %s (error detected at offset %d)",
- ct->c_file, TYPE_FIELD, i, i, "", cp, dp - cp);
- return NOTOK;
- }
-
- vp = (*ap = add (cp, NULL)) + (up - cp);
- *vp = '\0';
- for (dp++; isspace ((unsigned char) *dp);)
- dp++;
-
- /* now add the attribute value */
- ci->ci_values[ap - ci->ci_attrs] = vp = *ap + (dp - cp);
-
- if (*dp == '"') {
- for (cp = ++dp, dp = vp;;) {
- switch (c = *cp++) {
- case '\0':
-bad_quote:
- advise (NULL,
- "invalid quoted-string in message %s's %s: field\n%*.*s(parameter %s)",
- ct->c_file, TYPE_FIELD, i, i, "", *ap);
- return NOTOK;
-
- case '\\':
- *dp++ = c;
- if ((c = *cp++) == '\0')
- goto bad_quote;
- /* else fall... */
-
- default:
- *dp++ = c;
- continue;
-
- case '"':
- *dp = '\0';
- break;
- }
- break;
- }
- } else {
- for (cp = dp, dp = vp; istoken (*cp); cp++, dp++)
- continue;
- *dp = '\0';
- }
- if (!*vp) {
- advise (NULL,
- "invalid parameter in message %s's %s: field\n%*.*s(parameter %s)",
- ct->c_file, TYPE_FIELD, i, i, "", *ap);
- return NOTOK;
- }
- ap++;
-
- while (isspace ((unsigned char) *cp))
- cp++;
-
- if (*cp == '(' && get_comment (ct, &cp, 1) == NOTOK)
- return NOTOK;
+ if (parse_header_attrs (ct->c_file, i, &cp, ci, &status) == NOTOK) {
+ return status;
}
/*
static int
-get_comment (CT ct, char **ap, int istype)
+get_comment (const char *filename, CI ci, char **ap, int istype)
{
int i;
char *bp, *cp;
char c, buffer[BUFSIZ], *dp;
- CI ci;
- ci = &ct->c_ctinfo;
cp = *ap;
bp = buffer;
cp++;
case '\0':
invalid:
advise (NULL, "invalid comment in message %s's %s: field",
- ct->c_file, istype ? TYPE_FIELD : VRSN_FIELD);
+ filename, istype ? TYPE_FIELD : VRSN_FIELD);
return NOTOK;
case '\\':
/* match subtype */
for (kv = SubText; kv->kv_key; kv++)
- if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key))
+ if (!strcasecmp (ci->ci_subtype, kv->kv_key))
break;
ct->c_subtype = kv->kv_value;
/* scan for charset parameter */
for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++)
- if (!mh_strcasecmp (*ap, "charset"))
+ if (!strcasecmp (*ap, "charset"))
break;
/* check if content specified a character set */
/* match subtype */
for (kv = SubMultiPart; kv->kv_key; kv++)
- if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key))
+ if (!strcasecmp (ci->ci_subtype, kv->kv_key))
break;
ct->c_subtype = kv->kv_value;
*/
bp = 0;
for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
- if (!mh_strcasecmp (*ap, "boundary")) {
+ if (!strcasecmp (*ap, "boundary")) {
bp = *ep;
break;
}
/* match subtype */
for (kv = SubMessage; kv->kv_key; kv++)
- if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key))
+ if (!strcasecmp (ci->ci_subtype, kv->kv_key))
break;
ct->c_subtype = kv->kv_value;
/* scan for parameters "id", "number", and "total" */
for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
- if (!mh_strcasecmp (*ap, "id")) {
+ if (!strcasecmp (*ap, "id")) {
p->pm_partid = add (*ep, NULL);
continue;
}
- if (!mh_strcasecmp (*ap, "number")) {
+ if (!strcasecmp (*ap, "number")) {
if (sscanf (*ep, "%d", &p->pm_partno) != 1
|| p->pm_partno < 1) {
invalid_param:
}
continue;
}
- if (!mh_strcasecmp (*ap, "total")) {
+ if (!strcasecmp (*ap, "total")) {
if (sscanf (*ep, "%d", &p->pm_maxno) != 1
|| p->pm_maxno < 1)
goto invalid_param;
ct->c_ceopenfnx = NULL;
for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
- if (!mh_strcasecmp (*ap, "access-type")) {
+ if (!strcasecmp (*ap, "access-type")) {
struct str2init *s2i;
CT p = e->eb_content;
for (s2i = str2methods; s2i->si_key; s2i++)
- if (!mh_strcasecmp (*ep, s2i->si_key))
+ if (!strcasecmp (*ep, s2i->si_key))
break;
if (!s2i->si_key) {
e->eb_access = *ep;
return NOTOK;
continue;
}
- if (!mh_strcasecmp (*ap, "name")) {
+ if (!strcasecmp (*ap, "name")) {
e->eb_name = *ep;
continue;
}
- if (!mh_strcasecmp (*ap, "permission")) {
+ if (!strcasecmp (*ap, "permission")) {
e->eb_permission = *ep;
continue;
}
- if (!mh_strcasecmp (*ap, "site")) {
+ if (!strcasecmp (*ap, "site")) {
e->eb_site = *ep;
continue;
}
- if (!mh_strcasecmp (*ap, "directory")) {
+ if (!strcasecmp (*ap, "directory")) {
e->eb_dir = *ep;
continue;
}
- if (!mh_strcasecmp (*ap, "mode")) {
+ if (!strcasecmp (*ap, "mode")) {
e->eb_mode = *ep;
continue;
}
- if (!mh_strcasecmp (*ap, "size")) {
+ if (!strcasecmp (*ap, "size")) {
sscanf (*ep, "%lu", &e->eb_size);
continue;
}
- if (!mh_strcasecmp (*ap, "server")) {
+ if (!strcasecmp (*ap, "server")) {
e->eb_server = *ep;
continue;
}
- if (!mh_strcasecmp (*ap, "subject")) {
+ if (!strcasecmp (*ap, "subject")) {
e->eb_subject = *ep;
continue;
}
- if (!mh_strcasecmp (*ap, "url")) {
+ if (!strcasecmp (*ap, "url")) {
/*
* According to RFC 2017, we have to remove all whitespace from
* the URL
*u = '\0';
continue;
}
- if (composing && !mh_strcasecmp (*ap, "body")) {
+ if (composing && !strcasecmp (*ap, "body")) {
e->eb_body = getcpy (*ep);
continue;
}
/* match subtype */
for (kv = SubApplication; kv->kv_key; kv++)
- if (!mh_strcasecmp (ci->ci_subtype, kv->kv_key))
+ if (!strcasecmp (ci->ci_subtype, kv->kv_key))
break;
ct->c_subtype = kv->kv_value;
return NOTOK;
}
- if ((!e->eb_permission || mh_strcasecmp (e->eb_permission, "read-write"))
+ if ((!e->eb_permission || strcasecmp (e->eb_permission, "read-write"))
&& find_cache (NULL, wcachesw, &cachetype, e->eb_content->c_id,
cachefile, sizeof(cachefile)) != NOTOK) {
int mask;
ce->ce_unlink = (*file == NULL);
caching = 0;
cachefile[0] = '\0';
- if ((!e->eb_permission || mh_strcasecmp (e->eb_permission, "read-write"))
+ if ((!e->eb_permission || strcasecmp (e->eb_permission, "read-write"))
&& find_cache (NULL, wcachesw, &cachetype, e->eb_content->c_id,
cachefile, sizeof(cachefile)) != NOTOK) {
if (*file == NULL) {
vec[vecp++] = e->eb_dir;
vec[vecp++] = e->eb_name;
vec[vecp++] = ce->ce_file,
- vec[vecp++] = e->eb_mode && !mh_strcasecmp (e->eb_mode, "ascii")
+ vec[vecp++] = e->eb_mode && !strcasecmp (e->eb_mode, "ascii")
? "ascii" : "binary";
vec[vecp] = NULL;
case CE_BASE64:
return "base64";
case CE_QUOTED:
- return "quoted";
+ return "quoted-printable";
case CE_8BIT:
return "8bit";
case CE_7BIT:
return NULL;
}
+
+int
+parse_header_attrs (const char *filename, int len, char **header_attrp, CI ci,
+ int *status) {
+ char **attr = ci->ci_attrs;
+ char *cp = *header_attrp;
+
+ while (*cp == ';') {
+ char *dp, *vp, *up, c;
+
+ /* Relies on knowledge of this declaration:
+ * char *ci_attrs[NPARMS + 2];
+ */
+ if (attr >= ci->ci_attrs + sizeof ci->ci_attrs/sizeof (char *) - 2) {
+ advise (NULL,
+ "too many parameters in message %s's %s: field (%d max)",
+ filename, TYPE_FIELD, NPARMS);
+ *status = NOTOK;
+ return NOTOK;
+ }
+
+ cp++;
+ while (isspace ((unsigned char) *cp))
+ cp++;
+
+ if (*cp == '(' &&
+ get_comment (filename, ci, &cp, 1) == NOTOK) {
+ *status = NOTOK;
+ return NOTOK;
+ }
+
+ if (*cp == 0) {
+ advise (NULL,
+ "extraneous trailing ';' in message %s's %s: "
+ "parameter list",
+ filename, TYPE_FIELD);
+ *status = OK;
+ return NOTOK;
+ }
+
+ /* down case the attribute name */
+ for (dp = cp; istoken ((unsigned char) *dp); dp++)
+ if (isalpha((unsigned char) *dp) && isupper ((unsigned char) *dp))
+ *dp = tolower ((unsigned char) *dp);
+
+ for (up = dp; isspace ((unsigned char) *dp);)
+ dp++;
+ if (dp == cp || *dp != '=') {
+ advise (NULL,
+ "invalid parameter in message %s's %s: "
+ "field\n%*.*sparameter %s (error detected at offset %d)",
+ filename, TYPE_FIELD, len, len, "", cp, dp - cp);
+ *status = NOTOK;
+ return NOTOK;
+ }
+
+ vp = (*attr = add (cp, NULL)) + (up - cp);
+ *vp = '\0';
+ for (dp++; isspace ((unsigned char) *dp);)
+ dp++;
+
+ /* Now store the attribute value. */
+ ci->ci_values[attr - ci->ci_attrs] = vp = *attr + (dp - cp);
+
+ if (*dp == '"') {
+ for (cp = ++dp, dp = vp;;) {
+ switch (c = *cp++) {
+ case '\0':
+bad_quote:
+ advise (NULL,
+ "invalid quoted-string in message %s's %s: "
+ "field\n%*.*s(parameter %s)",
+ filename, TYPE_FIELD, len, len, "", *attr);
+ *status = NOTOK;
+ return NOTOK;
+
+ case '\\':
+ *dp++ = c;
+ if ((c = *cp++) == '\0')
+ goto bad_quote;
+ /* else fall... */
+
+ default:
+ *dp++ = c;
+ continue;
+
+ case '"':
+ *dp = '\0';
+ break;
+ }
+ break;
+ }
+ } else {
+ for (cp = dp, dp = vp; istoken (*cp); cp++, dp++)
+ continue;
+ *dp = '\0';
+ }
+ if (!*vp) {
+ advise (NULL,
+ "invalid parameter in message %s's %s: "
+ "field\n%*.*s(parameter %s)",
+ filename, TYPE_FIELD, len, len, "", *attr);
+ *status = NOTOK;
+ return NOTOK;
+ }
+
+ while (isspace ((unsigned char) *cp))
+ cp++;
+
+ if (*cp == '(' &&
+ get_comment (filename, ci, &cp, 1) == NOTOK) {
+ *status = NOTOK;
+ return NOTOK;
+ }
+
+ ++attr;
+ }
+
+ *header_attrp = cp;
+ return OK;
+}