1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999-2025 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <time.h>
#include <mailutils/wordsplit.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#include <mailutils/nls.h>
#include <mailutils/assoc.h>
#include <mailutils/list.h>
#include <mailutils/stream.h>
#include <mailutils/sql.h>
int
mu_is_proto (const char *p)
{
if (*p == '|')
return 1;
for (; *p && *p != '/'; p++)
if (*p == ':')
return 1;
return 0;
}
int
mu_mh_delim (const char *str)
{
if (str[0] == '-')
{
for (; *str == '-'; str++)
;
for (; *str == ' ' || *str == '\t'; str++)
;
}
return str[0] == '\n';
}
int
mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr)
{
int rc;
int i;
struct mu_wordsplit ws;
mu_assoc_t assoc_tab = NULL;
ws.ws_delim = ":";
if (mu_wordsplit (map, &ws, MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM))
{
mu_error (_("cannot split line `%s': %s"), map,
mu_wordsplit_strerror (&ws));
return errno;
}
for (i = 0; i < ws.ws_wordc; i++)
{
char *tok = ws.ws_wordv[i];
char *p = strchr (tok, '=');
char *pptr;
if (!p)
{
rc = EINVAL;
break;
}
if (!assoc_tab)
{
rc = mu_assoc_create (&assoc_tab, 0);
if (rc)
break;
mu_assoc_set_destroy_item (assoc_tab, mu_list_free_item);
*passoc_tab = assoc_tab;
}
*p++ = 0;
pptr = strdup (p);
if (!pptr)
{
rc = errno;
break;
}
rc = mu_assoc_install (assoc_tab, tok, pptr);
if (rc)
{
free (pptr);
break;
}
}
mu_wordsplit_free (&ws);
if (rc && perr)
*perr = i;
return rc;
}
int
mu_stream_flags_to_mode (int flags, int isdir)
{
int mode = 0;
if (flags & MU_STREAM_IRGRP)
mode |= S_IRGRP;
if (flags & MU_STREAM_IWGRP)
mode |= S_IWGRP;
if (flags & MU_STREAM_IROTH)
mode |= S_IROTH;
if (flags & MU_STREAM_IWOTH)
mode |= S_IWOTH;
if (isdir)
{
if (mode & (S_IRGRP|S_IWGRP))
mode |= S_IXGRP;
if (mode & (S_IROTH|S_IWOTH))
mode |= S_IXOTH;
}
return mode;
}
|