Postfix3.3.1
mail_command_client.c
[詳解]
1 /*++
2 /* NAME
3 /* mail_command_client 3
4 /* SUMMARY
5 /* single-command client
6 /* SYNOPSIS
7 /* #include <mail_proto.h>
8 /*
9 /* int mail_command_client(class, name, type, attr, ...)
10 /* const char *class;
11 /* const char *name;
12 /* int type;
13 /* const char *attr;
14 /* DESCRIPTION
15 /* This module implements a client interface for single-command
16 /* clients: a client that sends a single command and expects
17 /* a single completion status code.
18 /*
19 /* Arguments:
20 /* .IP class
21 /* Service type: MAIL_CLASS_PUBLIC or MAIL_CLASS_PRIVATE
22 /* .IP name
23 /* Service name (master.cf).
24 /* .IP "type, attr, ..."
25 /* Attribute information as defined in attr_print(3).
26 /* DIAGNOSTICS
27 /* The result is -1 if the request could not be sent, otherwise
28 /* the result is the status reported by the server.
29 /* Warnings: problems connecting to the requested service.
30 /* Fatal: out of memory.
31 /* SEE ALSO
32 /* attr_print(3), send attributes over byte stream
33 /* mail_command_server(3), server interface
34 /* mail_proto(3h), client-server protocol
35 /* LICENSE
36 /* .ad
37 /* .fi
38 /* The Secure Mailer license must be distributed with this software.
39 /* AUTHOR(S)
40 /* Wietse Venema
41 /* IBM T.J. Watson Research
42 /* P.O. Box 704
43 /* Yorktown Heights, NY 10598, USA
44 /*
45 /* Wietse Venema
46 /* Google, Inc.
47 /* 111 8th Avenue
48 /* New York, NY 10011, USA
49 /*--*/
50 
51 /* System library. */
52 
53 #include <sys_defs.h>
54 #include <stdlib.h> /* 44BSD stdarg.h uses abort() */
55 #include <stdarg.h>
56 
57 /* Utility library. */
58 
59 #include <vstream.h>
60 #include <msg.h>
61 
62 /* Global library. */
63 
64 #include <mail_proto.h>
65 
66 /* mail_command_client - single-command transaction with completion status */
67 
68 int mail_command_client(const char *class, const char *name,...)
69 {
70  va_list ap;
71  VSTREAM *stream;
72  int status;
73 
74  /*
75  * Talk a little protocol with the specified service.
76  *
77  * This function is used for non-critical services where it is OK to back
78  * off after the first error. Log what communication stage failed, to
79  * facilitate trouble analysis.
80  */
81  if ((stream = mail_connect(class, name, BLOCKING)) == 0) {
82  msg_warn("connect to %s/%s: %m", class, name);
83  return (-1);
84  }
85  va_start(ap, name);
86  status = attr_vprint(stream, ATTR_FLAG_NONE, ap);
87  va_end(ap);
88  if (status != 0) {
89  msg_warn("write %s: %m", VSTREAM_PATH(stream));
90  status = -1;
91  } else if (attr_scan(stream, ATTR_FLAG_STRICT,
92  RECV_ATTR_INT(MAIL_ATTR_STATUS, &status), 0) != 1) {
93  msg_warn("write/read %s: %m", VSTREAM_PATH(stream));
94  status = -1;
95  }
96  (void) vstream_fclose(stream);
97  return (status);
98 }
#define ATTR_FLAG_NONE
Definition: attr.h:98
VSTREAM * mail_connect(const char *class, const char *name, int block_mode)
Definition: mail_connect.c:79
#define RECV_ATTR_INT(name, val)
Definition: attr.h:71
#define VSTREAM_PATH(vp)
Definition: vstream.h:126
int vstream_fclose(VSTREAM *stream)
Definition: vstream.c:1268
void msg_warn(const char *fmt,...)
Definition: msg.c:215
int mail_command_client(const char *class, const char *name,...)
#define MAIL_ATTR_STATUS
Definition: mail_proto.h:126
#define attr_vprint
Definition: attr.h:110
#define attr_scan
Definition: attr.h:111
#define BLOCKING
Definition: iostuff.h:48
#define ATTR_FLAG_STRICT
Definition: attr.h:103