]> diplodocus.org Git - nmh/blob - sbr/context_find.c
Various IMAP protocol improvements
[nmh] / sbr / context_find.c
1 /* context_find.c -- find an entry in the context/profile list
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9
10
11 char *
12 context_find (const char *str)
13 {
14 struct node *np;
15
16 str = FENDNULL(str);
17 for (np = m_defs; np; np = np->n_next)
18 if (!strcasecmp(FENDNULL(np->n_name), str))
19 return np->n_field;
20
21 return NULL;
22 }
23
24
25 /*
26 * Helper function to search first, if subtype is non-NULL, for
27 * invoname-string-type/subtype and then, if not yet found,
28 * invoname-string-type. If entry is found but is empty, it is
29 * treated as not found.
30 */
31 char *
32 context_find_by_type (const char *string, const char *type,
33 const char *subtype)
34 {
35 char *value = NULL;
36
37 if (subtype) {
38 char *cp;
39
40 cp = concat (invo_name, "-", string, "-", type, "/", subtype, NULL);
41 if ((value = context_find (cp)) != NULL && *value == '\0') value = NULL;
42 free (cp);
43 }
44
45 if (value == NULL) {
46 char *cp;
47
48 cp = concat (invo_name, "-", string, "-", type, NULL);
49 if ((value = context_find (cp)) != NULL && *value == '\0') value = NULL;
50 free (cp);
51 }
52
53 return value;
54 }
55
56
57 /*
58 * Helper function to search profile an entry with name beginning with prefix.
59 * The search is case insensitive.
60 */
61 int
62 context_find_prefix (const char *prefix)
63 {
64 struct node *np;
65 size_t len;
66
67 len = strlen(prefix);
68 for (np = m_defs; np; np = np->n_next) {
69 if (np->n_name && ! strncasecmp (np->n_name, prefix, len)) {
70 return 1;
71 }
72 }
73
74 return 0;
75 }