/***********************************************************************
* *
* This software is part of the BSD package *
*Copyright (c) 1978-2011 The Regents of the University of California an*
* *
* Redistribution and use in source and binary forms, with or *
* without modification, are permitted provided that the following *
* conditions are met: *
* *
* 1. Redistributions of source code must retain the above *
* copyright notice, this list of conditions and the *
* following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above *
* copyright notice, this list of conditions and the *
* materials provided with the distribution. *
* *
* 3. Neither the name of The Regents of the University of California*
* names of its contributors may be used to endorse or *
* promote products derived from this software without *
* specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS *
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED *
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON *
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* 1. Redistributions of source code must retain the above copyright *
* notice, this list of conditions and the following disclaimer. *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in *
* distribution. *
* 3. Neither the name of the University nor the names of its *
* contributors may be used to endorse or promote products derived *
* from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" *
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF *
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT *
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
* SUCH DAMAGE. *
* *
* Kurt Shoens (UCB) *
* gsf *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
*/
#if __OBSOLETE__ < 19990101
#endif
#include "mimelib.h"
#if __OBSOLETE__ < 19990101
#endif
typedef struct Att_s
{
char* name;
char* value;
} Att_t;
typedef struct Cap_s
{
unsigned long flags;
char* test;
} Cap_t;
typedef struct
{
} Ent_t;
typedef struct
{
char* data;
int size;
} String_t;
typedef struct
{
char* next;
} Parse_t;
typedef struct
{
const char* pattern;
int prefix;
int hit;
} Walk_t;
/*
* convert c to lower case
*/
static int
lower(register int c)
{
}
/*
* Ent_t case insensitive comparf
*/
static int
{
return strcasecmp(a, b);
}
/*
* Cap_t free
*/
static void
{
{
}
}
/*
* Ent_t freef
*/
static void
{
{
}
}
/*
* add mime type entry in s to mp
*/
int
{
register char* t;
register char* v;
register char* k;
char* x;
int q;
for (; isspace(*s); s++);
if (*s && *s != '#')
{
cap = 0;
for (v = s; *v && *v != ';'; v++)
*v = 0;
if (*v)
{
*v++ = 0;
do
{
for (; isspace(*v); v++);
if (cap)
{
for (t = v; *t && !isspace(*t) && *t != '='; t++);
for (k = t; isspace(*t); t++);
if (!*t || *t == '=' || *t == ';')
{
if (*t)
while (isspace(*++t));
*k = 0;
k = v;
v = t;
}
else
k = 0;
}
if (*v == '"')
q = *v++;
else
q = 0;
for (t = v; *t; t++)
if (*t == '\\')
{
switch (*(t + 1))
{
case 0:
case '\\':
case '%':
*t = *(t + 1);
break;
default:
*t = ' ';
break;
}
if (!*++t)
break;
}
else if (*t == q)
{
*t = ' ';
q = 0;
}
else if (*t == ';' && !q)
{
*t = ' ';
break;
}
for (; t > v && isspace(*(t - 1)); t--);
if (t <= v && (!cap || !k))
break;
if (!cap)
{
return -1;
if (*t)
*t++ = 0;
}
else if (k)
{
if (*t)
*t++ = 0;
return -1;
if (!strcasecmp(k, "test"))
}
} while (*(v = t));
}
if (cap)
{
if (ent)
{
{
if (flags & MIME_REPLACE)
{
if (pud)
else
}
return 0;
}
}
return -1;
else
{
}
}
}
return 0;
}
/*
* load mime type files into mp
*/
int
{
register char* s;
register char* t;
register char* e;
register int n;
if (!(s = (char*)file))
{
if (!(s = getenv(MIME_FILES_ENV)))
s = MIME_FILES;
}
for (;;)
{
e = 0;
else if (e = strchr(s, ':'))
{
/*
* ok, so ~ won't work for the last list element
* we do it for MIME_FILES_ENV anyway
*/
if ((strneq(s, "~/", n = 2) || strneq(s, "$HOME/", n = 6) || strneq(s, "${HOME}/", n = 8)) && (t = getenv("HOME")))
{
s += n - 1;
}
}
{
break;
}
return -1;
if (!e)
break;
s = e + 1;
}
return 0;
}
/*
* mimelist walker
*/
static int
{
if (!wp->pattern || !strncasecmp(ent->name, wp->pattern, wp->prefix) && (!ent->name[wp->prefix] || ent->name[wp->prefix] == '/'))
{
{
{
{
}
}
}
}
return 0;
}
/*
* list mime <type,data> for pat on fp
*/
int
{
register const char* s;
{
for (s = pattern; *s && *s != '/'; s++);
if (!*s || (!*(s + 1) || *(s + 1) == '*' && !*(s + 2)))
{
}
}
}
/*
* get next arg in pp
* 0 returned if no more args
*/
static int
{
register char* s;
register int c;
register int q;
if (!*s || *s == '\n')
{
return 0;
}
q = 0;
while ((c = *s++) && c != ';' && c != '\n')
{
if (c == '"')
{
q = 1;
do
{
if (!(c = *s++) || c == '\n')
{
s--;
break;
}
} while (c != '"');
if (first < 0)
{
c = ';';
break;
}
}
else if (c == '=' && !first)
{
first = 1;
}
break;
}
if (first >= 0 || !q)
else
}
/*
* low level for mimeview()
*/
static char*
{
register char* t;
register int c;
for (;;)
{
switch (c = *s++)
{
case 0:
case '\n':
break;
case '%':
switch (c = *s++)
{
case 's':
continue;
case 't':
continue;
case '{':
for (t = s; *s && *s != '}'; s++);
{
break;
}
continue;
}
/*FALLTHROUGH*/
default:
continue;
}
break;
}
}
/*
* return value valid until next mime*() call
*/
char*
{
register char* s;
int c;
if (!(ent = (Ent_t*)dtmatch(mp->cap, type)) && (s = strchr(type, '/')) && (c = s - (char*)type) < sizeof(word))
{
word[c] = 0;
}
if (ent)
{
{
{
/*
* try to do a few common cases here
* mailcap consistency is a winning
* strategy
*/
{
goto lose;
if (a1.name.size == 6 && strneq(a1.name.data, "strcmp", 6) || a1.name.size == 10 && strneq(a1.name.data, "strcasecmp", 10))
{
goto lose;
goto lose;
c ^= 0;
else c ^= (a1.name.size == 6 ? strncmp : strncasecmp)(a2.name.data, a3.name.data, a2.name.size) == 0;
if (c)
break;
goto skip;
}
{
goto lose;
if (!arg(&a2, -1) || a2.name.size > 2 || a2.name.size == 1 && *a2.name.data != '=' || a2.name.size == 2 && (!strneq(a1.name.data, "!=", 2) || !strneq(a2.name.data, "==", 2)))
goto lose;
goto lose;
{
}
{
goto lose;
goto lose;
}
else
c ^= 0;
if (c)
break;
goto skip;
}
}
lose:
if (!system(s))
break;
}
skip:
return 0;
}
return 0;
}
return 0;
}
/*
* lower case identifier prefix strcmp
* if e!=0 then it will point to the next char after the match
*/
int
mimecmp(register const char* s, register const char* v, char** e)
{
register int n;
return n;
{
if (e)
*e = (char*)s;
return 0;
}
}
/*
* parse mime headers in strsearch(tab,num,siz) from s
* return >0 if mime header consumed
*/
int
mimehead(Mime_t* mp, void* tab, size_t num, size_t siz, register char* s, int (*set)(Mime_t*, void*, char*, size_t, Mimedisc_t*))
{
register void* p;
char* e;
#if __OBSOLETE__ < 19990101
#endif
{
s += 8;
{
{
return 0;
return 0;
return 1;
}
}
else if (strchr(s, ':'))
return 1;
}
}
/*
* open a mime library handle
*/
{
return 0;
{
return 0;
}
return mp;
}
/*
* close a mimeopen() handle
*/
int
{
if (mp)
{
}
return 0;
}