1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
|
/* ngdata.c
*/
/* This software is copyrighted as detailed in the LICENSE file. */
#include "EXTERN.h"
#include "common.h"
#include "list.h"
#include "trn.h"
#include "hash.h"
#include "cache.h"
#include "bits.h"
#include "head.h"
#include "rthread.h"
#include "rt-select.h"
#include "ng.h"
#include "intrp.h"
#include "kfile.h"
#include "final.h"
#include "term.h"
#include "env.h"
#include "util.h"
#include "util2.h"
#include "ndir.h"
#ifdef SCORE
#include "score.h"
#endif
#ifdef SCAN_ART
#include "scan.h"
#include "scanart.h"
#endif
#include "INTERN.h"
#include "ngdata.h"
#include "ngdata.ih"
#include "EXTERN.h"
#include "nntpclient.h"
#include "datasrc.h"
#include "nntp.h"
#include "rcstuff.h"
#include "rcln.h"
void
ngdata_init()
{
;
}
/* set current newsgroup */
void
set_ng(np)
NGDATA* np;
{
ngptr = np;
if (ngptr)
set_ngname(ngptr->rcline);
}
int
access_ng()
{
#ifdef SUPPORT_NNTP
ART_NUM old_first = ngptr->abs1st;
if (datasrc->flags & DF_REMOTE) {
int ret = nntp_group(ngname,ngptr);
if (ret == -2)
return -2;
if (ret <= 0) {
ngptr->toread = TR_BOGUS;
return 0;
}
if ((lastart = getngsize(ngptr)) < 0) /* Impossible... */
return 0;
absfirst = ngptr->abs1st;
if (absfirst > old_first)
checkexpired(ngptr,absfirst);
}
else
#endif
{
if (eaccess(ngdir,5)) { /* directory read protected? */
if (eaccess(ngdir,0)) {
# ifdef VERBOSE
IF(verbose)
printf("\nNewsgroup %s does not have a spool directory!\n",
ngname) FLUSH;
ELSE
# endif
# ifdef TERSE
printf("\nNo spool for %s!\n",ngname) FLUSH;
# endif
termdown(2);
} else {
# ifdef VERBOSE
IF(verbose)
printf("\nNewsgroup %s is not currently accessible.\n",
ngname) FLUSH;
ELSE
# endif
# ifdef TERSE
printf("\n%s not readable.\n",ngname) FLUSH;
# endif
termdown(2);
}
/* make this newsgroup temporarily invisible */
ngptr->toread = TR_NONE;
return 0;
}
/* chdir to newsgroup subdirectory */
if (chdir(ngdir)) {
printf(nocd,ngdir) FLUSH;
return 0;
}
if ((lastart = getngsize(ngptr)) < 0) /* Impossible... */
return 0;
absfirst = ngptr->abs1st;
}
dmcount = 0;
missing_count = 0;
in_ng = TRUE; /* tell the world we are here */
build_cache();
return 1;
}
void
chdir_newsdir()
{
if (chdir(datasrc->spool_dir) || (
#ifdef SUPPORT_NNTP
!(datasrc->flags & DF_REMOTE) &&
#endif
chdir(ngdir))) {
printf(nocd,ngdir) FLUSH;
sig_catcher(0);
}
}
void
grow_ng(newlast)
ART_NUM newlast;
{
ART_NUM tmpfirst;
forcegrow = FALSE;
if (newlast > lastart) {
ART_NUM tmpart = art;
ngptr->toread += (ART_UNREAD)(newlast-lastart);
tmpfirst = lastart+1;
#ifdef SCAN_ART
/* Increase the size of article scan arrays. */
sa_grow(lastart,newlast);
#endif
do {
lastart++;
article_ptr(lastart)->flags |= AF_EXISTS|AF_UNREAD;
} while (lastart < newlast);
article_list->high = lastart;
thread_grow();
#ifdef SCORE
/* Score all new articles now just in case they weren't done above. */
sc_fill_scorelist(tmpfirst,newlast);
#endif
#ifdef KILLFILES
#ifdef VERBOSE
IF(verbose)
sprintf(buf,
"%ld more article%s arrived -- processing memorized commands...\n\n",
(long)(lastart - tmpfirst + 1),
(lastart > tmpfirst ? "s have" : " has" ) );
ELSE /* my, my, how clever we are */
#endif
#ifdef TERSE
strcpy(buf, "More news -- auto-processing...\n\n");
#endif
termdown(2);
if (kf_state & KFS_NORMAL_LINES) {
bool forcelast_save = forcelast;
ARTICLE* artp_save = artp;
kill_unwanted(tmpfirst,buf,TRUE);
artp = artp_save;
forcelast = forcelast_save;
}
#endif
art = tmpart;
}
}
static int
ngorder_number(npp1, npp2)
register NGDATA** npp1;
register NGDATA** npp2;
{
return (int)((*npp1)->num - (*npp2)->num) * sel_direction;
}
static int
ngorder_groupname(npp1, npp2)
register NGDATA** npp1;
register NGDATA** npp2;
{
return strcaseCMP((*npp1)->rcline, (*npp2)->rcline) * sel_direction;
}
static int
ngorder_count(npp1, npp2)
register NGDATA** npp1;
register NGDATA** npp2;
{
int eq;
if ((eq = (int)((*npp1)->toread - (*npp2)->toread)) != 0)
return eq * sel_direction;
return (int)((*npp1)->num - (*npp2)->num);
}
/* Sort the newsgroups into the chosen order.
*/
void
sort_newsgroups()
{
register NGDATA* np;
register int i;
NGDATA** lp;
NGDATA** ng_list;
int (*sort_procedure)();
/* If we don't have at least two newsgroups, we're done! */
if (!first_ng || !first_ng->next)
return;
switch (sel_sort) {
case SS_NATURAL:
default:
sort_procedure = ngorder_number;
break;
case SS_STRING:
sort_procedure = ngorder_groupname;
break;
case SS_COUNT:
sort_procedure = ngorder_count;
break;
}
ng_list = (NGDATA**)safemalloc(newsgroup_cnt * sizeof (NGDATA*));
for (lp = ng_list, np = first_ng; np; np = np->next)
*lp++ = np;
assert(lp - ng_list == newsgroup_cnt);
qsort(ng_list, newsgroup_cnt, sizeof (NGDATA*), sort_procedure);
first_ng = np = ng_list[0];
np->prev = NULL;
for (i = newsgroup_cnt, lp = ng_list; --i; lp++) {
lp[0]->next = lp[1];
lp[1]->prev = lp[0];
}
last_ng = lp[0];
last_ng->next = NULL;
free((char*)ng_list);
}
void
ng_skip()
{
#ifdef SUPPORT_NNTP
if (datasrc->flags & DF_REMOTE) {
ART_NUM artnum;
clear();
# ifdef VERBOSE
IF(verbose)
fputs("Skipping unavailable article\n",stdout);
ELSE
# endif /* VERBOSE */
# ifdef TERSE
fputs("Skipping\n",stdout);
# endif /* TERSE */
termdown(1);
if (novice_delays) {
pad(just_a_sec/3);
sleep(1);
}
art = article_next(art);
artp = article_ptr(art);
do {
/* tries to grab PREFETCH_SIZE XHDRS, flagging missing articles */
(void) fetchsubj(art, FALSE);
artnum = art+PREFETCH_SIZE-1;
if (artnum > lastart)
artnum = lastart;
while (art <= artnum) {
if (artp->flags & AF_EXISTS)
return;
art = article_next(art);
artp = article_ptr(art);
}
} while (art <= lastart);
}
else
#endif
{
if (errno != ENOENT) { /* has it not been deleted? */
clear();
# ifdef VERBOSE
IF(verbose)
printf("\n(Article %ld exists but is unreadable.)\n",(long)art)
FLUSH;
ELSE
# endif
# ifdef TERSE
printf("\n(%ld unreadable.)\n",(long)art) FLUSH;
# endif
termdown(2);
if (novice_delays) {
pad(just_a_sec);
sleep(2);
}
}
inc_art(selected_only,FALSE); /* try next article */
}
}
/* find the maximum article number of a newsgroup */
ART_NUM
getngsize(gp)
register NGDATA* gp;
{
register int len;
register char* nam;
char tmpbuf[LBUFLEN];
long last, first;
char ch;
nam = gp->rcline;
len = gp->numoffset - 1;
if (!find_actgrp(gp->rc->datasrc,tmpbuf,nam,len,gp->ngmax)) {
if (gp->subscribechar == ':') {
gp->subscribechar = NEGCHAR;
gp->rc->flags |= RF_RCCHANGED;
newsgroup_toread--;
}
return TR_BOGUS;
}
#ifdef ANCIENT_NEWS
sscanf(tmpbuf+len+1, "%ld %c", &last, &ch);
first = 1;
#else
sscanf(tmpbuf+len+1, "%ld %ld %c", &last, &first, &ch);
#endif
if (!gp->abs1st)
gp->abs1st = (ART_NUM)first;
if (!in_ng) {
if (redirected) {
if (redirected != nullstr)
free(redirected);
redirected = NULL;
}
switch (ch) {
case 'n':
moderated = getval("NOPOSTRING"," (no posting)");
break;
case 'm':
moderated = getval("MODSTRING", " (moderated)");
break;
case 'x':
redirected = nullstr;
moderated = " (DISABLED)";
break;
case '=':
len = strlen(tmpbuf);
if (tmpbuf[len-1] == '\n')
tmpbuf[len-1] = '\0';
redirected = savestr(rindex(tmpbuf, '=') + 1);
moderated = " (REDIRECTED)";
break;
default:
moderated = nullstr;
break;
}
}
if (last <= gp->ngmax)
return gp->ngmax;
return gp->ngmax = (ART_NUM)last;
}
|