On Thu, Feb 10, 2005 at 02:30:25PM +0100, Urs Jan�en wrote:
> anyway, attached is a diff against a plain tin-1.7.7er source which

next try...

urs
-- 
"Only whimps use tape backup: _real_ men just upload their important stuff
 on ftp, and let the rest of the world mirror it ;)" - Linus
--- tin-1.7.7/src/nntplib.c     2004-11-15 18:44:25.000000000 +0100
+++ tin-1.7.7/src/nntplib.c     2005-02-10 14:17:41.000000000 +0100
@@ -51,7 +51,8 @@
        static constext *xhdr_cmd = NULL;
        static constext *xhdr_cmds = "XHDR";
 #      endif /* 0 */
-       static t_bool have_list_extensions = FALSE;
+       enum extension_type { NO, LIST_EXTENSIONS, CAPABILITIES };
+       static int have_list_extensions = NO;
        /* Set so we don't reconnect just to QUIT */
        static t_bool quitting = FALSE;
 #endif /* NNTP_ABLE */
@@ -952,14 +953,9 @@
 
 #ifdef NNTP_ABLE
 /*
- * Try and use LIST EXTENSIONS here. Get this list before issuing
- * other NNTP commands because the correct methods may be
- * mentioned in the list of extensions.
- * Possible extensions include:
- * - HDR & LIST HEADERS
- * - OVER [MSGID] & LIST OVERVIEW.FMT
- * - LISTGROUP
- * - STARTTLS
+ * Try and use CAPABILITIES/LIST EXTENSIONS here. Get this list before
+ * issuing other NNTP commands because the correct methods may be mentioned
+ * in the list of extensions.
  *
  * Sets up: have_list_extensions, xover_cmd, (xhdr_cmd)
  */
@@ -971,47 +967,109 @@
        char *ptr;
        int i;
 
-       if ((fp = nntp_command("LIST EXTENSIONS", OK_EXTENSIONS, NULL, 0)) == 
NULL)
-               return;
-
-       have_list_extensions = TRUE;
+#      if 1 /* "CAPABILITIES" will replace "LIST EXTENSIONS" */
+       if ((fp = nntp_command("CAPABILITIES", INF_CAPABILITIES, NULL, 0)) != 
NULL) {
+               int cap_version = -1;
 
-       while ((ptr = tin_fgets(fp, FALSE)) != NULL) {
-               /*
-                * Check for (X)OVER
-                * XOVER should not be listed in EXTENSIONS (but sometimes is)
-                * checking for it if OVER is not found does no harm.
-                */
-               if (!xover_cmd) {
-                       for (i = 1; i >= 0; i--) {
-                               if (strcmp(ptr, &xover_cmds[i]) == 0) {
-                                       xover_cmd = &xover_cmds[i];
-                                       break;
-                               }
+               have_list_extensions = CAPABILITIES;
+               while ((ptr = tin_fgets(fp, FALSE)) != NULL) {
+#              ifdef DEBUG
+                       debug_nntp("<<<", ptr);
+#              endif /* DEBUG */
+                       /* look for version number */
+                       if (cap_version == -1 && have_list_extensions == 
CAPABILITIES) {
+                               if (!strncasecmp(ptr, "VERSION", 7))
+                                       cap_version = atoi(ptr + 8);
                        }
+                       /* we currently only support CAPABILITIES VERSION 2 */
+                       if (cap_version == 2) {
+                               /*
+                                * Check for (X)OVER
+                                * XOVER should not be listed in CAPABILITIES
+                                * but checking for it if OVER is not found 
does no harm.
+                                */
+                               if (!xover_cmd) {
+                                       for (i = 1; i >= 0; i--) {
+                                               if (strcasecmp(ptr, 
&xover_cmds[i]) == 0) {
+                                                       xover_cmd = 
&xover_cmds[i];
+                                                       break;
+                                               }
+                                       }
+                               }
+                               /*
+                                * LIST, READER, SASL, STARTTLS, STREAMING, 
AUTHINFO, HDR, IHAVE
+                                * IMPLEMENTATION, (MODE-READER)
+                                */
+                       } else
+                               have_list_extensions = NO;
                }
-#              if 0 /* currently not used */
-               /*
-                * Check for (X)HDR
-                * XHDR should not be listed in EXTENSIONS (but sometimes is)
-                * checking for it if HDR is not found does no harm.
-                */
-               if (!xhdr_cmd) {
-                       for (i = 1; i >= 0; i--) {
-                               if (strcmp(ptr, &xhdr_cmds[i]) == 0) {
-                                       xhdr_cmd = &xhdr_cmds[i];
-                                       break;
+       }
+#      endif /* 1 */
+
+       if (have_list_extensions == NO) {
+               char buf[NNTP_STRLEN];
+
+               buf[0] = '\0';
+               fp = nntp_command("LIST EXTENSIONS", OK_EXTENSIONS, buf, 
sizeof(buf));
+               if (!fp) {
+                       /*
+                        * TODO: this is a dirty hack to work around a bug in
+                        *       Netscape-Collabra/3.52. A better solution would
+                        *       be to check for the (wrong) return code 
(should be 202,
+                        *       but is 215), but unfortunately nntp_command() 
throws
+                        *       away that data and get_only_respcode() doesn't 
do
+                        *       authentication if required...
+                        *       When "LIST EXTENSIONS" is repalced by 
"CAPABILITIES" this
+                        *       ugly code can be removed.
+                        */
+                       if (!strncasecmp(buf, " Extensions supported by 
server.", 32)) {
+                               /* remove pending data on the socket */
+                               while ((ptr = tin_fgets(FAKE_NNTP_FP, FALSE)) 
!= NULL)
+                                       ;
+                       }
+               } else {
+                       have_list_extensions = LIST_EXTENSIONS;
+                       while ((ptr = tin_fgets(fp, FALSE)) != NULL) {
+#      ifdef DEBUG
+                               debug_nntp("<<<", ptr);
+#      endif /* DEBUG */
+                               /*
+                                * Check for (X)OVER
+                                * XOVER should not be listed in EXTENSIONS 
(but sometimes is)
+                                * checking for it if OVER is not found does no 
harm.
+                                */
+                               if (!xover_cmd) {
+                                       for (i = 1; i >= 0; i--) {
+                                               if (strcmp(ptr, &xover_cmds[i]) 
== 0) {
+                                                       xover_cmd = 
&xover_cmds[i];
+                                                       break;
+                                               }
+                                       }
+                               }
+#      if 0 /* currently not used */
+                               /*
+                                * Check for (X)HDR
+                                * XHDR should not be listed in EXTENSIONS (but 
sometimes is)
+                                * checking for it if HDR is not found does no 
harm.
+                                */
+                               if (!xhdr_cmd) {
+                                       for (i = 1; i >= 0; i--) {
+                                               if (strcmp(ptr, &xhdr_cmds[i]) 
== 0) {
+                                                       xhdr_cmd = 
&xhdr_cmds[i];
+                                                       break;
+                                               }
+                                       }
                                }
+#      endif /* 0 */
+                                /*
+                                 * additional checks for
+                                 * - LISTGROUP
+                                 * - LIST OVERVIEW.FMT
+                                 * - LIST HEADERS
+                                 * go here whenever they are needed
+                                 */
                        }
                }
-#              endif /* 0 */
-                /*
-                 * additional checks for
-                 * - LISTGROUP
-                 * - LIST OVERVIEW.FMT
-                 * - LIST HEADERS
-                 * go here whenever they are needed
-                 */
        }
        return;
 }
@@ -1119,9 +1177,16 @@
        }
 
        /*
-        * Switch INN into NNRP mode with 'mode reader'
+        * Find out which NNTP extensions are available
+        * TODO: The authentication method required may be mentioned in the 
list of
+        *       extensions. (For details about authentication methods, see
+        *       draft-newman-nntpext-auth-01.txt).
         */
+       check_extensions();
 
+       /*
+        * Switch INN into NNRP mode with 'mode reader'
+        */
 #      ifdef DEBUG
        debug_nntp("nntp_open", "mode reader");
 #      endif /* DEBUG */
@@ -1170,14 +1235,6 @@
        }
 
        /*
-        * Find out which NNTP extensions are available
-        * TODO: The authentication method required may be mentioned in the 
list of
-        *       extensions. (For details about authentication methods, see
-        *       draft-newman-nntpext-auth-01.txt).
-        */
-       check_extensions();
-
-       /*
         * If the user wants us to authenticate on connection startup, do it 
now.
         * Some news servers return "201 no posting" first, but after successful
         * authentication you get a "200 posting allowed". To find out if we are
@@ -1261,7 +1318,7 @@
         * (successor of XOVER as of latest NNTP Draft (Jan 2002)
         * We have to check that we _don't_ get an ERR_COMMAND
         */
-       if (!have_list_extensions) {
+       if (have_list_extensions == NO) {
                for (i = 0; i < 2; i++) {
                        if (!nntp_command(&xover_cmds[i], ERR_COMMAND, NULL, 
0)) {
                                xover_cmd = &xover_cmds[i];
--- tin-1.7.7/include/nntplib.h 2004-11-15 18:44:23.000000000 +0100
+++ tin-1.7.7/include/nntplib.h 2005-01-19 11:20:56.000000000 +0100
@@ -88,6 +88,7 @@
 #endif /* 0 */
 
 #define        INF_HELP                100     /* Help text on way */
+#define        INF_CAPABILITIES        101     /* Capability list follows */
 #define        INF_AUTH                180     /* Authorization capabilities */
 #define        INF_DEBUG               199     /* Debug output */
 

Reply via email to