1 /* ========================================================================
2 * Copyright 1988-2006 University of Washington
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
11 * ========================================================================
15 #define tcp_getline tcp_getline_lnx
16 #define tcp_getbuffer tcp_getbuffer_lnx
17 #define tcp_soutr tcp_soutr_lnx
18 #define tcp_sout tcp_sout_lnx
21 #define mail_lookup_auth_name mail_lookup_auth_name_unused
25 //#include "em-core-utils.h"
30 #include "imap-dbglog.h"
39 #undef mail_lookup_auth_name
48 tcp_getdata_lnx(TCPSTREAM* stream)
52 int nread, sret, sockid, maxfd;
55 sockid = stream->tcpsi;
58 if (sockid < 0) return false;
60 while (stream->ictr < 1)
62 tmout.tv_usec = 0;//1000*10;
66 FD_SET(sockid, &readfds);
68 sret = select(maxfd, &readfds, NULL, NULL, &tmout);
75 if (max_timeout >= 50) {
76 IMAP_DEBUG_EXCEPTION("max select timeout %d", max_timeout);
78 //em_core_set_network_error(EMF_ERROR_NO_RESPONSE);
82 IMAP_DEBUG_EXCEPTION("%d select timeout", max_timeout);
88 if ((nread = read(sockid, stream->ibuf, BUFLEN)) < 0) {
89 IMAP_DEBUG_EXCEPTION("\t socket read failed...\n");
95 IMAP_DEBUG_EXCEPTION("\t socket read no data...\n");
100 stream->ictr = nread;
101 stream->iptr = stream->ibuf;
107 /* TCP/IP receive line
108 * Accepts: TCP/IP stream
109 * Returns: text line string or NIL if failure
112 char *tcp_getline_lnx (void *vstream)
114 TCPSTREAM *stream = (TCPSTREAM*)vstream;
119 /* make sure have data */
120 if (!tcp_getdata_lnx (stream)) return NIL;
121 st = stream->iptr; /* save start of string */
122 n = 0; /* init string count */
123 while (stream->ictr--) { /* look for end of line */
124 d = *stream->iptr++; /* slurp another character */
125 if ((c == '\015') && (d == '\012')) {
126 ret = (char *) fs_get (n--);
127 memcpy (ret,st,n); /* copy into a free storage string */
128 ret[n] = '\0'; /* tie off string with null */
131 n++; /* count another character searched */
132 c = d; /* remember previous character */
134 /* copy partial string from buffer */
135 memcpy ((ret = stp = (char *) fs_get (n)),st,n);
136 /* get more data from the net */
137 if (!tcp_getdata_lnx (stream)) fs_give ((void **) &ret);
138 /* special case of newline broken by buffer */
139 else if ((c == '\015') && (*stream->iptr == '\012')) {
140 stream->iptr++; /* eat the line feed */
142 ret[n - 1] = '\0'; /* tie off string with null */
144 /* else recurse to get remainder */
145 else if (st = tcp_getline_lnx (stream)) {
146 ret = (char *) fs_get (n + 1 + (m = strlen (st)));
147 memcpy (ret,stp,n); /* copy first part */
148 memcpy (ret + n,st,m); /* and second part */
149 fs_give ((void **) &stp); /* flush first part */
150 fs_give ((void **) &st); /* flush second part */
151 ret[n + m] = '\0'; /* tie off string with null */
159 unsigned int mail_lookup_auth_name (char *mechanism,long flags)
164 if(!try_auth) return 0;
166 for (i = 1, auth = mailauthenticators; auth; i++, auth = auth->next)
167 if (auth->client && !(flags & ~auth->flags) &&
168 !compare_cstring (auth->name,mechanism))
174 int try_auth_smtp = 0;
175 unsigned int mail_lookup_auth_name_smtp (char *mechanism,long flags)
180 if(!try_auth_smtp) return 0;
182 for (i = 1, auth = mailauthenticators; auth; i++, auth = auth->next)
183 if (auth->client && !(flags & ~auth->flags) &&
184 !compare_cstring (auth->name,mechanism))