~ubuntu-branches/ubuntu/vivid/tin/vivid

« back to all changes in this revision

Viewing changes to src/newsrc.c

  • Committer: Package Import Robot
  • Author(s): Marco d'Itri
  • Date: 2012-01-06 15:04:11 UTC
  • mfrom: (1.2.17)
  • Revision ID: package-import@ubuntu.com-20120106150411-vftxaked1sscxt1t
Tags: 1:2.1.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *  Module    : newsrc.c
4
4
 *  Author    : I. Lea & R. Skrenta
5
5
 *  Created   : 1991-04-01
6
 
 *  Updated   : 2011-04-16
 
6
 *  Updated   : 2011-11-06
7
7
 *  Notes     : ArtCount = (ArtMax - ArtMin) + 1  [could have holes]
8
8
 *
9
 
 * Copyright (c) 1991-2011 Iain Lea <iain@bricbrac.de>, Rich Skrenta <skrenta@pbm.com>
 
9
 * Copyright (c) 1991-2012 Iain Lea <iain@bricbrac.de>, Rich Skrenta <skrenta@pbm.com>
10
10
 * All rights reserved.
11
11
 *
12
12
 * Redistribution and use in source and binary forms, with or without
55
55
 */
56
56
static FILE *open_subscription_fp(void);
57
57
static char *parse_newsrc_line(char *line, int *sub);
58
 
static char *parse_subseq(struct t_group *group, char *seq, long *low, long *high, int *sum);
59
 
static char *parse_get_seq(char *seq, long *low, long *high);
 
58
static char *parse_subseq(struct t_group *group, char *seq, t_artnum *low, t_artnum *high, t_artnum *sum);
 
59
static char *parse_get_seq(char *seq, t_artnum *low, t_artnum *high);
60
60
static int write_newsrc_line(FILE *fp, char *line);
61
61
static t_bool create_newsrc(char *newsrc_file);
62
62
static void auto_subscribe_groups(char *newsrc_file);
404
404
        char *tin_spooldir,
405
405
        char *groupname,
406
406
        int grouptype,
407
 
        long *art_count,
408
 
        long *art_max,
409
 
        long *art_min)
 
407
        t_artnum *art_count,
 
408
        t_artnum *art_max,
 
409
        t_artnum *art_min)
410
410
{
411
411
        DIR *dir;
412
412
        DIR_BUF *direntry;
413
 
        long artnum;
 
413
        t_artnum artnum;
414
414
 
415
415
        if (read_news_via_nntp && grouptype == GROUP_TYPE_NEWS) {
416
416
#ifdef NNTP_ABLE
425
425
 
426
426
                switch (get_respcode(line, sizeof(line))) {
427
427
                        case OK_GROUP:
428
 
                                if (sscanf(line, "%ld %ld %ld", art_count, art_min, art_max) != 3)
 
428
                                if (sscanf(line, "%"T_ARTNUM_SFMT" %"T_ARTNUM_SFMT" %"T_ARTNUM_SFMT, art_count, art_min, art_max) != 3)
429
429
                                        error_message(2, _(txt_error_invalid_response_to_group), line);
430
430
                                break;
431
431
 
432
432
                        case ERR_NOGROUP:
433
 
                                *art_count = 0L;
434
 
                                *art_min = 1L;
435
 
                                *art_max = 0L;
 
433
                                *art_count = T_ARTNUM_CONST(0);
 
434
                                *art_min = T_ARTNUM_CONST(1);
 
435
                                *art_max = T_ARTNUM_CONST(0);
436
436
                                return -ERR_NOGROUP;
437
437
 
438
438
                        case ERR_ACCESS:
455
455
#endif /* NNTP_ABLE */
456
456
        } else {
457
457
                char group_path[PATH_LEN];
458
 
                *art_count = 0L;
459
 
                *art_min = 0L;
460
 
                *art_max = 0L;
 
458
                *art_count = T_ARTNUM_CONST(0);
 
459
                *art_min = T_ARTNUM_CONST(0);
 
460
                *art_max = T_ARTNUM_CONST(0);
461
461
 
462
462
                make_base_group_path(tin_spooldir, groupname, group_path, sizeof(group_path));
463
463
 
464
464
                if ((dir = opendir(group_path)) != NULL) {
465
465
                        while ((direntry = readdir(dir)) != NULL) {
466
 
                                artnum = atol(direntry->d_name); /* should be '\0' terminated... */
467
 
                                if (artnum >= 1L) {
 
466
                                artnum = atoartnum(direntry->d_name); /* should be '\0' terminated... */
 
467
                                if (artnum >= T_ARTNUM_CONST(1)) {
468
468
                                        if (artnum > *art_max) {
469
469
                                                *art_max = artnum;
470
 
                                                if (*art_min == 0L)
 
470
                                                if (*art_min == T_ARTNUM_CONST(0))
471
471
                                                        *art_min = artnum;
472
472
                                        } else if (artnum < *art_min)
473
473
                                                *art_min = artnum;
475
475
                                }
476
476
                        }
477
477
                        CLOSEDIR(dir);
478
 
                        if (*art_min == 0L)
479
 
                                *art_min = 1L;
 
478
                        if (*art_min == T_ARTNUM_CONST(0))
 
479
                                *art_min = T_ARTNUM_CONST(1);
480
480
                } else {
481
 
                        *art_min = 1L;
 
481
                        *art_min = T_ARTNUM_CONST(1);
482
482
                        return -1;
483
483
                }
484
484
        }
494
494
get_subscribe_info(
495
495
        struct t_group *grp)
496
496
{
497
 
        long oldmin = grp->xmin;
498
 
        long oldmax = grp->xmax;
 
497
        t_artnum oldmin = grp->xmin;
 
498
        t_artnum oldmax = grp->xmax;
499
499
 
500
500
        group_get_art_info(grp->spooldir, grp->name, grp->type, &grp->count, &grp->xmax, &grp->xmin);
501
501
 
502
502
        if (grp->newsrc.num_unread > grp->count) {
503
503
#ifdef DEBUG
504
504
                if (debug & DEBUG_NEWSRC) { /* TODO: is this the right debug-level? */
505
 
                        my_printf(cCRLF "Unread WRONG %s unread=[%ld] count=[%ld]", grp->name, grp->newsrc.num_unread, grp->count);
 
505
                        my_printf(cCRLF "Unread WRONG %s unread=[%"T_ARTNUM_PFMT"] count=[%"T_ARTNUM_PFMT"]", grp->name, grp->newsrc.num_unread, grp->count);
506
506
                        my_flush();
507
507
                }
508
508
#endif /* DEBUG */
513
513
                expand_bitmap(grp, 0);
514
514
#ifdef DEBUG
515
515
                if (debug & DEBUG_NEWSRC) { /* TODO: is this the right debug-level? */
516
 
                        my_printf(cCRLF "Min/Max DIFF %s old=[%ld-%ld] new=[%ld-%ld]", grp->name, oldmin, oldmax, grp->xmin, grp->xmax);
 
516
                        my_printf(cCRLF "Min/Max DIFF %s old=[%"T_ARTNUM_PFMT"-%"T_ARTNUM_PFMT"] new=[%"T_ARTNUM_PFMT"-%"T_ARTNUM_PFMT"]", grp->name, oldmin, oldmax, grp->xmin, grp->xmax);
517
517
                        my_flush();
518
518
                }
519
519
#endif /* DEBUG */
601
601
        FILE *fp;
602
602
        FILE *newfp;
603
603
        char *line;
604
 
        int sub;
605
 
        long i;
 
604
        int sub, i;
606
605
 
607
606
        if (!no_write && (newfp = fopen(newnewsrc, "w")) != NULL) {
608
607
                if (newsrc_mode)
710
709
grp_mark_unread(
711
710
        struct t_group *group)
712
711
{
713
 
        int bitlength;
 
712
        t_artnum bitlength;
714
713
        t_bitmap *newbitmap = (t_bitmap *) 0;
715
714
 
716
715
#ifdef DEBUG
736
735
        group->newsrc.xbitlen = bitlength;
737
736
 
738
737
        if (bitlength)
739
 
                NSETRNG1(group->newsrc.xbitmap, 0L, bitlength - 1L);
 
738
                NSETRNG1(group->newsrc.xbitmap, T_ARTNUM_CONST(0), bitlength - T_ARTNUM_CONST(1));
740
739
 
741
740
#ifdef DEBUG
742
741
        if (debug & DEBUG_NEWSRC)
788
787
        char *seq)
789
788
{
790
789
        char *ptr;
791
 
        int sum = 0;
792
 
        long low = 0L;
793
 
        long high = 0L;
794
 
        long min, max;
 
790
        t_artnum sum = T_ARTNUM_CONST(0);
 
791
        t_artnum low = T_ARTNUM_CONST(0);
 
792
        t_artnum high = T_ARTNUM_CONST(0);
 
793
        t_artnum min, max;
795
794
        t_bool gotseq = FALSE;
796
795
 
797
796
        /*
834
833
                group->newsrc.xbitlen = (max - min) + 1;
835
834
                if (group->newsrc.xbitlen > 0) {
836
835
                        group->newsrc.xbitmap = my_malloc(BITS_TO_BYTES(group->newsrc.xbitlen));
837
 
                        NSETRNG1(group->newsrc.xbitmap, 0L, group->newsrc.xbitlen - 1L);
 
836
                        NSETRNG1(group->newsrc.xbitmap, T_ARTNUM_CONST(0), group->newsrc.xbitlen - T_ARTNUM_CONST(1));
838
837
                }
839
838
 
840
839
                if (min <= high) {
860
859
                group->newsrc.xbitlen = (group->newsrc.xmax - group->newsrc.xmin) + 1;
861
860
                if (group->newsrc.xbitlen > 0) {
862
861
                        group->newsrc.xbitmap = my_malloc(BITS_TO_BYTES(group->newsrc.xbitlen));
863
 
                        NSETRNG1(group->newsrc.xbitmap, 0L, group->newsrc.xbitlen - 1L);
 
862
                        NSETRNG1(group->newsrc.xbitmap, T_ARTNUM_CONST(0), group->newsrc.xbitlen - T_ARTNUM_CONST(1));
864
863
                }
865
864
/*
866
 
wait_message(2, "BITMAP Grp=[%s] MinMax=[%ld-%ld] Len=[%ld]\n",
 
865
wait_message(2, "BITMAP Grp=[%s] MinMax=[%"T_ARTNUM_PFMT"-%"T_ARTNUM_PFMT"] Len=[%"T_ARTNUM_PFMT"]\n",
867
866
        group->name, group->xmin, group->xmax, group->newsrc.xbitlen);
868
867
*/
869
868
        }
874
873
                if (group->newsrc.xmax > high)
875
874
                        sum += group->newsrc.xmax - high;
876
875
        } else
877
 
                sum = (int) ((group->count >= 0) ? group->count : ((group->newsrc.xmax - group->newsrc.xmin) + 1));
 
876
                sum = (group->count >= 0) ? group->count : ((group->newsrc.xmax - group->newsrc.xmin) + 1);
878
877
 
879
878
        group->newsrc.num_unread = sum;
880
879
#ifdef DEBUG
896
895
parse_subseq(
897
896
        struct t_group *group,
898
897
        char *seq,
899
 
        long *low,
900
 
        long *high,
901
 
        int *sum)
 
898
        t_artnum *low,
 
899
        t_artnum *high,
 
900
        t_artnum *sum)
902
901
{
903
 
        long bitmin;
904
 
        long bitmax;
905
 
        long last_high = *high;
 
902
        t_artnum bitmin;
 
903
        t_artnum bitmax;
 
904
        t_artnum last_high = *high;
906
905
 
907
906
        seq = parse_get_seq(seq, low, high);
908
907
 
921
920
                if (bitmin >= 0) {
922
921
                        if (*high > group->newsrc.xmax) {
923
922
                                /* We trust .newsrc's max. */
924
 
                                long bitlen;
 
923
                                t_artnum bitlen;
925
924
                                t_bitmap *newbitmap;
926
925
 
927
926
                                group->newsrc.xmax = *high;
951
950
 
952
951
                if (bitmax > group->newsrc.xmax) {
953
952
                        /* We trust .newsrc's max. */
954
 
                        long bitlen;
 
953
                        t_artnum bitlen;
955
954
                        t_bitmap *newbitmap;
956
955
 
957
956
                        group->newsrc.xmax = bitmax;
983
982
static char *
984
983
parse_get_seq(
985
984
        char *seq,
986
 
        long *low,
987
 
        long *high)
 
985
        t_artnum *low,
 
986
        t_artnum *high)
988
987
{
989
 
        *low = strtol(seq, &seq, 10);
 
988
        *low = strtoartnum(seq, &seq, 10);
990
989
 
991
990
        if (*seq == '-') {      /* Range of articles */
992
991
                seq++;
993
 
                *high = strtol(seq, &seq, 10);
 
992
                *high = strtoartnum(seq, &seq, 10);
994
993
        } else  /* Single article */
995
994
                *high = *low;
996
995
 
1007
1006
void
1008
1007
parse_unread_arts(
1009
1008
        struct t_group *group,
1010
 
        long min)
 
1009
        t_artnum min)
1011
1010
{
1012
1011
        int i;
1013
 
        long unread = 0;
1014
 
        long bitmin, bitmax;
 
1012
        t_artnum unread = T_ARTNUM_CONST(0);
 
1013
        t_artnum bitmin, bitmax;
1015
1014
        t_bitmap *newbitmap = (t_bitmap *) 0;
1016
1015
 
1017
1016
        bitmin = group->newsrc.xmin;
1029
1028
 
1030
1029
        if (group->newsrc.xmax >= bitmin) {
1031
1030
                newbitmap = my_malloc(BITS_TO_BYTES(group->newsrc.xmax - bitmin + 1));
1032
 
                NSETRNG0(newbitmap, 0L, group->newsrc.xmax - bitmin);
 
1031
                NSETRNG0(newbitmap, T_ARTNUM_CONST(0), group->newsrc.xmax - bitmin);
1033
1032
        }
1034
1033
 
1035
1034
        /*
1037
1036
         * of all articles below the new minimum
1038
1037
         */
1039
1038
        if (min > 0 && newbitmap) {
1040
 
                long j, tmp_bitmax;
 
1039
                t_artnum j, tmp_bitmax;
1041
1040
 
1042
1041
                tmp_bitmax = (bitmax < min) ? bitmax : min;
1043
1042
                for (j = bitmin; j < tmp_bitmax; j++) {
1092
1091
        FILE *fp,
1093
1092
        struct t_group *group)
1094
1093
{
1095
 
        long artnum;
1096
 
        long i;
 
1094
        t_artnum artnum;
 
1095
        t_artnum i;
1097
1096
        t_bool flag = FALSE;
1098
1097
 
1099
1098
#ifdef DEBUG
1105
1104
 
1106
1105
        if (group->count == 0 || group->xmin > group->xmax) {
1107
1106
                if (group->newsrc.xmax > 1)
1108
 
                        fprintf(fp, "1-%ld", group->newsrc.xmax);
 
1107
                        fprintf(fp, "1-%"T_ARTNUM_PFMT, group->newsrc.xmax);
1109
1108
 
1110
1109
                fprintf(fp, "\n");
1111
1110
                fflush(fp);
1122
1121
                        if (group->newsrc.xbitmap && NTEST(group->newsrc.xbitmap, i - group->newsrc.xmin) == ART_READ) {
1123
1122
                                if (flag) {
1124
1123
                                        artnum = i;
1125
 
                                        fprintf(fp, ",%ld", i);
 
1124
                                        fprintf(fp, ",%"T_ARTNUM_PFMT, i);
1126
1125
                                } else {
1127
1126
                                        artnum = 1;
1128
1127
                                        flag = TRUE;
1132
1131
                                        i++;
1133
1132
 
1134
1133
                                if (artnum != i)
1135
 
                                        fprintf(fp, "-%ld", i);
 
1134
                                        fprintf(fp, "-%"T_ARTNUM_PFMT, i);
1136
1135
 
1137
1136
                        } else if (!flag) {
1138
1137
                                flag = TRUE;
1140
1139
                                        fprintf(fp, "1");
1141
1140
 
1142
1141
                                        if (group->newsrc.xmin > 2)
1143
 
                                                fprintf(fp, "-%ld", group->newsrc.xmin - 1);
 
1142
                                                fprintf(fp, "-%"T_ARTNUM_PFMT, group->newsrc.xmin - 1);
1144
1143
 
1145
1144
                                }
1146
1145
                        }
1155
1154
                fprintf(fp, "1");
1156
1155
 
1157
1156
                if (group->newsrc.xmin > 2)
1158
 
                        fprintf(fp, "-%ld", group->newsrc.xmin - 1);
 
1157
                        fprintf(fp, "-%"T_ARTNUM_PFMT, group->newsrc.xmin - 1);
1159
1158
 
1160
1159
#ifdef DEBUG
1161
1160
                if (debug & DEBUG_NEWSRC)
1424
1423
void
1425
1424
expand_bitmap(
1426
1425
        struct t_group *group,
1427
 
        long min)
 
1426
        t_artnum min)
1428
1427
{
1429
 
        long bitlen;
1430
 
        long first;
1431
 
        long tmp;
1432
 
        long max;
 
1428
        t_artnum bitlen;
 
1429
        t_artnum first;
 
1430
        t_artnum tmp;
 
1431
        t_artnum max;
1433
1432
        t_bool need_full_copy = FALSE;
1434
1433
 
1435
1434
        /* calculate new max */
1471
1470
        } else if (group->newsrc.xbitmap == NULL) {
1472
1471
                group->newsrc.xbitmap = my_malloc(BITS_TO_BYTES(bitlen));
1473
1472
                if (group->newsrc.xmin > first)
1474
 
                        NSETRNG0(group->newsrc.xbitmap, 0L, group->newsrc.xmin - first - 1L);
 
1473
                        NSETRNG0(group->newsrc.xbitmap, T_ARTNUM_CONST(0), group->newsrc.xmin - first - T_ARTNUM_CONST(1));
1475
1474
                if (bitlen > group->newsrc.xmin - first)
1476
1475
                        NSETRNG1(group->newsrc.xbitmap, group->newsrc.xmin - first, bitlen - 1);
1477
1476
#ifdef DEBUG
1493
1492
                /* Mark earlier articles as read, updating num_unread */
1494
1493
 
1495
1494
                if (first < group->newsrc.xmin) {
1496
 
                        NSETRNG0(newbitmap, 0L, group->newsrc.xmin - first - 1L);
 
1495
                        NSETRNG0(newbitmap, T_ARTNUM_CONST(0), group->newsrc.xmin - first - T_ARTNUM_CONST(1));
1497
1496
                }
1498
1497
 
1499
1498
                for (tmp = group->newsrc.xmin; tmp < min; tmp++) {
1530
1529
                /* Mark earlier articles as read, updating num_unread */
1531
1530
 
1532
1531
                if (first < group->newsrc.xmin) {
1533
 
                        NSETRNG0(newbitmap, 0L, group->newsrc.xmin - first - 1L);
 
1532
                        NSETRNG0(newbitmap, T_ARTNUM_CONST(0), group->newsrc.xmin - first - T_ARTNUM_CONST(1));
1534
1533
                }
1535
1534
 
1536
1535
                for (tmp = group->newsrc.xmin; tmp < min; tmp++) {