summaryrefslogtreecommitdiffabout
path: root/kmicromail
Unidiff
Diffstat (limited to 'kmicromail') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libetpan/include/libetpan/mailstream.h1
-rw-r--r--kmicromail/libetpan/tools/mailstream.c2
-rw-r--r--kmicromail/libetpan/tools/mailstream.h3
-rw-r--r--kmicromail/libetpan/tools/mailstream_socket.c13
4 files changed, 14 insertions, 5 deletions
diff --git a/kmicromail/libetpan/include/libetpan/mailstream.h b/kmicromail/libetpan/include/libetpan/mailstream.h
index a4e35cd..ffb5062 100644
--- a/kmicromail/libetpan/include/libetpan/mailstream.h
+++ b/kmicromail/libetpan/include/libetpan/mailstream.h
@@ -13,48 +13,49 @@
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * $Id$ 33 * $Id$
34 */ 34 */
35 35
36#ifndef MAILSTREAM_H 36#ifndef MAILSTREAM_H
37#define DEFAULT_NETWORK_TIMEOUT 30
37 38
38#define MAILSTREAM_H 39#define MAILSTREAM_H
39 40
40#include <sys/time.h> 41#include <sys/time.h>
41 42
42#include <libetpan/mailstream_low.h> 43#include <libetpan/mailstream_low.h>
43#include <libetpan/mailstream_helper.h> 44#include <libetpan/mailstream_helper.h>
44#include <libetpan/mailstream_socket.h> 45#include <libetpan/mailstream_socket.h>
45#include <libetpan/mailstream_ssl.h> 46#include <libetpan/mailstream_ssl.h>
46#include <libetpan/mailstream_types.h> 47#include <libetpan/mailstream_types.h>
47 48
48#ifdef __cplusplus 49#ifdef __cplusplus
49extern "C" { 50extern "C" {
50#endif 51#endif
51 52
52mailstream * mailstream_new(mailstream_low * low, size_t buffer_size); 53mailstream * mailstream_new(mailstream_low * low, size_t buffer_size);
53ssize_t mailstream_write(mailstream * s, const void * buf, size_t count); 54ssize_t mailstream_write(mailstream * s, const void * buf, size_t count);
54ssize_t mailstream_read(mailstream * s, void * buf, size_t count); 55ssize_t mailstream_read(mailstream * s, void * buf, size_t count);
55int mailstream_close(mailstream * s); 56int mailstream_close(mailstream * s);
56int mailstream_flush(mailstream * s); 57int mailstream_flush(mailstream * s);
57ssize_t mailstream_feed_read_buffer(mailstream * s); 58ssize_t mailstream_feed_read_buffer(mailstream * s);
58mailstream_low * mailstream_get_low(mailstream * s); 59mailstream_low * mailstream_get_low(mailstream * s);
59void mailstream_set_low(mailstream * s, mailstream_low * low); 60void mailstream_set_low(mailstream * s, mailstream_low * low);
60 61
diff --git a/kmicromail/libetpan/tools/mailstream.c b/kmicromail/libetpan/tools/mailstream.c
index 0f55e67..6d1a8cc 100644
--- a/kmicromail/libetpan/tools/mailstream.c
+++ b/kmicromail/libetpan/tools/mailstream.c
@@ -19,49 +19,49 @@
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * $Id$ 33 * $Id$
34 */ 34 */
35 35
36#include "mailstream.h" 36#include "mailstream.h"
37#include "maillock.h" 37#include "maillock.h"
38#include <string.h> 38#include <string.h>
39#include <stdlib.h> 39#include <stdlib.h>
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/stat.h> 41#include <sys/stat.h>
42 42
43#define DEFAULT_NETWORK_TIMEOUT 300 43
44 44
45#ifdef LIBETPAN_MAILSTREAM_DEBUG 45#ifdef LIBETPAN_MAILSTREAM_DEBUG
46 46
47#define STREAM_DEBUG 47#define STREAM_DEBUG
48 48
49#include <stdio.h> 49#include <stdio.h>
50 50
51#define LOG_FILE "libetpan-stream-debug.log" 51#define LOG_FILE "libetpan-stream-debug.log"
52 52
53int mailstream_debug = 0; 53int mailstream_debug = 0;
54 54
55#define STREAM_LOG_BUF(buf, size) \ 55#define STREAM_LOG_BUF(buf, size) \
56 if (mailstream_debug) { \ 56 if (mailstream_debug) { \
57 FILE * f; \ 57 FILE * f; \
58 mode_t old_mask; \ 58 mode_t old_mask; \
59 \ 59 \
60 old_mask = umask(0077); \ 60 old_mask = umask(0077); \
61 f = fopen(LOG_FILE, "a"); \ 61 f = fopen(LOG_FILE, "a"); \
62 umask(old_mask); \ 62 umask(old_mask); \
63 if (f != NULL) { \ 63 if (f != NULL) { \
64 maillock_write_lock(LOG_FILE, fileno(f)); \ 64 maillock_write_lock(LOG_FILE, fileno(f)); \
65 fwrite((buf), 1, (size), f); \ 65 fwrite((buf), 1, (size), f); \
66 maillock_write_unlock(LOG_FILE, fileno(f)); \ 66 maillock_write_unlock(LOG_FILE, fileno(f)); \
67 fclose(f); \ 67 fclose(f); \
diff --git a/kmicromail/libetpan/tools/mailstream.h b/kmicromail/libetpan/tools/mailstream.h
index a4e35cd..8a89a72 100644
--- a/kmicromail/libetpan/tools/mailstream.h
+++ b/kmicromail/libetpan/tools/mailstream.h
@@ -15,49 +15,50 @@
15 * 3. Neither the name of the libEtPan! project nor the names of its 15 * 3. Neither the name of the libEtPan! project nor the names of its
16 * contributors may be used to endorse or promote products derived 16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * $Id$ 33 * $Id$
34 */ 34 */
35 35
36#ifndef MAILSTREAM_H 36#ifndef MAILSTREAM_H
37 37
38#define MAILSTREAM_H 38#define MAILSTREAM_H
39 39//dont forget to change the value in <libetpan/mailstream.h> as well
40#define DEFAULT_NETWORK_TIMEOUT 30
40#include <sys/time.h> 41#include <sys/time.h>
41 42
42#include <libetpan/mailstream_low.h> 43#include <libetpan/mailstream_low.h>
43#include <libetpan/mailstream_helper.h> 44#include <libetpan/mailstream_helper.h>
44#include <libetpan/mailstream_socket.h> 45#include <libetpan/mailstream_socket.h>
45#include <libetpan/mailstream_ssl.h> 46#include <libetpan/mailstream_ssl.h>
46#include <libetpan/mailstream_types.h> 47#include <libetpan/mailstream_types.h>
47 48
48#ifdef __cplusplus 49#ifdef __cplusplus
49extern "C" { 50extern "C" {
50#endif 51#endif
51 52
52mailstream * mailstream_new(mailstream_low * low, size_t buffer_size); 53mailstream * mailstream_new(mailstream_low * low, size_t buffer_size);
53ssize_t mailstream_write(mailstream * s, const void * buf, size_t count); 54ssize_t mailstream_write(mailstream * s, const void * buf, size_t count);
54ssize_t mailstream_read(mailstream * s, void * buf, size_t count); 55ssize_t mailstream_read(mailstream * s, void * buf, size_t count);
55int mailstream_close(mailstream * s); 56int mailstream_close(mailstream * s);
56int mailstream_flush(mailstream * s); 57int mailstream_flush(mailstream * s);
57ssize_t mailstream_feed_read_buffer(mailstream * s); 58ssize_t mailstream_feed_read_buffer(mailstream * s);
58mailstream_low * mailstream_get_low(mailstream * s); 59mailstream_low * mailstream_get_low(mailstream * s);
59void mailstream_set_low(mailstream * s, mailstream_low * low); 60void mailstream_set_low(mailstream * s, mailstream_low * low);
60 61
61#ifdef LIBETPAN_MAILSTREAM_DEBUG 62#ifdef LIBETPAN_MAILSTREAM_DEBUG
62extern int mailstream_debug; 63extern int mailstream_debug;
63#endif 64#endif
diff --git a/kmicromail/libetpan/tools/mailstream_socket.c b/kmicromail/libetpan/tools/mailstream_socket.c
index 29e50e1..04a6f48 100644
--- a/kmicromail/libetpan/tools/mailstream_socket.c
+++ b/kmicromail/libetpan/tools/mailstream_socket.c
@@ -148,81 +148,88 @@ static int mailstream_low_socket_get_fd(mailstream_low * s)
148 return socket_data->fd; 148 return socket_data->fd;
149} 149}
150 150
151 151
152static ssize_t mailstream_low_socket_read(mailstream_low * s, 152static ssize_t mailstream_low_socket_read(mailstream_low * s,
153 void * buf, size_t count) 153 void * buf, size_t count)
154{ 154{
155 struct mailstream_socket_data * socket_data; 155 struct mailstream_socket_data * socket_data;
156 156
157 socket_data = (struct mailstream_socket_data *) s->data; 157 socket_data = (struct mailstream_socket_data *) s->data;
158 158
159 /* timeout */ 159 /* timeout */
160 { 160 {
161 fd_set fds_read; 161 fd_set fds_read;
162 fd_set fds_excp; 162 fd_set fds_excp;
163 struct timeval timeout; 163 struct timeval timeout;
164 int r; 164 int r;
165 165
166 timeout = mailstream_network_delay; 166 timeout = mailstream_network_delay;
167 167
168 FD_ZERO(&fds_read); 168 FD_ZERO(&fds_read);
169 FD_SET(socket_data->fd, &fds_read); 169 FD_SET(socket_data->fd, &fds_read);
170 FD_ZERO(&fds_excp); 170 FD_ZERO(&fds_excp);
171 FD_SET(socket_data->fd, &fds_excp); 171 FD_SET(socket_data->fd, &fds_excp);
172 // LUTZ for safety I insert here a max val as well
173 if ( timeout.tv_sec > DEFAULT_NETWORK_TIMEOUT )
174 timeout.tv_sec = DEFAULT_NETWORK_TIMEOUT;
172 r = select(socket_data->fd + 1, &fds_read, NULL, &fds_excp, &timeout); 175 r = select(socket_data->fd + 1, &fds_read, NULL, &fds_excp, &timeout);
173 if (r == 0) 176 if (r < 1 )
174 return -1; 177 return -1;
175 if (FD_ISSET(socket_data->fd, &fds_excp)) 178 if (FD_ISSET(socket_data->fd, &fds_excp))
176 return -1; 179 return -1;
177 if (!FD_ISSET(socket_data->fd, &fds_read)) 180 if (!FD_ISSET(socket_data->fd, &fds_read))
178 return 0; 181 return 0;
179 } 182 }
180 return recv(socket_data->fd,buf,count,MSG_NOSIGNAL); 183 return recv(socket_data->fd,buf,count,MSG_NOSIGNAL);
181 //return read(socket_data->fd, buf, count); 184 //return read(socket_data->fd, buf, count);
182} 185}
183 186#include <stdio.h>
184static ssize_t mailstream_low_socket_write(mailstream_low * s, 187static ssize_t mailstream_low_socket_write(mailstream_low * s,
185 const void * buf, size_t count) 188 const void * buf, size_t count)
186{ 189{
187 struct mailstream_socket_data * socket_data; 190 struct mailstream_socket_data * socket_data;
188 191
189 socket_data = (struct mailstream_socket_data *) s->data; 192 socket_data = (struct mailstream_socket_data *) s->data;
190 /* timeout */ 193 /* timeout */
191 { 194 {
192 fd_set fds_write; 195 fd_set fds_write;
193 fd_set fds_excp; 196 fd_set fds_excp;
194 struct timeval timeout; 197 struct timeval timeout;
195 int r; 198 int r;
196 199
197 timeout = mailstream_network_delay; 200 timeout = mailstream_network_delay;
198 201
199 FD_ZERO(&fds_write); 202 FD_ZERO(&fds_write);
200 FD_SET(socket_data->fd, &fds_write); 203 FD_SET(socket_data->fd, &fds_write);
201 FD_ZERO(&fds_excp); 204 FD_ZERO(&fds_excp);
202 FD_SET(socket_data->fd, &fds_excp); 205 FD_SET(socket_data->fd, &fds_excp);
206 // LUTZ next line blocks sometimes
207 if ( timeout.tv_sec > DEFAULT_NETWORK_TIMEOUT )
208 timeout.tv_sec = DEFAULT_NETWORK_TIMEOUT;
209 fprintf(stderr,"fd %d to secs %d \n", socket_data->fd, timeout.tv_sec );
203 r = select(socket_data->fd + 1, NULL, &fds_write, &fds_excp, &timeout); 210 r = select(socket_data->fd + 1, NULL, &fds_write, &fds_excp, &timeout);
204 if (r == 0) 211 if (r < 1)
205 return -1; 212 return -1;
206 if (FD_ISSET(socket_data->fd, &fds_excp)) 213 if (FD_ISSET(socket_data->fd, &fds_excp))
207 return -1; 214 return -1;
208 if (!FD_ISSET(socket_data->fd, &fds_write)) 215 if (!FD_ISSET(socket_data->fd, &fds_write))
209 return 0; 216 return 0;
210 } 217 }
211 218
212 return send(socket_data->fd,buf,count,MSG_NOSIGNAL); 219 return send(socket_data->fd,buf,count,MSG_NOSIGNAL);
213 //return write(socket_data->fd, buf, count); 220 //return write(socket_data->fd, buf, count);
214} 221}
215 222
216 223
217/* mailstream */ 224/* mailstream */
218 225
219mailstream * mailstream_socket_open(int fd) 226mailstream * mailstream_socket_open(int fd)
220{ 227{
221 mailstream_low * low; 228 mailstream_low * low;
222 mailstream * s; 229 mailstream * s;
223 230
224 low = mailstream_low_socket_open(fd); 231 low = mailstream_low_socket_open(fd);
225 if (low == NULL) 232 if (low == NULL)
226 goto err; 233 goto err;
227 234
228 s = mailstream_new(low, 8192); 235 s = mailstream_new(low, 8192);