Discussion:
[tin 2.2.1] URL-patch and cleanups (was: [tin 2.2.1] snapshots)
Urs Janßen
2014-04-29 22:14:26 UTC
Permalink
the patch below should fit over the last snapshot and fixes several
unlikely issues besides updating the URL-regexp and allowing to edit
the urls.

=== modified file 'include/tin.h'
--- include/tin.h 2014-02-07 08:26:51 +0000
+++ include/tin.h 2014-04-20 12:27:38 +0000
@@ -691,19 +691,7 @@
* TODO: - split out ftp (only ftp allows username:passwd@, RFC 1738)?
* - test IDNA (RFC 3490) case
*/
-#if 0
-# if 0 /* this one is ok for IPv4 */
-# define URL_REGEX "\\b(?:https?|ftp|gopher)://(?:[^:@/\\s]*(?::[^:@/\\s]*)?@)?(?:(?:[^\\W_](?:(?:-(?!-)|[^\\W_]){0,61}[^\\W_])?\\.)+[a-z]{2,6}\\.?|localhost|(?:(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?))(?::\\d+)?(?:/[^)\\]\\>\"\\s]*|$|(?=[)\\]\\>\"\\s]))"
-# else /* this one should be IPv6 safe - test me! */
-# define URL_REGEX "\\b(?:https?|ftp|gopher)://(?:[^:@/\\s]*(?::[^:@/\\s]*)?@)?(?:(?:[^\\W_](?:(?:-(?!-)|[^\\W_]){0,61}[^\\W_])?\\.)+[a-z]{2,6}\\.?|localhost|(?:(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)|\\[(?:(?:[0-9A-F]{0,4}:){1,7}[0-9A-F]{1,4}|(?:[0-9A-F]{0,4}:){1,3}(?:(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?))\\])(?::\\d+)?(?:/[^)\\]\\>\"\\s]*|$|(?=[)\\]\\>\"\\s]))"
-# endif /* 0 */
-#else /* the following should be IDN safe */
-# if 0 /* this one is ok for IPv4 */
-# define URL_REGEX "\\b(?:https?|ftp|gopher)://(?:[^:@/\\s]*(?::[^:@/\\s]*)?@)?(?:(?:(?:[^\\W_](?:(?:-(?!-)|[^\\W_]){0,61}[^\\W_])?|xn--[^\\W_](?:-(?!-)|[^\\W_]){1,57}[^\\W_])\\.)+[a-z]{2,6}\\.?|localhost|(?:(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?))(?::\\d+)?(?:/[^)\\]\\>\"\\s]*|$|(?=[)\\]\\>\"\\s]))"
-# else /* this one should be IPv6 safe - test me! */
-# define URL_REGEX "\\b(?:https?|ftp|gopher)://(?:[^:@/\\s]*(?::[^:@/\\s]*)?@)?(?:(?:(?:[^\\W_](?:(?:-|[^\\W_]){0,61}(?<!---)[^\\W_])?|xn--[^\\W_](?:-(?!-)|[^\\W_]){1,57}[^\\W_])\\.)+[a-z]{2,6}\\.?|localhost|(?:(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)|\\[(?:(?:[0-9A-F]{0,4}:){1,7}[0-9A-F]{1,4}|(?:[0-9A-F]{0,4}:){1,3}(?:(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?))\\])(?::\\d+)?(?:/[^)\\]\\>\"\\s]*|$|(?=[)\\]\\>\"\\s]))"
-# endif /* 0 */
-#endif /* 0 */
+#define URL_REGEX "\\b(?:https?|ftp|gopher)://(?:[^:@/\\s]*(?::[^:@/\\s]*)?@)?(?:(?:(?:[^\\W_](?:(?:-|[^\\W_]){0,61}(?<!---)[^\\W_])?|xn--[^\\W_](?:-(?!-)|[^\\W_]){1,57}[^\\W_])\\.)+[a-z]{2,6}\\.?|localhost|(?:(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)|\\[(?:(?:[0-9A-F]{0,4}:){1,7}[0-9A-F]{1,4}|(?:[0-9A-F]{0,4}:){1,3}(?:(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?))\\])(?::\\d+)?(?(?=[^\\)\\]\\>\"\\s]*\\()(?:/[^\\]\\>\"\\s]*|$|(?=[)\\]\\>\"\\s]))|(?:/[^)\\]\\>\"\\s]*|$|(?=[)\\]\\>\"\\s])))"
/*
* case insensitive
* TOFO: check against RFC 2368
@@ -714,15 +702,8 @@
* case insensitive
* TODO: check against RFC 5538
*/
-#if 1 /* complex */
-# define NEWS_REGEX "\\b(?:s?news|nntp):(?:(?:(?://(?:(?:[^\\W_](?:(?:-|[^\\W_]){0,61}(?<!---)[^\\W_])?|xn--[^\\W_](?:-(?!-)|[^\\W_]){1,57}[^\\W_])\\.)+[a-z]{2,6}\\.?|localhost|(?:(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?))(?::\\d+)?(?(?=[/])[^()\\^\\[\\]{}\\|\\x00-\\x1f\\x7f\\s\"<>'\\\\:,;]+|$))|[^\\^\\[\\]{}\\|\\x00-\\x1f\\x7f\\s<>\"():,;\\\\'/]+)\\b"
-#else
-# if 1 /* less complex */
-# define NEWS_REGEX "\\b(?:s?news|nntp):[^\\s\\*@>]+(?(?=[@])[^\\s\\*@<>()\",/]+|[^\\s\\*<>()\":,/]+)\\b"
-# else
-# define NEWS_REGEX "\\b(?:s?news|nntp):[^\\s@]+[@.][^\\s@]+(?:$|(?=[\\s.><,\"/():]))\\b"
-# endif /* 1 */
-#endif /* 1 */
+#define NEWS_REGEX "\\b(?:s?news|nntp):(?:(?:(?://(?:(?:[^\\W_](?:(?:-|[^\\W_]){0,61}(?<!---)[^\\W_])?|xn--[^\\W_](?:-(?!-)|[^\\W_]){1,57}[^\\W_])\\.)+[a-z]{2,6}\\.?|localhost|(?:(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(?:2[0-4]\\d|25[0-5]|[01]?\\d\\d?))(?::\\d+)?(?(?=[/])[^()\\^\\[\\]{}\\|\\x00-\\x1f\\x7f\\s\"<>'\\\\:,;]+|$))|[^\\^\\[\\]{}\\|\\x00-\\x1f\\x7f\\s<>\"():,;\\\\'/]+)\\b"
+
#if 0 /* not implemented */
/*
* case insensitive
=== modified file 'src/config.c'
--- src/config.c 2013-11-28 00:36:11 +0000
+++ src/config.c 2014-04-25 22:53:20 +0000
@@ -1707,20 +1707,23 @@
;

buf = my_strdup(tmp);
+ tmp = buf;
+#if 0 /* my_strdup exits if alloc fails */
if (!buf) {
*new_argc = 0;
return NULL;
}
+#endif /* 0 */

new_argv = my_calloc(1, sizeof(char *));
+#if 0 /* my_calloc() exits if alloc fails */
if (!new_argv) {
free(buf);
*new_argc = 0;
return NULL;
}
-
- tmp = buf;
- new_argv[0] = NULL;
+#endif /* 0 */
+ /* new_argv[0] = NULL; */ /* done by calloc */

while (*tmp) {
if (!isspace((int) *tmp)) { /* found the beginning of a word */

=== modified file 'src/feed.c'
--- src/feed.c 2013-12-21 16:53:47 +0000
+++ src/feed.c 2014-04-26 06:35:32 +0000
@@ -607,8 +607,10 @@
}

set_xclick_off(); /* TODO: there is no corresponding set_xclick_on()? */
- thread_base = which_thread(respnum);
- stat_thread(thread_base, &sbuf);
+ if ((thread_base = which_thread(respnum)) >= 0)
+ stat_thread(thread_base, &sbuf);
+ else /* TODO: error message? */
+ return -1;

switch (type) {
case FEED_ARTICLE:

=== modified file 'src/page.c'
--- src/page.c 2014-02-07 08:26:51 +0000
+++ src/page.c 2014-04-26 06:29:07 +0000
@@ -1871,7 +1871,7 @@
int ch,
int curr_respnum)
{
- int num;
+ int i, num;

clear_message();

@@ -1880,7 +1880,10 @@
return -1;
}

- return find_response(which_thread(curr_respnum), num);
+ if ((i = which_thread(curr_respnum)) >= 0)
+ return find_response(i, num);
+ else
+ return -1;
}


@@ -2536,7 +2539,7 @@
t_url *lptr;

lptr = find_url(n);
- len = strlen(lptr->url);
+ len = strlen(lptr->url) << 1; /* double size; room for editing URL */
url = my_malloc(len + 1);
if (prompt_default_string("URL:", url, len, lptr->url, HIST_URL)) {
if (!*url) { /* Don't try and open nothing */

=== modified file 'src/post.c'
--- src/post.c 2014-02-07 08:26:51 +0000
+++ src/post.c 2014-04-24 09:51:43 +0000
@@ -4270,8 +4270,7 @@
if (line[0] != '\n' && line[0] != '#') {
if (line[0] != ' ' && line[0] != '\t') {
x_hdrs = my_realloc(x_hdrs, (num_x_hdrs + 1) * sizeof(char *));
- x_hdrs[num_x_hdrs] = my_malloc(strlen(line) + 1);
- strcpy(x_hdrs[num_x_hdrs++], line);
+ x_hdrs[num_x_hdrs++] = my_strdup(line);
} else {
if (!num_x_hdrs) /* folded line, but no previous header */
continue;

=== modified file 'src/read.c'
--- src/read.c 2013-11-28 00:36:11 +0000
+++ src/read.c 2014-04-29 22:02:09 +0000
@@ -178,7 +178,7 @@
t_bool header)
{
char *ptr;
- signed char c;
+ int c;
int i;
#ifdef NNTP_ABLE
t_bool check_dot_only_line;

=== modified file 'src/rfc2046.c'
--- src/rfc2046.c 2014-02-25 21:56:51 +0000
+++ src/rfc2046.c 2014-04-28 22:07:46 +0000
@@ -95,6 +95,9 @@
{
int i;

+ if (type == NULL)
+ return -1;
+
for (i = 0; content_types[i] != NULL; ++i) {
if (strcasecmp(type, content_types[i]) == 0)
return i;

=== modified file 'src/thread.c'
--- src/thread.c 2014-02-25 21:56:51 +0000
+++ src/thread.c 2014-04-29 16:33:21 +0000
@@ -1272,7 +1272,7 @@

if (curr_group->attribute->wrap_on_next_unread) {
n = base[0];
- while (n != cur_base_art) {
+ while (n != cur_base_art && n >= 0) {
if (((arts[n].status == ART_UNREAD) || (arts[n].status == ART_WILL_RETURN)) && arts[n].thread != ART_EXPIRED)
return n;

Loading...