Hi all,
Since there were no takers, I did a follow-up on my earlier conclusion
that the networking code could do with some improvements.
For those of you who haven't followed the list; dbmail2 won't work with
mozilla and derivatives.
I've wrapped the code talking to clients in simple wrappers with error
checking, and lo; mozilla suddenly works just fine with dbmail2 :-)
As a proof-of-concept I'm attaching my patch against the HEAD branch as
of today.
This is not for inclusion in CVS just yet. It's still kind of rough, but
I wanted to share my relief that this really does appear to fix the bug.
Also, pop3.c and lmtpd.c would probably also benefit from this approach
as well.
IMO imap4.c and friends could do with some re-indenting. Looks like
there are several different indent-styles intertwined in the code. Any
consensus on that regard ?
--
________________________________________________________________
Paul Stevens mailto:[EMAIL PROTECTED]
NET FACILITIES GROUP PGP: finger [EMAIL PROTECTED]
The Netherlands________________________________http://www.nfg.nl
Index: imap4.c
===================================================================
RCS file: /cvsroot-dbmail/dbmail/imap4.c,v
retrieving revision 1.72
diff -r1.72 imap4.c
109a110,122
> int ci_write(FILE * fd, char * msg, ...);
> int ci_write(FILE * fd, char * msg, ...)
> {
> va_list ap;
> va_start(ap, msg);
> if ( feof(fd) || fprintf(fd,msg,ap) < 0 ) {
> va_end(ap);
> trace(TRACE_ERROR,"ci_write");
> return -1;
> }
> va_end(ap);
> return 0;
> }
110a124,130
> void ci_cleanup(ClientInfo *ci);
> void ci_cleanup(ClientInfo *ci)
> {
> close_cache();
> null_free(((imap_userdata_t*)ci->userData)->mailbox.seq_list);
> null_free(ci->userData);
> }
142,143c162,164
< fprintf(ci->tx,"* OK dbmail imap (protocol version 4r1) server %s ready to run\r\n",
< IMAP_SERVER_VERSION);
---
> if ( ci_write(ci->tx,"* OK dbmail imap (protocol version 4r1) server %s ready to run\r\n",
> IMAP_SERVER_VERSION) )
> return EOF;
150c171,172
< fprintf(ci->tx, "* BYE internal system failure\r\n");
---
> if ( ci_write(ci->tx, "* BYE internal system failure\r\n") )
> return -1;
166c188,189
< fprintf(ci->tx,"* BYE [TRY RFC]\r\n");
---
> if ( ci_write(ci->tx,"* BYE [TRY RFC]\r\n") )
> return -1;
176,179c199
< close_cache();
< null_free(((imap_userdata_t*)ci->userData)->mailbox.seq_list);
< null_free(ci->userData);
<
---
> ci_cleanup(ci);
191,194c211
< close_cache();
< null_free(((imap_userdata_t*)ci->userData)->mailbox.seq_list);
< null_free(ci->userData);
<
---
> ci_cleanup(ci);
202c219,220
< fgets(line, MAX_LINESIZE, ci->rx); /* read command line */
---
> if ( fgets(line, MAX_LINESIZE, ci->rx) == NULL ) /* read command line */
> return -1;
209,212c227
< close_cache();
< null_free(((imap_userdata_t*)ci->userData)->mailbox.seq_list);
< null_free(ci->userData);
<
---
> ci_cleanup(ci);
221,226c236,238
< fprintf(ci->tx, "* BYE Input contains invalid characters\r\n");
< close_cache();
<
< null_free(((imap_userdata_t*)ci->userData)->mailbox.seq_list);
< null_free(ci->userData);
<
---
> if ( ci_write( ci->tx, "* BYE Input contains invalid characters\r\n") )
> return EOF;
> ci_cleanup(ci);
245c257,258
< fprintf(ci->tx, "* BAD No tag specified\r\n");
---
> if ( ci_write(ci->tx, "* BAD No tag specified\r\n") )
> return EOF;
256,263c269,279
< if (strcmp(cpy, "yeah!") == 0)
< fprintf(ci->tx,"* YEAH dbmail ROCKS sunnyboy!\r\n");
< else
< {
< if (checktag(cpy))
< fprintf(ci->tx, "%s BAD No command specified\r\n",cpy);
< else
< fprintf(ci->tx, "* BAD Invalid tag specified\r\n");
---
> if (strcmp(cpy, "yeah!") == 0) {
> if ( ci_write(ci->tx,"* YEAH dbmail ROCKS sunnyboy!\r\n") )
> return EOF;
> } else {
> if (checktag(cpy)) {
> if ( ci_write(ci->tx, "%s BAD No command specified\r\n",cpy) )
> return EOF;
> } else {
> if ( ci_write(ci->tx, "* BAD Invalid tag specified\r\n") )
> return EOF;
> }
266c282
< }
---
> }
279c295,296
< fprintf(ci->tx, "* BAD Invalid tag specified\r\n");
---
> if ( ci_write(ci->tx, "* BAD Invalid tag specified\r\n") )
> return EOF;
301,304c318
< close_cache();
< null_free(((imap_userdata_t*)ci->userData)->mailbox.seq_list);
< null_free(ci->userData);
<
---
> ci_cleanup(ci);
311c325,326
< fprintf(ci->tx,"%s BAD invalid argument specified\r\n",tag);
---
> if ( ci_write(ci->tx,"%s BAD invalid argument specified\r\n",tag) )
> return EOF;
321c336,337
< fprintf(ci->tx,"%s BAD command not recognized\r\n",tag);
---
> if ( ci_write(ci->tx,"%s BAD command not recognized\r\n",tag) )
> return EOF;
378c394,395
< fprintf(ci->tx,"* BYE internal dbase error\r\n");
---
> if ( ci_write(ci->tx,"* BYE internal dbase error\r\n") )
> return EOF;
381,384c398,399
< close_cache();
< null_free(((imap_userdata_t*)ci->userData)->mailbox.seq_list);
< null_free(ci->userData);
<
---
> ci_cleanup(ci);
>
396c411,412
< fprintf(ci->tx, "* %u EXISTS\r\n", newmailbox.exists);
---
> if ( ci_write(ci->tx, "* %u EXISTS\r\n", newmailbox.exists) )
> return EOF;
400,402c416,420
< if (newmailbox.recent != ud->mailbox.recent)
< fprintf(ci->tx, "* %u RECENT\r\n", newmailbox.recent);
<
---
> if (newmailbox.recent != ud->mailbox.recent) {
> if ( ci_write(ci->tx, "* %u RECENT\r\n", newmailbox.recent) )
> return EOF;
> }
>
407,408c425,428
< if (this_was_noop)
< fprintf(ci->tx, "%s OK NOOP completed\r\n", tag);
---
> if (this_was_noop) {
> if ( ci_write(ci->tx, "%s OK NOOP completed\r\n", tag) )
> return EOF;
> }
419,424c439,442
< close_cache();
<
< null_free(((imap_userdata_t*)ci->userData)->mailbox.seq_list);
< null_free(ci->userData);
<
< fprintf(ci->tx,"%s OK completed\r\n",tag);
---
> ci_cleanup(ci);
>
> if ( ci_write(ci->tx,"%s OK completed\r\n",tag) )
> return EOF;