Postfix3.3.1
dict_static.c
[詳解]
1 /*++
2 /* NAME
3 /* dict_static 3
4 /* SUMMARY
5 /* dictionary manager interface to static variables
6 /* SYNOPSIS
7 /* #include <dict_static.h>
8 /*
9 /* DICT *dict_static_open(name, name, dict_flags)
10 /* const char *name;
11 /* int dummy;
12 /* int dict_flags;
13 /* DESCRIPTION
14 /* dict_static_open() implements a dummy dictionary that returns
15 /* as lookup result the dictionary name, regardless of the lookup
16 /* key value.
17 /* SEE ALSO
18 /* dict(3) generic dictionary manager
19 /* LICENSE
20 /* .ad
21 /* .fi
22 /* The Secure Mailer license must be distributed with this software.
23 /* AUTHOR(S)
24 /* jeffm
25 /* ghostgun.com
26 /*--*/
27 
28 /* System library. */
29 
30 #include "sys_defs.h"
31 #include <stdio.h> /* sprintf() prototype */
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <string.h>
35 
36 /* Utility library. */
37 
38 #include "mymalloc.h"
39 #include "msg.h"
40 #include "stringops.h"
41 #include "dict.h"
42 #include "dict_static.h"
43 
44 /* dict_static_lookup - access static value*/
45 
46 static const char *dict_static_lookup(DICT *dict, const char *unused_name)
47 {
49 }
50 
51 /* dict_static_close - close static dictionary */
52 
53 static void dict_static_close(DICT *dict)
54 {
55  dict_free(dict);
56 }
57 
58 /* dict_static_open - make association with static variable */
59 
60 DICT *dict_static_open(const char *name, int open_flags, int dict_flags)
61 {
62  DICT *dict;
63  char *err = 0;
64  char *cp, *saved_name = 0;
65 
66  /*
67  * Let the optimizer worry about eliminating redundant code.
68  */
69 #define DICT_STATIC_OPEN_RETURN(d) do { \
70  DICT *__d = (d); \
71  if (saved_name != 0) \
72  myfree(saved_name); \
73  if (err != 0) \
74  myfree(err); \
75  return (__d); \
76  } while (0)
77 
78  /*
79  * Optionally strip surrounding braces and whitespace.
80  */
81  if (name[0] == CHARS_BRACE[0]) {
82  saved_name = cp = mystrdup(name);
83  if ((err = extpar(&cp, CHARS_BRACE, EXTPAR_FLAG_STRIP)) != 0)
85  open_flags, dict_flags,
86  "bad %s:name syntax: %s",
87  DICT_TYPE_STATIC, err));
88  name = cp;
89  }
90 
91  /*
92  * Bundle up the request.
93  */
94  dict = dict_alloc(DICT_TYPE_STATIC, name, sizeof(*dict));
95  dict->lookup = dict_static_lookup;
96  dict->close = dict_static_close;
97  dict->flags = dict_flags | DICT_FLAG_FIXED;
100 }
#define DICT_TYPE_STATIC
Definition: dict_static.h:22
#define CHARS_BRACE
Definition: sys_defs.h:1763
char * mystrdup(const char *str)
Definition: mymalloc.c:225
char * extpar(char **bp, const char *parens, int flags)
Definition: extpar.c:77
void(* close)(struct DICT *)
Definition: dict.h:87
char * name
Definition: dict.h:80
#define DICT_FLAG_FIXED
Definition: dict.h:114
int flags
Definition: dict.h:81
#define EXTPAR_FLAG_STRIP
Definition: stringops.h:57
#define DICT_ERR_NONE
Definition: dict.h:177
Definition: dict.h:78
DICT * dict_static_open(const char *name, int open_flags, int dict_flags)
Definition: dict_static.c:60
#define DICT_OWNER_TRUSTED
Definition: dict.h:46
const char *(* lookup)(struct DICT *, const char *)
Definition: dict.h:82
#define DICT_ERR_VAL_RETURN(dict, err, val)
Definition: dict.h:192
int status
Definition: dict.h:38
void dict_free(DICT *)
Definition: dict_alloc.c:163
#define DICT_STATIC_OPEN_RETURN(d)
DICT * dict_alloc(const char *, const char *, ssize_t)
Definition: dict_alloc.c:135
DICT_OWNER owner
Definition: dict.h:93
DICT * dict_surrogate(const char *dict_type, const char *dict_name, int open_flags, int dict_flags, const char *fmt,...)