1/* -*- buffer-read-only: t -*- vi: set ro:
2   THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT.
3*/
4#line 1 "callout.mf4"
5/* Callout functions                                    -*- mfl -*-
6   Copyright (C) 2010-2021 Sergey Poznyakoff
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 3, or (at your option)
11   any later version.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
20
21module 'callout'.
22
23require status
24
25#pragma regex push +extended
26
27dclex e_callout_proto
28
29#line 29
30
31string last_poll_host
32string last_poll_greeting
33string last_poll_helo
34string last_poll_sent
35string last_poll_recv
36number cache_used
37
38static func setvar(number fd, string name, string value)
39do
40  write(fd, "SET %name=%value\r\n")
41  set reply getline(fd)
42  if not reply matches 'OK.*'
43    throw e_callout_proto reply
44  fi
45done
46
47func callout_open(string url)
48  returns number
49do
50  number fd open("@ %url")
51  fd_set_delimiter(fd,"\r\n")
52  string reply getline(fd)
53  if not reply matches 'OK.*'
54    throw e_callout_proto reply
55  fi
56
57  string sid ""
58  if milter_client_address == ""
59    set sid "local:"
60  else
61    set sid "%milter_client_address:"
62  fi
63  if macro_defined("i")
64    set sid sid . getmacro("i")
65  fi
66  write(fd, "SID %sid\r\n")
67  set reply getline(fd)
68  if not reply matches 'OK.*'
69    throw e_callout_proto reply
70  fi
71
72
73#line 79
74  return fd
75done
76
77func callout_close(number fd)
78do
79  write(fd, "QUIT\r\n")
80  set reply getline(fd)
81  close(fd)
82done
83
84func callout_do(number fd, string email; string rest)
85  returns number
86do
87  string reply ""
88
89  if dequote(email) == ""
90    return 0
91  fi
92
93  write(fd, 'VRFY "'.escape(email).'"')
94  if $#>@rest
95    write(fd, ' '.rest)
96  fi
97  write(fd, "\r\n")
98  set reply getline(fd)
99  if not reply matches 'OK.*'
100    throw e_callout_proto reply
101  fi
102
103  write(fd, "RUN\r\n")
104  set cache_used 1
105  loop for set reply getline(fd),
106       while index(reply, "*") == 0,
107       set reply getline(fd)
108  do
109    if reply matches '\* ([0-9]+) ([A-Z]+) (.*)'
110      set cache_used 0
111      switch \2
112      do
113      case "INIT":
114	set last_poll_host \3
115      case "GRTNG":
116	set last_poll_greeting \3
117      case "HELO":
118        set last_poll_helo \3
119      case "SENT":
120	set last_poll_sent \3
121      case "RECV":
122	set last_poll_recv \3
123      done
124    fi
125  done
126
127  if reply matches "OK ([0-9]+)=(.*)"
128    switch \2
129    do
130    case "success":
131      pass
132    case "not_found":
133      return e_not_found
134    case "failure":
135      return e_failure
136    case "temp_failure" or "timeout":
137      return e_temp_failure
138    done
139  else
140    return e_not_found
141  fi
142  return 0
143done
144
145#pragma provide-callout
146precious string callout_server_url
147precious number __callout_fd -1
148
149begin
150do
151  if callout_server_url == ""
152    set callout_server_url default_callout_server_url()
153  fi
154done
155
156func __callout_open_default()
157  returns number
158do
159  if __callout_fd == -1
160    set __callout_fd callout_open(callout_server_url)
161  fi
162  return __callout_fd
163done
164
165func callout(string email)
166  returns number
167do
168  return callout_do(__callout_open_default(), email)
169done
170
171
172
173
174
175
176
177