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