Copyright updates:
[exim.git] / src / src / dummies.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2009 */
6 /* Copyright (c) The Exim Maintainers 2021 */
7 /* See the file NOTICE for conditions of use and distribution. */
8
9 /* This file is not part of the main Exim code. There are little bits of test
10 code for some of Exim's modules, and when they are used, the module they are
11 testing may call other main Exim functions that are not available and/or
12 should not be used in a test. The classic case is log_write(). This module
13 contains dummy versions of such functions - well not really dummies, more like
14 alternates. */
15
16 #include <stdarg.h>
17 #include <stdio.h>
18 #include <errno.h>
19 #include <string.h>
20
21 /* We don't have the full Exim headers dragged in, but this function
22 is used for debugging output. */
23
24 extern gstring * string_vformat(gstring *, unsigned, const char *, va_list);
25
26
27 /*************************************************
28 *         Handle calls to write the log          *
29 *************************************************/
30
31 /* The message gets written to stderr when log_write() is called from a
32 utility. The message always gets '\n' added on the end of it.
33
34 Arguments:
35   selector  not relevant when running a utility
36   flags     not relevant when running a utility
37   format    a printf() format
38   ...       arguments for format
39
40 Returns:    nothing
41 */
42
43 void
44 log_write(unsigned int selector, int flags, char *format, ...)
45 {
46 va_list ap;
47 va_start(ap, format);
48 vfprintf(stderr, format, ap);
49 fprintf(stderr, "\n");
50 va_end(ap);
51 }
52
53
54 /*************************************************
55 *      Handle calls to print debug output        *
56 *************************************************/
57
58 /* The message just gets written to stderr.
59 We use tainted memory to format into just so that we can handle
60 tainted arguments.
61
62 Arguments:
63   format    a printf() format
64   ...       arguments for format
65
66 Returns:    nothing
67 */
68
69 void
70 debug_printf(char *format, ...)
71 {
72 va_list ap;
73 rmark reset_point = store_mark();
74 gstring * g = string_get_tainted(1024, TRUE);
75
76 va_start(ap, format);
77
78 if (!string_vformat(g, 0, format, ap))
79   {
80   char * s = "**** debug string overflowed buffer ****\n";
81   char * p = CS g->s + g->ptr;
82   int maxlen = g->size - (int)strlen(s) - 3;
83   if (p > g->s + maxlen) p = g->s + maxlen;
84   if (p > g->s && p[-1] != '\n') *p++ = '\n';
85   strcpy(p, s);
86   }
87
88 fprintf(stderr, "%s", string_from_gstring(g));
89 fflush(stderr);
90 store_reset(reset_point);
91 va_end(ap);
92 }
93
94
95
96 /*************************************************
97 *              SIGALRM handler                   *
98 *************************************************/
99
100 extern int sigalrm_seen;
101
102 void
103 sigalrm_handler(int sig)
104 {
105 sigalrm_seen = TRUE;
106 }
107
108
109
110 /*************************************************
111 *              Complete Dummies                  *
112 *************************************************/
113
114 int
115 header_checkname(void *h, char *name, int len)
116 {
117 return 0;
118 }
119
120 void
121 directory_make(char *parent, char *name, int mode, int panic)
122 {
123 }
124
125 void
126 host_build_sender_fullhost(void) { }
127
128 /* This one isn't needed for test_host */
129
130 #ifndef TEST_HOST
131 char *
132 host_ntoa(int type, const void *arg, char *buffer, int *portptr)
133 {
134 return NULL;
135 }
136 #endif
137
138
139 /* End of dummies.c */