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